diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-20 16:27:40 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-20 16:27:40 +0000 |
commit | bb3be70c22f021a052c5ced2f4ce229ddf66f705 (patch) | |
tree | bd6b5170276aa6eba646841d12ede0664ecad3f7 /base | |
parent | 86ec4f6ed711a2a58b6e0982b7a0a2fdf95e107a (diff) | |
download | chromium_src-bb3be70c22f021a052c5ced2f4ce229ddf66f705.zip chromium_src-bb3be70c22f021a052c5ced2f4ce229ddf66f705.tar.gz chromium_src-bb3be70c22f021a052c5ced2f4ce229ddf66f705.tar.bz2 |
Maintain the list of devices all in one place.
This effectively moves a bunch of code from the message-pump to the
touch-factory. This way, the list of devices is maintained in one place.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6882083
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82307 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/message_pump_glib_x.cc | 114 | ||||
-rw-r--r-- | base/message_pump_glib_x.h | 11 |
2 files changed, 0 insertions, 125 deletions
diff --git a/base/message_pump_glib_x.cc b/base/message_pump_glib_x.cc index 34313e5..472f68b 100644 --- a/base/message_pump_glib_x.cc +++ b/base/message_pump_glib_x.cc @@ -21,57 +21,6 @@ gboolean PlaceholderDispatch(GSource* source, return TRUE; } -#if defined(HAVE_XINPUT2) - -// Setup XInput2 select for the GtkWidget. -gboolean GtkWidgetRealizeCallback(GSignalInvocationHint* hint, guint nparams, - const GValue* pvalues, gpointer data) { - GtkWidget* widget = GTK_WIDGET(g_value_get_object(pvalues)); - GdkWindow* window = widget->window; - base::MessagePumpGlibX* msgpump = static_cast<base::MessagePumpGlibX*>(data); - - DCHECK(window); // TODO(sad): Remove once determined if necessary. - - if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_TOPLEVEL && - GDK_WINDOW_TYPE(window) != GDK_WINDOW_CHILD && - GDK_WINDOW_TYPE(window) != GDK_WINDOW_DIALOG) - return true; - - // TODO(sad): Do we need to set a flag on |window| to make sure we don't - // select for the same GdkWindow multiple times? Does it matter? - msgpump->SetupXInput2ForXWindow(GDK_WINDOW_XID(window)); - - return true; -} - -// We need to capture all the GDK windows that get created, and start -// listening for XInput2 events. So we setup a callback to the 'realize' -// signal for GTK+ widgets, so that whenever the signal triggers for any -// GtkWidget, which means the GtkWidget should now have a GdkWindow, we can -// setup XInput2 events for the GdkWindow. -static guint realize_signal_id = 0; -static guint realize_hook_id = 0; - -void SetupGtkWidgetRealizeNotifier(base::MessagePumpGlibX* msgpump) { - gpointer klass = g_type_class_ref(GTK_TYPE_WIDGET); - - g_signal_parse_name("realize", GTK_TYPE_WIDGET, - &realize_signal_id, NULL, FALSE); - realize_hook_id = g_signal_add_emission_hook(realize_signal_id, 0, - GtkWidgetRealizeCallback, static_cast<gpointer>(msgpump), NULL); - - g_type_class_unref(klass); -} - -void RemoveGtkWidgetRealizeNotifier() { - if (realize_signal_id != 0) - g_signal_remove_emission_hook(realize_signal_id, realize_hook_id); - realize_signal_id = 0; - realize_hook_id = 0; -} - -#endif // HAVE_XINPUT2 - } // namespace namespace base { @@ -79,7 +28,6 @@ namespace base { MessagePumpGlibX::MessagePumpGlibX() : base::MessagePumpForUI(), #if defined(HAVE_XINPUT2) xiopcode_(-1), - pointer_devices_(), #endif gdksource_(NULL), dispatching_event_(false), @@ -94,41 +42,8 @@ MessagePumpGlibX::MessagePumpGlibX() : base::MessagePumpForUI(), } MessagePumpGlibX::~MessagePumpGlibX() { -#if defined(HAVE_XINPUT2) - RemoveGtkWidgetRealizeNotifier(); -#endif } -#if defined(HAVE_XINPUT2) -void MessagePumpGlibX::SetupXInput2ForXWindow(Window xwindow) { - Display* xdisplay = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); - - // Setup mask for mouse events. - unsigned char mask[(XI_LASTEVENT + 7)/8]; - memset(mask, 0, sizeof(mask)); - - XISetMask(mask, XI_ButtonPress); - XISetMask(mask, XI_ButtonRelease); - XISetMask(mask, XI_Motion); - - XIEventMask evmasks[pointer_devices_.size()]; - int count = 0; - for (std::set<int>::const_iterator iter = pointer_devices_.begin(); - iter != pointer_devices_.end(); - ++iter, ++count) { - evmasks[count].deviceid = *iter; - evmasks[count].mask_len = sizeof(mask); - evmasks[count].mask = mask; - } - - XISelectEvents(xdisplay, xwindow, evmasks, pointer_devices_.size()); - - // TODO(sad): Setup masks for keyboard events. - - XFlush(xdisplay); -} -#endif // HAVE_XINPUT2 - bool MessagePumpGlibX::RunOnce(GMainContext* context, bool block) { GdkDisplay* gdisp = gdk_display_get_default(); if (!gdisp || !GetDispatcher()) @@ -277,35 +192,6 @@ void MessagePumpGlibX::InitializeXInput2(void) { xiopcode_ = -1; return; } - - // TODO(sad): Here, we only setup so that the X windows created by GTK+ are - // setup for XInput2 events. We need a way to listen for XInput2 events for X - // windows created by other means (e.g. for context menus). - SetupGtkWidgetRealizeNotifier(this); - - // Instead of asking X for the list of devices all the time, let's maintain a - // list of pointer devices we care about. - // It is not necessary to select for slave devices. XInput2 provides enough - // information to the event callback to decide which slave device triggered - // the event, thus decide whether the 'pointer event' is a 'mouse event' or a - // 'touch event'. - // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which - // is possible), then the device is detected as a floating device, and a - // floating device is not connected to a master device. So it is necessary to - // also select on the floating devices. - int count = 0; - XIDeviceInfo* devices = XIQueryDevice(xdisplay, XIAllDevices, &count); - for (int i = 0; i < count; i++) { - XIDeviceInfo* devinfo = devices + i; - if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) - pointer_devices_.insert(devinfo->deviceid); - } - XIFreeDeviceInfo(devices); - - // TODO(sad): Select on root for XI_HierarchyChanged so that floats_ and - // masters_ can be kept up-to-date. This is a relatively rare event, so we can - // put it off for a later time. - // Note: It is not necessary to listen for XI_DeviceChanged events. } #endif // HAVE_XINPUT2 diff --git a/base/message_pump_glib_x.h b/base/message_pump_glib_x.h index e8e92d6..60e3b5d 100644 --- a/base/message_pump_glib_x.h +++ b/base/message_pump_glib_x.h @@ -9,7 +9,6 @@ #include "base/message_pump_glib.h" #include <bitset> -#include <set> #include <glib.h> #include <gtk/gtk.h> @@ -26,11 +25,6 @@ class MessagePumpGlibX : public MessagePumpForUI { // was captured and being processed by GDK (when |false|). bool IsDispatchingEvent(void) { return dispatching_event_; } -#if defined(HAVE_XINPUT2) - // Setup an X Window for XInput2 events. - void SetupXInput2ForXWindow(Window xid); -#endif - // Overridden from MessagePumpForUI: virtual bool RunOnce(GMainContext* context, bool block); @@ -47,11 +41,6 @@ class MessagePumpGlibX : public MessagePumpForUI { // The opcode used for checking events. int xiopcode_; - - // The list of pointer devices we care about. We maintain this list so that - // it is not necessary to query X for the list of devices for each - // GdkWindow created. - std::set<int> pointer_devices_; #endif // The event source for GDK events. |