From c830c1ea3a114daaf1f12c1fab39cb5d843791b9 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 13 Apr 2015 10:23:46 +1000 Subject: [PATCH] Don't post a events for a missing capability Log a bug instead. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/libinput.c b/src/libinput.c index 80144571..bcb2509d 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1065,6 +1065,35 @@ notify_removed_device(struct libinput_device *device) &removed_device_event->base); } +static inline bool +device_has_cap(struct libinput_device *device, + enum libinput_device_capability cap) +{ + const char *capability; + + if (libinput_device_has_capability(device, cap)) + return true; + + switch (cap) { + case LIBINPUT_DEVICE_CAP_POINTER: + capability = "CAP_POINTER"; + break; + case LIBINPUT_DEVICE_CAP_KEYBOARD: + capability = "CAP_KEYBOARD"; + break; + case LIBINPUT_DEVICE_CAP_TOUCH: + capability = "CAP_TOUCH"; + break; + } + + log_bug_libinput(device->seat->libinput, + "Event for missing capability %s on device \"%s\"\n", + capability, + libinput_device_get_name(device)); + + return false; +} + void keyboard_notify_key(struct libinput_device *device, uint64_t time, @@ -1074,6 +1103,9 @@ keyboard_notify_key(struct libinput_device *device, struct libinput_event_keyboard *key_event; uint32_t seat_key_count; + if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_KEYBOARD)) + return; + key_event = zalloc(sizeof *key_event); if (!key_event) return; @@ -1100,6 +1132,9 @@ pointer_notify_motion(struct libinput_device *device, { struct libinput_event_pointer *motion_event; + if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_POINTER)) + return; + motion_event = zalloc(sizeof *motion_event); if (!motion_event) return; @@ -1122,6 +1157,9 @@ pointer_notify_motion_absolute(struct libinput_device *device, { struct libinput_event_pointer *motion_absolute_event; + if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_POINTER)) + return; + motion_absolute_event = zalloc(sizeof *motion_absolute_event); if (!motion_absolute_event) return; @@ -1145,6 +1183,9 @@ pointer_notify_button(struct libinput_device *device, struct libinput_event_pointer *button_event; int32_t seat_button_count; + if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_POINTER)) + return; + button_event = zalloc(sizeof *button_event); if (!button_event) return; @@ -1175,6 +1216,9 @@ pointer_notify_axis(struct libinput_device *device, { struct libinput_event_pointer *axis_event; + if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_POINTER)) + return; + axis_event = zalloc(sizeof *axis_event); if (!axis_event) return; @@ -1201,6 +1245,9 @@ touch_notify_touch_down(struct libinput_device *device, { struct libinput_event_touch *touch_event; + if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_TOUCH)) + return; + touch_event = zalloc(sizeof *touch_event); if (!touch_event) return; @@ -1226,6 +1273,9 @@ touch_notify_touch_motion(struct libinput_device *device, { struct libinput_event_touch *touch_event; + if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_TOUCH)) + return; + touch_event = zalloc(sizeof *touch_event); if (!touch_event) return; @@ -1250,6 +1300,9 @@ touch_notify_touch_up(struct libinput_device *device, { struct libinput_event_touch *touch_event; + if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_TOUCH)) + return; + touch_event = zalloc(sizeof *touch_event); if (!touch_event) return; @@ -1271,6 +1324,9 @@ touch_notify_frame(struct libinput_device *device, { struct libinput_event_touch *touch_event; + if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_TOUCH)) + return; + touch_event = zalloc(sizeof *touch_event); if (!touch_event) return;