diff --git a/src/core/input-events.c b/src/core/input-events.c index b21a30453..246582af6 100644 --- a/src/core/input-events.c +++ b/src/core/input-events.c @@ -23,6 +23,8 @@ #include #include "input-events.h" +#include "devices-core.h" +#include "device-map.h" #include #ifdef HAVE_XINPUT2 @@ -614,3 +616,62 @@ meta_input_event_get_crossing_details (MetaDisplay *display, return retval; } + +MetaDevice * +meta_input_event_get_device (MetaDisplay *display, + XEvent *ev) +{ + guint evtype; + + if (!meta_input_event_get_type (display, ev, &evtype)) + return NULL; + +#ifdef HAVE_XINPUT2 + if (ev->type == GenericEvent && + ev->xcookie.extension == display->xinput2_opcode) + { + XIEvent *xev; + + g_assert (display->have_xinput2 == TRUE); + + xev = (XIEvent *) ev->xcookie.data; + + switch (evtype) + { + case XI_Motion: + case XI_ButtonPress: + case XI_ButtonRelease: + case XI_KeyPress: + case XI_KeyRelease: + return meta_device_map_lookup (display->device_map, + ((XIDeviceEvent *) xev)->deviceid); + case XI_FocusIn: + case XI_FocusOut: + case XI_Enter: + case XI_Leave: + return meta_device_map_lookup (display->device_map, + ((XIEnterEvent *) xev)->deviceid); + default: + break; + } + } + else +#endif + { + switch (ev->type) + { + case KeyPress: + case KeyRelease: + case FocusIn: + case FocusOut: + return meta_device_map_lookup (display->device_map, + META_CORE_KEYBOARD_ID); + default: + /* All other events are pointers' */ + return meta_device_map_lookup (display->device_map, + META_CORE_POINTER_ID); + } + } + + return NULL; +} diff --git a/src/core/input-events.h b/src/core/input-events.h index 46eba8089..11070558c 100644 --- a/src/core/input-events.h +++ b/src/core/input-events.h @@ -33,7 +33,7 @@ #include #include #include "display-private.h" - +#include "device-map.h" gboolean meta_input_event_get_type (MetaDisplay *display, XEvent *ev, @@ -71,5 +71,8 @@ gboolean meta_input_event_get_crossing_details (MetaDisplay *display, guint *mode_out, guint *detail_out); +MetaDevice *meta_input_event_get_device (MetaDisplay *display, + XEvent *ev); + #endif /* META_EVENT_H */