Skip to content

Commit

Permalink
feat(linux): mcompile tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
SabineSIL committed Nov 9, 2023
1 parent 3796ee3 commit 4a7901b
Show file tree
Hide file tree
Showing 3 changed files with 301 additions and 299 deletions.
298 changes: 298 additions & 0 deletions linux/mcompile/keymap/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,301 @@ bool get_US_Keysym_From_OtherKeysym(v_str_3D &All_Vector, int inOther, int &OutU
MyCoutW(L" #### get_US_Char_FromOther of keymap ended", 1);
return true;
}*/


// _S2 maybe I will need that later??

/* static xkb_keysym_t get_ascii(struct xkb_state *state, xkb_keycode_t keycode) {
struct xkb_keymap *keymap;
xkb_layout_index_t num_layouts;
xkb_layout_index_t layout;
xkb_level_index_t level;
const xkb_keysym_t *syms;
int num_syms;
keymap = xkb_state_get_keymap(state);
num_layouts = xkb_keymap_num_layouts_for_key(keymap, keycode);
for (layout = 0; layout < num_layouts; layout++) {
level = xkb_state_key_get_level(state, keycode, layout);
num_syms = xkb_keymap_key_get_syms_by_level(keymap, keycode,
layout, level, &syms);
if (num_syms != 1)
continue;
if (syms[0] > 0 && xkb_keysym_to_utf32(syms[0]) < 128)
return syms[0];
}
return XKB_KEY_NoSymbol;
}
*/


/*static xkb_keysym_t get_ascii_SAB(xkb_keycode_t keycode) {
xkb_layout_index_t num_layouts;
xkb_layout_index_t layout;
xkb_level_index_t level;
const xkb_keysym_t *syms;
int num_syms;
struct xkb_context *ctx;
ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!ctx)
MyCoutW(L" # Error in xkb_context_new", 1);
// get a keymap from a given name ( is)
struct xkb_keymap *keymap_is;
struct xkb_rule_names names = {
// Example RMLVO for Icelandic Dvorak.
.rules = NULL,
.model = "pc105",
.layout = "is",
.variant = "dvorak",
.options = "terminate:ctrl_alt_bksp"
};
keymap_is = xkb_keymap_new_from_names(ctx, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap_is)
MyCoutW(L" # Error in xkb_keymap_new_from_names", 1);
// how many layouts are in keymap ( here is: 4)
num_layouts = xkb_keymap_num_layouts_for_key(keymap_is, keycode);
std::wcout << L" num_layouts: " << num_layouts << L"\n";
for (layout = 0; layout < num_layouts; layout++) {
// how many levels do we have per key e.g. [a, A, ä, ascitilde ]
std::wcout << L" layout: Nr" << layout << L"\n";
xkb_level_index_t level = xkb_keymap_num_levels_for_key ( keymap_is, keycode, layout ) ;
std::wcout << L" we have level nr of : " << level << L"\n";
for( int j=0; j< level;j++)
{
std::wcout << L" j: " << j << L"\n";
// get the keysym(characzter) in level level ( get a for level 1; A for level 2;)
num_syms = xkb_keymap_key_get_syms_by_level(keymap_is, keycode, layout, j, &syms);
std::wcout << L" num_syms(j): " << num_syms << L"\n";
// if no entry for this level
if (num_syms != 1)
continue;
if (syms[0] > 0 && xkb_keysym_to_utf32(syms[0]) < 128)
return syms[0];
}
}
return XKB_KEY_NoSymbol;
}*/
// bak all tries for DoConvert here:
/*
//#include "XKeyboard.h"
#include "/usr/include/libxklavier/xklavier.h"
#include "/usr/include/libxklavier/xkl_config_item.h"
#include "/usr/include/libxklavier/xkl_config_rec.h
#include "/usr/include/libxklavier/xkl_config_registry.h
#include "/usr/include/libxklavier/xkl_engine.h
#include "/usr/include/libxklavier/xkl_engine_marshal.h
#include "/usr/include/libxklavier/xkl-enum-types.h
#include "/usr/include/libxklavier/xklavier.h"
#include "/usr/include/libxklavier/xklavier.h"
std::wcout << L"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n";
std::string st = std::locale("").name() ;
std::wstring wstr = wstring_from_string(st);
std::wcout << wstr;
std::wcout << L"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n";
xklgetg
//const char** ccc = XklGetGroupNames ( ) ;
//xkl_engine_get_groups_names
//const char** cccc = XkbGetNames ( ) ;
/*
Display *dpy = XOpenDisplay(NULL);
if (dpy == NULL) {
fprintf(stderr, "Cannot open display\n");
exit(1);
}
XkbStateRec state;
XkbGetState(dpy, XkbUseCoreKbd, &state);
XkbDescPtr desc = XkbGetKeyboard(dpy, XkbAllComponentsMask, XkbUseCoreKbd);
char*symbols = XGetAtomName(dpy, desc->names->symbols);
//char *group = XGetAtomName(dpy, desc->names->groups[state.group]);
//printf("Full name: %s\n", group);
XKeyboard xkb;
std::string cGrpName=xkb.currentGroupName(); //return somethings like "USA"
std::string cGrpSymb=xkb.currentGroupSymbol(); //return somethings like "us"
xkb.setGroupByNum(0);//set keyboard layout to first layout in available ones
//wprintf(L"Full name: %s\n", symbols);
//std::wcout << L"qqqqqqqqqqqqqqqqqqqq: " << *symbols;
xkb_keysym_t in;
xkb_keysym_t out;
std::vector < int > vi ={34,39,43,47,48,61,57};
for( int i=0; i<vi.size();i++)
{
in = vi[i];
out = get_ascii_SAB(in) ;
std:: wcout << L" in : " << in << L" out : " << out << L" ( " << (char)out << L")\n " ;
}
MyCoutW(L"#### KMX_DoConvert of keymap started", 1);
gdk_init(&argc, &argv);
GdkDisplay *display = gdk_display_get_default();
if (!display) {
printf("ERROR: can't get display\n");
return 1;
}
GdkKeymap *keymap = gdk_keymap_get_for_display(display);
if (!keymap) {
printf("ERROR: Can't get keymap\n");
gdk_display_close(display);
return 2;
}
MyCoutW(L" # Top checks of keymap OK", 1);
das geht... v
struct xkb_context *ctx;
ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!ctx)
MyCoutW(L" # Error in xkb_context_new", 1);
struct xkb_keymap *keymap;
struct xkb_rule_names names = {
// Example RMLVO for Icelandic Dvorak.
.rules = NULL,
.model = "pc105",
.layout = "is",
.variant = "dvorak",
.options = "terminate:ctrl_alt_bksp"
};
keymap = xkb_keymap_new_from_names(ctx, &names,
XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap)
MyCoutW(L" # Error in xkb_keymap_new_from_names", 1);
MyCoutW(L" # XKB setup OK", 1);
xkb_layout_index_t num_layouts;
xkb_layout_index_t layout;
xkb_level_index_t level;
const xkb_keysym_t *syms;
int num_syms;
std::vector < int > vi ={34,39,43,47,48,61,57};
for( int i=0; i<vi.size();i++)
{
num_syms = xkb_keymap_key_get_syms_by_level(keymap, vi[i], layout, 0, &syms);
std::wcout << L"keycode in: " << vi[i] << L" keysym out: " << num_syms << L"\n";;
}
das geht... ^
//num_syms = xkb_keymap_key_get_syms_by_level(keymap, keycode, layout, level, &syms);
// *******************************************************************************************************************
struct xkb_keymap *keymap1;
xkb_layout_index_t num_layouts;
xkb_layout_index_t layout;
xkb_level_index_t level;
const xkb_keysym_t *syms;
int num_syms;
keymap1 = xkb_state_get_keymap(state);
num_layouts = xkb_keymap_num_layouts_for_key(keymap1, keycode);
for (layout = 0; layout < num_layouts; layout++) {
level = xkb_state_key_get_level(state, keycode, layout);
num_syms = xkb_keymap_key_get_syms_by_level(keymap1, keycode,
layout, level, &syms);
if (num_syms != 1)
continue;
if (syms[0] > 0 && xkb_keysym_to_utf32(syms[0]) < 128)
return syms[0];
}
//return XKB_KEY_NoSymbol;
MyCoutW(L" # XKB get syn OK", 1);
// https://cpp.hotexamples.com/examples/-/-/xkb_state_get_keymap/cpp-xkb_state_get_keymap-function-examples.html
int num;
lv = xkb_state_key_get_level(state, code + KBDXKB_SHIFT, lo);
num = xkb_keymap_key_get_syms_by_level(keymap, code + KBDXKB_SHIFT, lo, lv, &s);
*/

/*int get_OtherKeysym_From_US_Keysym(v_str_3D &All_Vector,int inUS){
int outOther;
MyCoutW(L" #### get_OtherKeysym_From_US_Keysym of keymap started", 1);
wprintf(L" in Us ##################### %i and KeysymsUS : \n", inUS );
// loop and find char in US; then find char of Other
for( int i=0; i< (int)All_Vector[1].size();i++) {
for( int j=0; j< (int)All_Vector[1][0].size();j++) {
int KeysymUS = (int) *All_Vector[0][i][j].c_str();
int KeysymOther = (int) *All_Vector[1][i][j].c_str();
std::wstring KeysymUS_wstr = wstring_from_string(All_Vector[0][i][j]);
//if ( inUS == 58)
wprintf(L" in Us %i and KeysymsUS %i : \n", inUS ,KeysymUS );
//wprintf(L" ................................................................................... inxx: %s outxx: %s %s\n", All_Vector[0][25][2].c_str(),All_Vector[1][25][0].c_str(),All_Vector[1][25][2].c_str());
if( inUS == KeysymUS ) {
//wprintf(L" FOUND Value in US !!!!! : %i out ########: %S \n", inUS,KeysymUS_wstr.c_str());
//wprintf(L" FOUND Value in US !!!!! : %i out ########: %S \n", inUS,KeysymUS_wstr.c_str());
// wprintf(L" FOUND Value in OTHER !!!!! : Other in: %i ( %s ) -- Keycode : %s -- US out ########: %i ( %s ) \n", KeysymUS,All_Vector[0][i][j].c_str(), All_Vector[1][i][0].c_str() , KeysymOther,All_Vector[1][i][j].c_str());
wprintf(L" get_OtherKeysym_From_US_Keysym FOUND Value in US !!!!! : Other in: %i ( %s ) -- Keycode : %s -- US out ########: %i ( %s ) \n",
KeysymUS,All_Vector[0][i][j].c_str(), All_Vector[1][i][0].c_str() , KeysymOther,All_Vector[1][i][j].c_str());
//wprintf(L" FOUND 2 Value in OTHER !!!!! : Other in: %i ( %s ) -- Keycode : %s -- US out ########: %i ( %s ) \n", KeysymOther,All_Vector[1][i][j].c_str(), All_Vector[1][i][0].c_str() , KeysymUS,All_Vector[0][i][j].c_str());
outOther = KeysymOther;
MyCoutW(L" #### get_OtherKeysym_From_US_Keysym of keymap ended", 1);
return outOther;
}
}
}
MyCoutW(L" #### get_US_Char_FromOther of keymap ended", 1);
return true;
}
*/
4 changes: 2 additions & 2 deletions linux/mcompile/keymap/mc_import_rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,8 @@ bool KMX_ImportRules(KMX_WCHAR *kbid, LPKMX_KEYBOARD kp,v_dw_3D &All_Vector, Gd
//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
// _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;

Expand Down
Loading

0 comments on commit 4a7901b

Please sign in to comment.