From e0df7688f63d57f4f72c99977bd4cedb33e59a71 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Sun, 15 Aug 2021 09:32:11 -0500 Subject: 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 --- video/out/wayland_common.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 6311e34d13..9b901d9f40 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -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, -- cgit v1.2.3