X11: add necessary XFree call after call to XGetKeyboardMapping (#1427)
Build and Test / build-linux (push) Has been cancelled
Build and Test / build-wayland (push) Has been cancelled
Build and Test / build-macos (push) Has been cancelled
Build and Test / build-windows (push) Has been cancelled

Also :
- remove duplication of function keycode_to_ascii for X11 and Wayland;
- add comments detailing implementation.
This commit is contained in:
ManoloFLTK
2026-05-05 09:32:59 +02:00
parent fe4a6aa912
commit d2cff6107d
4 changed files with 29 additions and 27 deletions
+4 -13
View File
@@ -1301,17 +1301,6 @@ static bool remove_xid_vector(Window xid) {
}
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;
@@ -2006,13 +1995,15 @@ int fl_handle(const XEvent& thisevent)
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
// Check for non-Latin keyboard layout. Based on the assumption that the 'A' key of the keyboard
// having a non-ASCII keysym indicates a non-Latin layout.
if (syms[0] > 'z') {
int asciiSym = keycode_to_ascii(keycode);
int asciiSym = Fl_Unix_System_Driver::keycode_to_ascii(keycode);
if (asciiSym != 0) {
keysym = asciiSym;
}
}
XFree(syms);
// 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
+1
View File
@@ -49,6 +49,7 @@ public:
static unsigned char *create_bmp(const unsigned char *data, int W, int H, int *return_size);
static Fl_RGB_Image *own_bmp_to_RGB(char *bmp);
static void read_int(uchar *c, int& i);
static char keycode_to_ascii(int keycode);
};
#endif /* FL_NIX_SYSTEM_DRIVER_H */
@@ -912,3 +912,23 @@ Fl_RGB_Image *Fl_Unix_System_Driver::own_bmp_to_RGB(char *bmp) {
img->alloc_array = 1;
return img;
}
/*
Used with non-Latin keyboards to get the Latin letter associated to a key,
typically useful when used with Ctrl.
Based on the assumption that Latin letters have the QWERTY layout in any
non-Latin layout. This assumption was verified true for Greek, Russian,
and Thai layouts.
Not used with keyboard layouts using Latin letters where the location
of letters varies extensively (e.g., French, Turkish).
*/
char Fl_Unix_System_Driver::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;
}
@@ -21,7 +21,7 @@
#include <wayland-cursor.h>
#include "../../../libdecor/build/fl_libdecor.h"
#include "xdg-shell-client-protocol.h"
#include "../Posix/Fl_Posix_System_Driver.H"
#include "../Unix/Fl_Unix_System_Driver.H"
#include <FL/Fl.H>
#include <FL/Fl_Image_Surface.H>
#include <FL/platform.H>
@@ -589,17 +589,6 @@ static void remove_int_vector(std::vector<int>& v, int val) {
}
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;
}
static int process_wld_key(struct xkb_state *xkb_state, uint32_t key,
uint32_t *p_keycode, xkb_keysym_t *p_sym) {
uint32_t keycode = key + 8;
@@ -615,9 +604,10 @@ static int process_wld_key(struct xkb_state *xkb_state, uint32_t key,
} else if (keycode == 19) {
for_key_vector = '0';
}
// Check for non-Latin keyboard layout
// Check for non-Latin keyboard layout. Based on the assumption that the 'A' key of the keyboard
// having a non-ASCII keysym indicates a non-Latin layout.
if (xkb_state_key_get_one_sym(xkb_state, 38 /* 'A' key on US keyboard */) > 'z') {
int asciiSym = keycode_to_ascii(keycode);
int asciiSym = Fl_Unix_System_Driver::keycode_to_ascii(keycode);
if (asciiSym != 0) {
for_key_vector = asciiSym;
}