Undo commit 5ea7a04 which requires Mutter V12

That commit's goal was to use an algorithm that does not assume
that number keys are at keycodes 10-19, which may not hold with
"special" keyboards. Unfortunately, the new algorithm requires
Mutter V12 and fails with Mutter V11, used by Debian 12.
This commit is contained in:
ManoloFLTK 2023-08-23 15:59:04 +02:00
parent f456f2550a
commit ee0f173d9f

View File

@ -504,7 +504,8 @@ static void wl_keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
struct Fl_Wayland_Screen_Driver::seat *seat = (struct Fl_Wayland_Screen_Driver::seat*)data;
assert(format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1);
char *map_shm = (char*)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
char *map_shm = (char*)mmap(NULL, size, PROT_READ,
wl_keyboard_get_version(wl_keyboard) >= 7 ? MAP_PRIVATE : MAP_SHARED, fd, 0);
assert(map_shm != MAP_FAILED);
struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_string(seat->xkb_context, map_shm,
@ -538,23 +539,17 @@ static void remove_int_vector(Fl_Int_Vector& v, int val) {
static int process_wld_key(struct xkb_state *xkb_state, uint32_t key,
uint32_t *p_keycode, xkb_keysym_t *p_sym,
struct xkb_keymap *xkb_keymap) {
uint32_t *p_keycode, xkb_keysym_t *p_sym) {
uint32_t keycode = key + 8;
xkb_keysym_t sym = xkb_state_key_get_one_sym(xkb_state, keycode);
if (sym == 0xfe20) sym = FL_Tab;
if (sym >= 'A' && sym <= 'Z') sym += 32; // replace uppercase by lowercase letter
int for_key_vector = sym; // for support of Fl::event_key(int)
// Special processing for number keys == keysym in ['0'-'9'] :
// compute sym2 = keysym for same key with opposite shift state
int depressed = xkb_state_mod_name_is_active(xkb_state, XKB_MOD_NAME_SHIFT, XKB_STATE_MODS_DEPRESSED) ? 0 : 1;
struct xkb_state *xkb_state2 = xkb_state_new(xkb_keymap);
xkb_state_update_mask(xkb_state2, depressed, 0, 0, 0, 0, 0);
xkb_keysym_t sym2 = xkb_state_key_get_one_sym(xkb_state2, keycode);
xkb_state_unref(xkb_state2);
// use that other keysym if it matches a number key
if (sym2 >= '0' && sym2 <= '9') {
for_key_vector = sym2;
// special processing for number keys == keycodes 10-19 :
if (keycode >= 10 && keycode <= 18) {
for_key_vector = '1' + (keycode - 10);
} else if (keycode == 19) {
for_key_vector = '0';
}
if (p_keycode) *p_keycode = keycode;
if (p_sym) *p_sym = sym;
@ -573,7 +568,7 @@ static void wl_keyboard_enter(void *data, struct wl_keyboard *wl_keyboard,
for (uint32_t *p = (uint32_t *)(keys)->data;
(const char *) p < ((const char *) (keys)->data + (keys)->size);
(p)++) {
int for_key_vector = process_wld_key(seat->xkb_state, *p, NULL, NULL, seat->xkb_keymap);
int for_key_vector = process_wld_key(seat->xkb_state, *p, NULL, NULL);
//fprintf(stderr, "%d ", for_key_vector);
if (search_int_vector(key_vector, for_key_vector) < 0) key_vector.push_back(for_key_vector);
}
@ -713,7 +708,7 @@ static void wl_keyboard_key(void *data, struct wl_keyboard *wl_keyboard,
static char buf[128];
uint32_t keycode;
xkb_keysym_t sym;
int for_key_vector = process_wld_key(seat->xkb_state, key, &keycode, &sym, seat->xkb_keymap);
int for_key_vector = process_wld_key(seat->xkb_state, key, &keycode, &sym);
/*xkb_keysym_get_name(sym, buf, sizeof(buf));
const char *action = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? "press" : "release");
fprintf(stderr, "key %s: sym: %-12s(%d) code:%u fl_win=%p, ", action, buf, sym, keycode, Fl_Wayland_Window_Driver::surface_to_window(seat->keyboard_surface));*/