backend/libinput: guard against new enum entries

When libinput introduces new enum entries, we'd abort or send bogus
events to the compositor. Instead, log a message and ignore the
event.

Keep all enums without a default case so that the compiler warns
when we're missing a case.
This commit is contained in:
Simon Ser 2026-02-12 22:37:41 +01:00 committed by Simon Zeni
parent 25f94c5965
commit 884d29e5f3
7 changed files with 179 additions and 89 deletions

View file

@ -2,6 +2,7 @@
#include <libinput.h>
#include <stdlib.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/util/log.h>
#include "backend/libinput.h"
struct wlr_libinput_input_device *device_from_keyboard(
@ -30,6 +31,18 @@ void init_device_keyboard(struct wlr_libinput_input_device *dev) {
libinput_device_led_update(dev->handle, 0);
}
static bool key_state_from_libinput(enum libinput_key_state state, enum wl_keyboard_key_state *out) {
switch (state) {
case LIBINPUT_KEY_STATE_RELEASED:
*out = WL_KEYBOARD_KEY_STATE_RELEASED;
return true;
case LIBINPUT_KEY_STATE_PRESSED:
*out = WL_KEYBOARD_KEY_STATE_PRESSED;
return true;
}
return false;
}
void handle_keyboard_key(struct libinput_event *event,
struct wlr_keyboard *kb) {
struct libinput_event_keyboard *kbevent =
@ -39,13 +52,9 @@ void handle_keyboard_key(struct libinput_event *event,
.keycode = libinput_event_keyboard_get_key(kbevent),
.update_state = true,
};
switch (libinput_event_keyboard_get_key_state(kbevent)) {
case LIBINPUT_KEY_STATE_RELEASED:
wlr_event.state = WL_KEYBOARD_KEY_STATE_RELEASED;
break;
case LIBINPUT_KEY_STATE_PRESSED:
wlr_event.state = WL_KEYBOARD_KEY_STATE_PRESSED;
break;
if (!key_state_from_libinput(libinput_event_keyboard_get_key_state(kbevent), &wlr_event.state)) {
wlr_log(WLR_DEBUG, "Unhandled libinput key state");
return;
}
wlr_keyboard_notify_key(kb, &wlr_event);
}