Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: ui/base/x/events_x.cc

Issue 8793002: aura-x11: Add support for xmodmap'ed pointer buttons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "ui/base/events.h" 5 #include "ui/base/events.h"
6 6
7 #include <X11/Xlib.h> 7 #include <X11/Xlib.h>
8 #include <X11/extensions/XInput2.h> 8 #include <X11/extensions/XInput2.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "ui/base/keycodes/keyboard_code_conversion_x.h" 12 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
13 #include "ui/base/touch/touch_factory.h" 13 #include "ui/base/touch/touch_factory.h"
14 #include "ui/base/x/x11_util.h"
14 #include "ui/gfx/point.h" 15 #include "ui/gfx/point.h"
15 16
16 #if !defined(TOOLKIT_USES_GTK) 17 #if !defined(TOOLKIT_USES_GTK)
17 #include "base/message_pump_x.h" 18 #include "base/message_pump_x.h"
18 #endif 19 #endif
19 20
20 namespace { 21 namespace {
21 22
22 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. 23 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+.
23 static const int kWheelScrollAmount = 53; 24 static const int kWheelScrollAmount = 53;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return ui::EF_RIGHT_BUTTON_DOWN; 72 return ui::EF_RIGHT_BUTTON_DOWN;
72 default: 73 default:
73 return 0; 74 return 0;
74 } 75 }
75 } 76 }
76 77
77 int GetButtonMaskForX2Event(XIDeviceEvent* xievent) { 78 int GetButtonMaskForX2Event(XIDeviceEvent* xievent) {
78 int buttonflags = 0; 79 int buttonflags = 0;
79 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { 80 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) {
80 if (XIMaskIsSet(xievent->buttons.mask, i)) { 81 if (XIMaskIsSet(xievent->buttons.mask, i)) {
81 buttonflags |= GetEventFlagsForButton(i); 82 int button = (xievent->sourceid == xievent->deviceid) ?
83 ui::GetMappedButton(i) : i;
84 buttonflags |= GetEventFlagsForButton(button);
82 } 85 }
83 } 86 }
84 return buttonflags; 87 return buttonflags;
85 } 88 }
86 89
87 ui::EventType GetTouchEventType(const base::NativeEvent& native_event) { 90 ui::EventType GetTouchEventType(const base::NativeEvent& native_event) {
88 XIDeviceEvent* event = 91 XIDeviceEvent* event =
89 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 92 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
90 #if defined(USE_XI2_MT) 93 #if defined(USE_XI2_MT)
91 switch(event->evtype) { 94 switch(event->evtype) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return ET_MOUSE_MOVED; 185 return ET_MOUSE_MOVED;
183 case EnterNotify: 186 case EnterNotify:
184 return ET_MOUSE_ENTERED; 187 return ET_MOUSE_ENTERED;
185 case LeaveNotify: 188 case LeaveNotify:
186 return ET_MOUSE_EXITED; 189 return ET_MOUSE_EXITED;
187 case GenericEvent: { 190 case GenericEvent: {
188 XIDeviceEvent* xievent = 191 XIDeviceEvent* xievent =
189 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 192 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
190 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) 193 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid))
191 return GetTouchEventType(native_event); 194 return GetTouchEventType(native_event);
195 int button = EventButtonFromNative(native_event);
192 switch (xievent->evtype) { 196 switch (xievent->evtype) {
193 case XI_ButtonPress: 197 case XI_ButtonPress:
194 if (xievent->detail >= kMinWheelButton && 198 if (button >= kMinWheelButton &&
195 xievent->detail <= kMaxWheelButton) 199 button <= kMaxWheelButton)
196 return ET_MOUSEWHEEL; 200 return ET_MOUSEWHEEL;
197 return ET_MOUSE_PRESSED; 201 return ET_MOUSE_PRESSED;
198 case XI_ButtonRelease: 202 case XI_ButtonRelease:
199 if (xievent->detail >= kMinWheelButton && 203 if (button >= kMinWheelButton &&
200 xievent->detail <= kMaxWheelButton) 204 button <= kMaxWheelButton)
201 return ET_MOUSEWHEEL; 205 return ET_MOUSEWHEEL;
202 return ET_MOUSE_RELEASED; 206 return ET_MOUSE_RELEASED;
203 case XI_Motion: 207 case XI_Motion:
204 return GetButtonMaskForX2Event(xievent) ? 208 return GetButtonMaskForX2Event(xievent) ?
205 ET_MOUSE_DRAGGED : ET_MOUSE_MOVED; 209 ET_MOUSE_DRAGGED : ET_MOUSE_MOVED;
206 } 210 }
207 } 211 }
208 default: 212 default:
209 break; 213 break;
210 } 214 }
(...skipping 19 matching lines...) Expand all
230 XIDeviceEvent* xievent = 234 XIDeviceEvent* xievent =
231 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 235 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
232 const bool touch = 236 const bool touch =
233 TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid); 237 TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid);
234 switch (xievent->evtype) { 238 switch (xievent->evtype) {
235 case XI_ButtonPress: 239 case XI_ButtonPress:
236 case XI_ButtonRelease: { 240 case XI_ButtonRelease: {
237 int flags = GetButtonMaskForX2Event(xievent) | 241 int flags = GetButtonMaskForX2Event(xievent) |
238 GetEventFlagsFromXState(xievent->mods.effective); 242 GetEventFlagsFromXState(xievent->mods.effective);
239 const EventType type = EventTypeFromNative(native_event); 243 const EventType type = EventTypeFromNative(native_event);
244 int button = EventButtonFromNative(native_event);
240 if ((type == ET_MOUSE_PRESSED || type == ET_MOUSE_RELEASED) && !touch) 245 if ((type == ET_MOUSE_PRESSED || type == ET_MOUSE_RELEASED) && !touch)
241 flags |= GetEventFlagsForButton(xievent->detail); 246 flags |= GetEventFlagsForButton(button);
242 return flags; 247 return flags;
243 } 248 }
244 case XI_Motion: 249 case XI_Motion:
245 return GetButtonMaskForX2Event(xievent) | 250 return GetButtonMaskForX2Event(xievent) |
246 GetEventFlagsFromXState(xievent->mods.effective); 251 GetEventFlagsFromXState(xievent->mods.effective);
247 } 252 }
248 } 253 }
249 } 254 }
250 return 0; 255 return 0;
251 } 256 }
(...skipping 26 matching lines...) Expand all
278 double y = xievent->event_y; 283 double y = xievent->event_y;
279 if (XIMaskIsSet(xievent->valuators.mask, 1)) 284 if (XIMaskIsSet(xievent->valuators.mask, 1))
280 y = *valuators++ - (xievent->root_y - xievent->event_y); 285 y = *valuators++ - (xievent->root_y - xievent->event_y);
281 286
282 return gfx::Point(static_cast<int>(x), static_cast<int>(y)); 287 return gfx::Point(static_cast<int>(x), static_cast<int>(y));
283 } 288 }
284 } 289 }
285 return gfx::Point(); 290 return gfx::Point();
286 } 291 }
287 292
293 int EventButtonFromNative(const base::NativeEvent& native_event) {
294 CHECK_EQ(GenericEvent, native_event->type);
295 XIDeviceEvent* xievent =
296 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
297 int button = xievent->detail;
298
299 return (xievent->sourceid == xievent->deviceid) ?
300 ui::GetMappedButton(button) : button;
301 }
302
288 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { 303 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) {
289 return KeyboardCodeFromXKeyEvent(native_event); 304 return KeyboardCodeFromXKeyEvent(native_event);
290 } 305 }
291 306
292 bool IsMouseEvent(const base::NativeEvent& native_event) { 307 bool IsMouseEvent(const base::NativeEvent& native_event) {
293 if (native_event->type == ButtonPress || 308 if (native_event->type == ButtonPress ||
294 native_event->type == ButtonRelease || 309 native_event->type == ButtonRelease ||
295 native_event->type == MotionNotify) 310 native_event->type == MotionNotify)
296 return true; 311 return true;
297 if (native_event->type == GenericEvent) { 312 if (native_event->type == GenericEvent) {
298 XIDeviceEvent* xievent = 313 XIDeviceEvent* xievent =
299 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 314 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
300 return xievent->evtype == XI_ButtonPress || 315 return xievent->evtype == XI_ButtonPress ||
301 xievent->evtype == XI_ButtonRelease || 316 xievent->evtype == XI_ButtonRelease ||
302 xievent->evtype == XI_Motion; 317 xievent->evtype == XI_Motion;
303 } 318 }
304 return false; 319 return false;
305 } 320 }
306 321
307 int GetMouseWheelOffset(const base::NativeEvent& native_event) { 322 int GetMouseWheelOffset(const base::NativeEvent& native_event) {
308 int button; 323 int button;
309 if (native_event->type == GenericEvent) { 324 if (native_event->type == GenericEvent)
310 XIDeviceEvent* xiev = 325 button = EventButtonFromNative(native_event);
311 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 326 else
312 button = xiev->detail;
313 } else {
314 button = native_event->xbutton.button; 327 button = native_event->xbutton.button;
315 }
316 switch (button) { 328 switch (button) {
317 case 4: 329 case 4:
318 #if defined(OS_CHROMEOS) 330 #if defined(OS_CHROMEOS)
319 return kTouchpadScrollAmount; 331 return kTouchpadScrollAmount;
320 case 8: 332 case 8:
321 #endif 333 #endif
322 return kWheelScrollAmount; 334 return kWheelScrollAmount;
323 335
324 case 5: 336 case 5:
325 #if defined(OS_CHROMEOS) 337 #if defined(OS_CHROMEOS)
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // Make sure we use atom from current xdisplay, which may 416 // Make sure we use atom from current xdisplay, which may
405 // change during the test. 417 // change during the test.
406 noop->xclient.message_type = XInternAtom( 418 noop->xclient.message_type = XInternAtom(
407 base::MessagePumpX::GetDefaultXDisplay(), 419 base::MessagePumpX::GetDefaultXDisplay(),
408 "noop", False); 420 "noop", False);
409 #endif 421 #endif
410 return noop; 422 return noop;
411 } 423 }
412 424
413 } // namespace ui 425 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/events.h ('k') | ui/base/x/x11_util.h » ('j') | ui/base/x/x11_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698