input: ignore “keyboard key” events on seats without keyboard focus

There are two ways this can happen:

1. The compositor did not send a “keyboard enter” event before sending
   the key release event.
2. The compositor did send a “keyboard enter” event, but did so before
   sending a “keyboard map” event. In this case, the seat’s XKB context
   hasn’t yet been set, and foot ignores the “keyboard enter” event.

Regardless of the root cause, this causes foot to crash because the
seat instance in foot isn’t able to track which terminal window
instance is being focused.

While this is a compositor bug, it still makes sense to detect this in
foot, and ignore such events, to ensure the user doesn’t lose any
work.

Closes #1097
This commit is contained in:
Daniel Eklöf 2022-06-25 23:05:41 +02:00
parent 206e9a1050
commit a16029e7c9
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 15 additions and 0 deletions

View file

@ -80,9 +80,12 @@
* Workaround for buggy compositors (e.g. some versions of GNOME)
allowing drag-and-drops even though foot has reported it does not
support the offered mime-types ([#1092][1092]).
* Crash when compositor sends a _”keyboard key”_ event without a prior
_”keyboard enter”_ event ([#1097][1097]).
[1055]: https://codeberg.org/dnkl/foot/issues/1055
[1092]: https://codeberg.org/dnkl/foot/issues/1092
[1097]: https://codeberg.org/dnkl/foot/issues/1092
### Security

12
input.c
View file

@ -1572,6 +1572,18 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial,
uint32_t time, uint32_t key, uint32_t state)
{
struct seat *seat = data;
if (unlikely(seat->kbd_focus == NULL)) {
LOG_WARN(
"compositor sent 'keyboard key %s' event on seat %s "
"without a prior 'keyboard enter' event",
(state == WL_KEYBOARD_KEY_STATE_PRESSED
? "pressed"
: "released"),
seat->name);
return;
}
key_press_release(seat, seat->kbd_focus, serial, key + 8, state);
}