OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/message_pump_glib_x.h" | 5 #include "base/message_pump_glib_x.h" |
6 | 6 |
7 #include <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
8 #if defined(HAVE_XINPUT2) | 8 #if defined(HAVE_XINPUT2) |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 #else | 10 #else |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 #endif // HAVE_XINPUT2 | 73 #endif // HAVE_XINPUT2 |
74 | 74 |
75 } // namespace | 75 } // namespace |
76 | 76 |
77 namespace base { | 77 namespace base { |
78 | 78 |
79 MessagePumpGlibX::MessagePumpGlibX() : base::MessagePumpForUI(), | 79 MessagePumpGlibX::MessagePumpGlibX() : base::MessagePumpForUI(), |
80 #if defined(HAVE_XINPUT2) | 80 #if defined(HAVE_XINPUT2) |
81 xiopcode_(-1), | 81 xiopcode_(-1), |
82 masters_(), | 82 pointer_devices_(), |
83 floats_(), | |
84 #endif | 83 #endif |
85 gdksource_(NULL), | 84 gdksource_(NULL), |
86 dispatching_event_(false), | 85 dispatching_event_(false), |
87 capture_x_events_(0), | 86 capture_x_events_(0), |
88 capture_gdk_events_(0) { | 87 capture_gdk_events_(0) { |
89 gdk_event_handler_set(&EventDispatcherX, this, NULL); | 88 gdk_event_handler_set(&EventDispatcherX, this, NULL); |
90 | 89 |
91 #if defined(HAVE_XINPUT2) | 90 #if defined(HAVE_XINPUT2) |
92 InitializeXInput2(); | 91 InitializeXInput2(); |
93 #endif | 92 #endif |
(...skipping 11 matching lines...) Expand all Loading... |
105 Display* xdisplay = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); | 104 Display* xdisplay = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); |
106 | 105 |
107 // Setup mask for mouse events. | 106 // Setup mask for mouse events. |
108 unsigned char mask[(XI_LASTEVENT + 7)/8]; | 107 unsigned char mask[(XI_LASTEVENT + 7)/8]; |
109 memset(mask, 0, sizeof(mask)); | 108 memset(mask, 0, sizeof(mask)); |
110 | 109 |
111 XISetMask(mask, XI_ButtonPress); | 110 XISetMask(mask, XI_ButtonPress); |
112 XISetMask(mask, XI_ButtonRelease); | 111 XISetMask(mask, XI_ButtonRelease); |
113 XISetMask(mask, XI_Motion); | 112 XISetMask(mask, XI_Motion); |
114 | 113 |
115 // It is not necessary to select for slave devices. XInput2 provides enough | 114 XIEventMask evmasks[pointer_devices_.size()]; |
116 // information to the event callback to decide which slave device triggered | |
117 // the event, thus decide whether the 'pointer event' is a 'mouse event' or a | |
118 // 'touch event'. | |
119 // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which | |
120 // is possible), then the device is detected as a floating device, and a | |
121 // floating device is not connected to a master device. So it is necessary to | |
122 // also select on the floating devices. | |
123 std::set<int> devices; | |
124 std::set_union(masters_.begin(), masters_.end(), | |
125 floats_.begin(), floats_.end(), | |
126 std::inserter(devices, devices.begin())); | |
127 XIEventMask evmasks[devices.size()]; | |
128 int count = 0; | 115 int count = 0; |
129 for (std::set<int>::const_iterator iter = devices.begin(); | 116 for (std::set<int>::const_iterator iter = pointer_devices_.begin(); |
130 iter != devices.end(); | 117 iter != pointer_devices_.end(); |
131 ++iter, ++count) { | 118 ++iter, ++count) { |
132 evmasks[count].deviceid = *iter; | 119 evmasks[count].deviceid = *iter; |
133 evmasks[count].mask_len = sizeof(mask); | 120 evmasks[count].mask_len = sizeof(mask); |
134 evmasks[count].mask = mask; | 121 evmasks[count].mask = mask; |
135 } | 122 } |
136 | 123 |
137 XISelectEvents(xdisplay, xwindow, evmasks, devices.size()); | 124 XISelectEvents(xdisplay, xwindow, evmasks, pointer_devices_.size()); |
138 | 125 |
139 // TODO(sad): Setup masks for keyboard events. | 126 // TODO(sad): Setup masks for keyboard events. |
140 | 127 |
141 XFlush(xdisplay); | 128 XFlush(xdisplay); |
142 } | 129 } |
143 #endif // HAVE_XINPUT2 | 130 #endif // HAVE_XINPUT2 |
144 | 131 |
145 bool MessagePumpGlibX::RunOnce(GMainContext* context, bool block) { | 132 bool MessagePumpGlibX::RunOnce(GMainContext* context, bool block) { |
146 GdkDisplay* gdisp = gdk_display_get_default(); | 133 GdkDisplay* gdisp = gdk_display_get_default(); |
147 if (!gdisp || !GetDispatcher()) | 134 if (!gdisp || !GetDispatcher()) |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 xiopcode_ = -1; | 277 xiopcode_ = -1; |
291 return; | 278 return; |
292 } | 279 } |
293 | 280 |
294 // TODO(sad): Here, we only setup so that the X windows created by GTK+ are | 281 // TODO(sad): Here, we only setup so that the X windows created by GTK+ are |
295 // setup for XInput2 events. We need a way to listen for XInput2 events for X | 282 // setup for XInput2 events. We need a way to listen for XInput2 events for X |
296 // windows created by other means (e.g. for context menus). | 283 // windows created by other means (e.g. for context menus). |
297 SetupGtkWidgetRealizeNotifier(this); | 284 SetupGtkWidgetRealizeNotifier(this); |
298 | 285 |
299 // Instead of asking X for the list of devices all the time, let's maintain a | 286 // Instead of asking X for the list of devices all the time, let's maintain a |
300 // list of slave (physical) and master (virtual) pointer devices. | 287 // list of pointer devices we care about. |
| 288 // It is not necessary to select for slave devices. XInput2 provides enough |
| 289 // information to the event callback to decide which slave device triggered |
| 290 // the event, thus decide whether the 'pointer event' is a 'mouse event' or a |
| 291 // 'touch event'. |
| 292 // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which |
| 293 // is possible), then the device is detected as a floating device, and a |
| 294 // floating device is not connected to a master device. So it is necessary to |
| 295 // also select on the floating devices. |
301 int count = 0; | 296 int count = 0; |
302 XIDeviceInfo* devices = XIQueryDevice(xdisplay, XIAllDevices, &count); | 297 XIDeviceInfo* devices = XIQueryDevice(xdisplay, XIAllDevices, &count); |
303 for (int i = 0; i < count; i++) { | 298 for (int i = 0; i < count; i++) { |
304 XIDeviceInfo* devinfo = devices + i; | 299 XIDeviceInfo* devinfo = devices + i; |
305 if (devinfo->use == XIFloatingSlave) { | 300 if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) |
306 floats_.insert(devinfo->deviceid); | 301 pointer_devices_.insert(devinfo->deviceid); |
307 } else if (devinfo->use == XIMasterPointer) { | |
308 masters_.insert(devinfo->deviceid); | |
309 } | |
310 } | 302 } |
311 XIFreeDeviceInfo(devices); | 303 XIFreeDeviceInfo(devices); |
312 | 304 |
313 // TODO(sad): Select on root for XI_HierarchyChanged so that floats_ and | 305 // TODO(sad): Select on root for XI_HierarchyChanged so that floats_ and |
314 // masters_ can be kept up-to-date. This is a relatively rare event, so we can | 306 // masters_ can be kept up-to-date. This is a relatively rare event, so we can |
315 // put it off for a later time. | 307 // put it off for a later time. |
316 // Note: It is not necessary to listen for XI_DeviceChanged events. | 308 // Note: It is not necessary to listen for XI_DeviceChanged events. |
317 } | 309 } |
318 #endif // HAVE_XINPUT2 | 310 #endif // HAVE_XINPUT2 |
319 | 311 |
320 } // namespace base | 312 } // namespace base |
OLD | NEW |