mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-02-22 01:40:43 -05:00
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:
parent
25f94c5965
commit
884d29e5f3
7 changed files with 179 additions and 89 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include <assert.h>
|
||||
#include <libinput.h>
|
||||
#include <wlr/interfaces/wlr_switch.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "backend/libinput.h"
|
||||
#include "config.h"
|
||||
|
||||
|
|
@ -23,33 +24,49 @@ struct wlr_libinput_input_device *device_from_switch(
|
|||
return dev;
|
||||
}
|
||||
|
||||
static bool switch_type_from_libinput(enum libinput_switch type, enum wlr_switch_type *out) {
|
||||
switch (type) {
|
||||
case LIBINPUT_SWITCH_LID:
|
||||
*out = WLR_SWITCH_TYPE_LID;
|
||||
return true;
|
||||
case LIBINPUT_SWITCH_TABLET_MODE:
|
||||
*out = WLR_SWITCH_TYPE_TABLET_MODE;
|
||||
return true;
|
||||
#if HAVE_LIBINPUT_SWITCH_KEYPAD_SLIDE
|
||||
case LIBINPUT_SWITCH_KEYPAD_SLIDE:
|
||||
*out = WLR_SWITCH_TYPE_KEYPAD_SLIDE;
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool switch_state_from_libinput(enum libinput_switch_state state, enum wlr_switch_state *out) {
|
||||
switch (state) {
|
||||
case LIBINPUT_SWITCH_STATE_OFF:
|
||||
*out = WLR_SWITCH_STATE_OFF;
|
||||
return true;
|
||||
case LIBINPUT_SWITCH_STATE_ON:
|
||||
*out = WLR_SWITCH_STATE_ON;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void handle_switch_toggle(struct libinput_event *event,
|
||||
struct wlr_switch *wlr_switch) {
|
||||
struct libinput_event_switch *sevent =
|
||||
libinput_event_get_switch_event (event);
|
||||
libinput_event_get_switch_event(event);
|
||||
struct wlr_switch_toggle_event wlr_event = {
|
||||
.time_msec = usec_to_msec(libinput_event_switch_get_time_usec(sevent)),
|
||||
};
|
||||
switch (libinput_event_switch_get_switch(sevent)) {
|
||||
case LIBINPUT_SWITCH_LID:
|
||||
wlr_event.switch_type = WLR_SWITCH_TYPE_LID;
|
||||
break;
|
||||
case LIBINPUT_SWITCH_TABLET_MODE:
|
||||
wlr_event.switch_type = WLR_SWITCH_TYPE_TABLET_MODE;
|
||||
break;
|
||||
#if HAVE_LIBINPUT_SWITCH_KEYPAD_SLIDE
|
||||
case LIBINPUT_SWITCH_KEYPAD_SLIDE:
|
||||
wlr_event.switch_type = WLR_SWITCH_TYPE_KEYPAD_SLIDE;
|
||||
break;
|
||||
#endif
|
||||
if (!switch_type_from_libinput(libinput_event_switch_get_switch(sevent), &wlr_event.switch_type)) {
|
||||
wlr_log(WLR_DEBUG, "Unhandled libinput switch type");
|
||||
return;
|
||||
}
|
||||
switch (libinput_event_switch_get_switch_state(sevent)) {
|
||||
case LIBINPUT_SWITCH_STATE_OFF:
|
||||
wlr_event.switch_state = WLR_SWITCH_STATE_OFF;
|
||||
break;
|
||||
case LIBINPUT_SWITCH_STATE_ON:
|
||||
wlr_event.switch_state = WLR_SWITCH_STATE_ON;
|
||||
break;
|
||||
if (!switch_state_from_libinput(libinput_event_switch_get_switch_state(sevent), &wlr_event.switch_state)) {
|
||||
wlr_log(WLR_DEBUG, "Unhandled libinput switch state");
|
||||
return;
|
||||
}
|
||||
wl_signal_emit_mutable(&wlr_switch->events.toggle, &wlr_event);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue