input-events: Add method to get the device for an event

This commit is contained in:
Carlos Garnacho 2011-06-11 22:16:28 +02:00
parent 50cee11c53
commit 722420df3a
2 changed files with 65 additions and 1 deletions

View File

@ -23,6 +23,8 @@
#include <config.h>
#include "input-events.h"
#include "devices-core.h"
#include "device-map.h"
#include <X11/Xlib.h>
#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;
}

View File

@ -33,7 +33,7 @@
#include <config.h>
#include <X11/Xlib.h>
#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 */