input: workaround buggy Sway sending bad input events

Sway 1.2 has been seen sending keyboard_key() events without first
sending a keyboard_enter() event.

This can be triggered by:

1. start a foot terminal
2. unfocus it (move focus to another window)
3. switch to a vt
4. switch back to sway
5. focus the foot terminal

At this point, Sway will *not* send the keyboard_enter() event, but
instead send a keyboard_key() event.

(furthermore, if you now unfocus the window again, sway will send a
keyboard_leave() event, still without having sent a keyboard_enter()
event).

Sway has _also_ been seen crashing in wl_pointer_motion(). Though this
was in a build without proper debug information, everything points to
a similar issue - i.e. sway is sending a motion event without first
having sent an enter event.

Workaround this by detecting this and logging a warning the first time
it happens. The event is then ignored.
This commit is contained in:
Daniel Eklöf 2019-11-22 21:56:13 +01:00
parent fc7069e1a6
commit 9d24e68e62
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

21
input.c
View file

@ -154,6 +154,17 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial,
struct wayland *wayl = data;
struct terminal *term = wayl->focused;
/* Workaround buggy Sway 1.2 */
if (term == NULL) {
static bool have_warned = false;
if (!have_warned) {
have_warned = true;
LOG_WARN("compositor sent keyboard_key event without first sending keyboard_enter");
}
stop_repeater(wayl, -1);
return;
}
assert(term != NULL);
const xkb_mod_mask_t ctrl = 1 << wayl->kbd.mod_ctrl;
@ -420,6 +431,16 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
struct wayland *wayl = data;
struct terminal *term = wayl->moused;
/* Workaround buggy Sway 1.2 */
if (term == NULL) {
static bool have_warned = false;
if (!have_warned) {
have_warned = true;
LOG_WARN("compositor sent pointer_motion event without first sending pointer_enter");
}
return;
}
assert(term != NULL);
int x = wl_fixed_to_int(surface_x) * term->scale;