Skip to content

Commit

Permalink
feat(linux): mcompile new get_position_From_GDK
Browse files Browse the repository at this point in the history
  • Loading branch information
SabineSIL committed Nov 9, 2023
1 parent e9cc546 commit 3796ee3
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
3 changes: 2 additions & 1 deletion linux/mcompile/keymap/helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

#include "helpers.h"

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//_S2 do not review - all this will be deleted later

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

int append_other_ToVector(v_dw_3D &All_Vector) {
InsertKeyvalsFromVectorFile(All_Vector);
Expand Down
7 changes: 4 additions & 3 deletions linux/mcompile/keymap/helpers.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//_S2 do not review - all this will be deleted later
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#pragma once
#ifndef HELPERS_H
#define HELPERS_H
Expand All @@ -7,9 +11,6 @@
#include "mc_kmxfile.h"
#include "keymap.h"


//_S2 do not review - all this will be deleted later

// why again here?
typedef std::vector<std::string> v_str_1D;
typedef std::vector<KMX_DWORD> v_dw_1D;
Expand Down
16 changes: 16 additions & 0 deletions linux/mcompile/keymap/keymap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,22 @@ KMX_DWORD get_position_From_VirtualKey_Other(KMX_DWORD VK_Other , v_dw_3D &All_V

}

// returns Keyval which hold the Keysym (in unshifted, shifted)
KMX_DWORD get_position_From_GDK(GdkKeymap *keymap, UINT KeySym ) {
GdkKeymapKey *maps;
guint *keyvals;
gint count;

for (int k=0; k<255 ; k++ ){
if (gdk_keymap_get_entries_for_keycode (keymap, k, &maps, &keyvals, &count)) {
if ( (keyvals[0] == KeySym) || (keyvals[1] == KeySym) ) {
return (KMX_DWORD) maps[0].keycode;
}
}
}
return 0; //_S2 TODO what do I return if not found??
}

// _S2 TODO How to do mapping between Linux keycodes and keyman SC
const int Lin_KM__map(int i, v_dw_3D &All_Vector) {
// MAP:
Expand Down
2 changes: 2 additions & 0 deletions linux/mcompile/keymap/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ KMX_DWORD get_SC_From_VirtualKey_US(KMX_DWORD VK_US , v_dw_3D &All_Vector);
KMX_DWORD get_position_From_VirtualKey_Other(KMX_DWORD VK_US , v_dw_3D &All_Vector);
// return the Scancode of for given VirtualKey of Other in specific column. If column > available columns look in all columns;
KMX_DWORD get_position_From_VirtualKey_Other(KMX_DWORD VK_Other , v_dw_3D &All_Vector, int which_columns);
// return the Scancode of for given VirtualKey using GDK
KMX_DWORD get_position_From_GDK(GdkKeymap *keymap, UINT mapped_ikey);

// initialize GDK
bool InitializeGDK(GdkKeymap **keymap,int argc, gchar *argv[]);
Expand Down
31 changes: 22 additions & 9 deletions linux/mcompile/keymap/mc_import_rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ int i4 = this->KMX_IsXxxxGrCapsEqualToXxxxShift() ? 8 : 0;
if (st.size() == 0) {
// No character assigned here
}
// _S2 deadkeys don work yet
// _S2 deadkeys don't work yet
else if (this->m_rgfDeadKey[(int)ss][caps]) {
// It's a dead key, append an @ sign.
key->dpContext = new KMX_WCHAR[1];
Expand Down Expand Up @@ -690,8 +690,6 @@ bool KMX_ImportRules(KMX_WCHAR *kbid, LPKMX_KEYBOARD kp,v_dw_3D &All_Vector, Gd
// values in it. Then, store the SC in each valid VK so it can act as both a
// flag that the VK is valid, and it can store the SC value.
// _S2 this does not find exactly the same keys as the windows version does(windows finds more)
// but the ones we need for mcompile are there


for(UINT sc = 0x01; sc <= 0x7f; sc++) {
KMX_VirtualKey *key = new KMX_VirtualKey(sc, hkl, All_Vector, keymap);
Expand Down Expand Up @@ -780,16 +778,29 @@ bool KMX_ImportRules(KMX_WCHAR *kbid, LPKMX_KEYBOARD kp,v_dw_3D &All_Vector, Gd
continue;
}

// _S2 TODO get Keyval from GDK
int Keypos = get_position_From_VirtualKey_Other(mapped_ikey , All_Vector, 99);
UINT VK_vec = (UINT) All_Vector[1][Keypos][0];
// _S2 TODO get Keyval from GDK get the keyval(nr of key )for e.g.52 -> 52 is printed out by key 13)
//int Keypos = get_position_From_VirtualKey_Other(mapped_ikey , All_Vector, 99);
//UINT VK_vec = (UINT) All_Vector[1][Keypos][0];

// _S2 get_position_From_GDK gives wrong values for 0,65,94,126 which are not processed correctly -> "what do I return if not found..."
KMX_DWORD keypos_GDK= get_position_From_GDK( *keymap, mapped_ikey );

//if ( VK_vec != keypos_GDK)
// wprintf(L" DIFFFFERERNT !!!!!!! , %i -- %i\n", VK_vec,keypos_GDK );

// _S2 TODO this needs to go !! it's temporary until we decide what to return if not found. At the moment we return 0 in this case which is a problem for gdk
// _S2 to avoid Gdk-CRITICAL **: 16:41:42.662: gdk_keymap_get_entries_for_keyval: assertion 'keyval != 0' failed we set keypos_GDK to a value
if (keypos_GDK ==0)
keypos_GDK = 49;


for(int caps = 0; caps <= 1; caps++) {

//_S2 TODO get char - do I need rc ?? ( was rc = ToUnicodeEx...)
std::wstring VK_Other_OLD = get_VirtualKey_Other_from_iKey(mapped_ikey, ss, caps, All_Vector);
// std::wstring VK_Other1= getKeySyms_according_to_Shiftstate( *keymap, VK_vec, All_Vector, ss, caps);
std::wstring VK_Other = PrintKeymapForCodeReturnKeySym2( *keymap, VK_vec, All_Vector, ss, caps );
//std::wstring VK_Other = PrintKeymapForCodeReturnKeySym2( *keymap, VK_vec, All_Vector, ss, caps );
std::wstring VK_Other = PrintKeymapForCodeReturnKeySym2( *keymap, keypos_GDK, All_Vector, ss, caps );


/* _S2 can go later
Expand Down Expand Up @@ -849,6 +860,7 @@ UINT VK_vec = (UINT) All_Vector[1][Keypos][0];
memcpy(gp, kp->dpGroupArray, sizeof(KMX_GROUP) * kp->cxGroupArray);

//

// Find the current highest deadkey index
//

Expand Down Expand Up @@ -876,10 +888,11 @@ UINT VK_vec = (UINT) All_Vector[1][Keypos][0];
for (UINT iKey = 0; iKey < rgKey.size(); iKey++) {
if ((rgKey[iKey] != NULL) && rgKey[iKey]->KMX_IsKeymanUsedKey() && (!rgKey[iKey]->KMX_IsEmpty())) {
nKeys+= rgKey[iKey]->KMX_GetKeyCount(loader.MaxShiftState());
wprintf(L" iKey = %i, Delta: %i \n", iKey, rgKey[iKey]->KMX_GetKeyCount(loader.MaxShiftState()));
//wprintf(L" iKey = %i, Delta: %i \n", iKey, rgKey[iKey]->KMX_GetKeyCount(loader.MaxShiftState()));
}
}


nDeadkey++; // ensure a 1-based index above the max deadkey value already in the keyboard

gp->fUsingKeys = TRUE;
Expand All @@ -897,7 +910,7 @@ int STOP;

for (UINT iKey = 0; iKey < rgKey.size(); iKey++) {
if ((rgKey[iKey] != NULL) && rgKey[iKey]->KMX_IsKeymanUsedKey() && (!rgKey[iKey]->KMX_IsEmpty())) {
wprintf(L"********************************* I use Key Nr %i\n",iKey);
//wprintf(L"********************************* I use Key Nr %i\n",iKey);
// for each item,
if(rgKey[iKey]->KMX_LayoutRow(loader.MaxShiftState(), &gp->dpKeyArray[nKeys], &alDead, nDeadkey, bDeadkeyConversion, All_Vector)) { // I4552
nKeys+=rgKey[iKey]->KMX_GetKeyCount(loader.MaxShiftState());
Expand Down
1 change: 0 additions & 1 deletion linux/mcompile/keymap/mc_kmxfile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "mc_kmxfile.h"
#include "u16.h"
#include "filesystem.h" // _S2 needed?
#include <typeinfo>

KMX_BOOL KMX_VerifyKeyboard(LPKMX_BYTE filebase, KMX_DWORD sz);
Expand Down

0 comments on commit 3796ee3

Please sign in to comment.