wayland: check for xkb state in handle modifiers

Normally in wayland, you receive a keymap event from the compositor
which is what allows the client to setup what is needed for xkb.
However, it turns out that this doesn't occur in the case of virtual
keyboards, such as from wtype, that come from the custom
virtual-keyboard protocol. What happens in this case is that mpv only
receives a keyboard entrance event. According to the wayland protocol
documentation [1], "the compositor must send wl_keyboard.modifiers event
after [the wl_keyboard.enter] event". It is possible for this to occur
before the physical keyboard is properly mapped (i.e: using a virtual
keyboard to start mpv). What this results in is a segfault once
xkb_state_update_mask is called in the modifiers event. The fix is to
simply not always assume we have created the xkb state if we get this
event and check for its existence first. Closes #9119.

https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_keyboard
This commit is contained in:
Dudemanguy 2021-08-15 09:32:11 -05:00
parent 0c9e1e34fd
commit e0df7688f6
1 changed files with 4 additions and 3 deletions

View File

@ -395,7 +395,6 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,
state = state == WL_KEYBOARD_KEY_STATE_PRESSED ? MP_KEY_STATE_DOWN
: MP_KEY_STATE_UP;
int mpmod = get_mods(wl);
int mpkey = lookupkey(sym);
if (mpkey) {
@ -414,8 +413,10 @@ static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboar
{
struct vo_wayland_state *wl = data;
xkb_state_update_mask(wl->xkb_state, mods_depressed, mods_latched,
mods_locked, 0, 0, group);
if (wl->xkb_state) {
xkb_state_update_mask(wl->xkb_state, mods_depressed, mods_latched,
mods_locked, 0, 0, group);
}
}
static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard,