mirror of
https://github.com/fltk/fltk.git
synced 2026-05-21 22:51:41 +08:00
X11: Fix Fl::event_key() when using non-latin keyboard layouts (#1427)
This commit is contained in:
@@ -1300,6 +1300,18 @@ static bool remove_xid_vector(Window xid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static char keycode_to_ascii(int keycode) {
|
||||
static const char row_AD[] = "qwertyuiop";
|
||||
static const char row_AC[] = "asdfghjkl";
|
||||
static const char row_AB[] = "zxcvbnm";
|
||||
if (keycode >= 24 && keycode <= 33) return row_AD[keycode - 24];
|
||||
else if (keycode >= 38 && keycode <= 46) return row_AC[keycode - 38];
|
||||
else if (keycode >= 52 && keycode <= 58) return row_AB[keycode - 52];
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
int fl_handle(const XEvent& thisevent)
|
||||
{
|
||||
XEvent xevent = thisevent;
|
||||
@@ -1991,6 +2003,17 @@ int fl_handle(const XEvent& thisevent)
|
||||
keysym = '0';
|
||||
}
|
||||
|
||||
int keysyms_per_keycode;
|
||||
KeySym *syms = XGetKeyboardMapping(fl_display, 38 /* 'A' key on US keyboard */, 1,
|
||||
&keysyms_per_keycode);
|
||||
// Check for non-Latin keyboard layout
|
||||
if (syms[0] > 'z') {
|
||||
int asciiSym = keycode_to_ascii(keycode);
|
||||
if (asciiSym != 0) {
|
||||
keysym = asciiSym;
|
||||
}
|
||||
}
|
||||
|
||||
// We have to get rid of the XK_KP_function keys, because they are
|
||||
// not produced on Windoze and thus case statements tend not to check
|
||||
// for them. There are 15 of these in the range 0xff91 ... 0xff9f
|
||||
|
||||
Reference in New Issue
Block a user