wayland: replace old keymap if we receive a new keymap event

Fixes: 2274311b25
Fixes: #15022
This commit is contained in:
llyyr 2024-10-08 18:47:43 +05:30 committed by sfan5
parent c201c4874d
commit 6871304029
1 changed files with 9 additions and 6 deletions

View File

@ -528,10 +528,12 @@ static void keyboard_handle_keymap(void *data, struct wl_keyboard *wl_keyboard,
return;
}
if (!s->xkb_keymap)
s->xkb_keymap = xkb_keymap_new_from_buffer(wl->xkb_context, map_str,
strnlen(map_str, size),
XKB_KEYMAP_FORMAT_TEXT_V1, 0);
if (s->xkb_keymap)
xkb_keymap_unref(s->xkb_keymap);
s->xkb_keymap = xkb_keymap_new_from_buffer(wl->xkb_context, map_str,
strnlen(map_str, size),
XKB_KEYMAP_FORMAT_TEXT_V1, 0);
munmap(map_str, size);
close(fd);
@ -540,9 +542,10 @@ static void keyboard_handle_keymap(void *data, struct wl_keyboard *wl_keyboard,
MP_ERR(wl, "failed to compile keymap\n");
return;
}
if (s->xkb_state)
xkb_state_unref(s->xkb_state);
if (!s->xkb_state)
s->xkb_state = xkb_state_new(s->xkb_keymap);
s->xkb_state = xkb_state_new(s->xkb_keymap);
if (!s->xkb_state) {
MP_ERR(wl, "failed to create XKB state\n");
xkb_keymap_unref(s->xkb_keymap);