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

Side by Side Diff: views/events/event_x.cc

Issue 7792094: touchui: support XInput2 MT (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: update patch set according to comment #12 Created 9 years, 3 months 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 "views/events/event.h" 5 #include "views/events/event.h"
6 6
7 #include <gdk/gdk.h> 7 #include <gdk/gdk.h>
8 #include <gdk/gdkx.h> 8 #include <gdk/gdkx.h>
9 #include <X11/extensions/XInput2.h> 9 #include <X11/extensions/XInput2.h>
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { 70 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) {
71 if (XIMaskIsSet(xievent->buttons.mask, i)) { 71 if (XIMaskIsSet(xievent->buttons.mask, i)) {
72 buttonflags |= GetEventFlagsForButton(i); 72 buttonflags |= GetEventFlagsForButton(i);
73 } 73 }
74 } 74 }
75 75
76 return buttonflags; 76 return buttonflags;
77 } 77 }
78 78
79 ui::EventType GetTouchEventType(XEvent* xev) { 79 ui::EventType GetTouchEventType(XEvent* xev) {
80 #if defined(USE_XI2_MT)
81 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data);
82 switch(event->evtype) {
83 case XI_TouchBegin:
84 return ui::ET_TOUCH_PRESSED;
85 case XI_TouchUpdate:
86 return ui::ET_TOUCH_MOVED;
87 case XI_TouchEnd:
88 return ui::ET_TOUCH_RELEASED;
89 }
90
91 return ui::ET_UNKNOWN;
92 #else
80 XGenericEventCookie* cookie = &xev->xcookie; 93 XGenericEventCookie* cookie = &xev->xcookie;
81 DCHECK_EQ(cookie->evtype, XI_Motion); 94 DCHECK_EQ(cookie->evtype, XI_Motion);
82 95
83 // Note: We will not generate a _STATIONARY event here. It will be created, 96 // Note: We will not generate a _STATIONARY event here. It will be created,
84 // when necessary, by a RWHVV. 97 // when necessary, by a RWHVV.
85 // TODO(sad): When should _CANCELLED be generated? 98 // TODO(sad): When should _CANCELLED be generated?
86 99
87 TouchFactory* factory = TouchFactory::GetInstance(); 100 TouchFactory* factory = TouchFactory::GetInstance();
88 float slot; 101 float slot;
89 if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_SLOT_ID, &slot)) 102 if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_SLOT_ID, &slot))
90 return ui::ET_UNKNOWN; 103 return ui::ET_UNKNOWN;
91 104
92 if (!factory->IsSlotUsed(slot)) { 105 if (!factory->IsSlotUsed(slot)) {
93 // This is a new touch point. 106 // This is a new touch point.
94 return ui::ET_TOUCH_PRESSED; 107 return ui::ET_TOUCH_PRESSED;
95 } 108 }
96 109
97 float tracking; 110 float tracking;
98 if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_TRACKING_ID, 111 if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_TRACKING_ID,
99 &tracking)) 112 &tracking))
100 return ui::ET_UNKNOWN; 113 return ui::ET_UNKNOWN;
101 114
102 if (tracking == 0l) { 115 if (tracking == 0l) {
103 // The touch point has been released. 116 // The touch point has been released.
104 return ui::ET_TOUCH_RELEASED; 117 return ui::ET_TOUCH_RELEASED;
105 } 118 }
106 119
107 return ui::ET_TOUCH_MOVED; 120 return ui::ET_TOUCH_MOVED;
121 #endif
108 } 122 }
109 123
110 int GetTouchIDFromXEvent(XEvent* xev) { 124 int GetTouchIDFromXEvent(XEvent* xev) {
111 float slot = 0; 125 float id = 0;
126 #if defined(USE_XI2_MT)
127 TouchFactory::TouchParam tp = TouchFactory::TP_TRACKING_ID;
sadrul 2011/09/12 16:20:38 Please add a TODO for fixing up the touch-id (i.e.
ningxin.hu 2011/09/13 00:51:08 Will add the TODO and follow up with a patch. Than
128 #else
129 TouchFactory::TouchParam tp = TouchFactory::TP_SLOT_ID;
130 #endif
112 if (!TouchFactory::GetInstance()->ExtractTouchParam( 131 if (!TouchFactory::GetInstance()->ExtractTouchParam(
113 *xev, TouchFactory::TP_SLOT_ID, &slot)) 132 *xev, tp, &id))
114 LOG(ERROR) << "Could not get the slot ID for the event. Using 0."; 133 LOG(ERROR) << "Could not get the touch ID for the event. Using 0.";
115 return slot; 134 return id;
116 } 135 }
117 136
118 ui::EventType EventTypeFromNative(NativeEvent2 native_event) { 137 ui::EventType EventTypeFromNative(NativeEvent2 native_event) {
119 switch (native_event->type) { 138 switch (native_event->type) {
120 case KeyPress: 139 case KeyPress:
121 return ui::ET_KEY_PRESSED; 140 return ui::ET_KEY_PRESSED;
122 case KeyRelease: 141 case KeyRelease:
123 return ui::ET_KEY_RELEASED; 142 return ui::ET_KEY_RELEASED;
124 case ButtonPress: 143 case ButtonPress:
125 if (native_event->xbutton.button == 4 || 144 if (native_event->xbutton.button == 4 ||
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 radius_x_(GetTouchParamFromXEvent(native_event_2, 415 radius_x_(GetTouchParamFromXEvent(native_event_2,
397 TouchFactory::TP_TOUCH_MAJOR, 416 TouchFactory::TP_TOUCH_MAJOR,
398 2.0) / 2.0), 417 2.0) / 2.0),
399 radius_y_(GetTouchParamFromXEvent(native_event_2, 418 radius_y_(GetTouchParamFromXEvent(native_event_2,
400 TouchFactory::TP_TOUCH_MINOR, 419 TouchFactory::TP_TOUCH_MINOR,
401 2.0) / 2.0), 420 2.0) / 2.0),
402 rotation_angle_(GetTouchParamFromXEvent(native_event_2, 421 rotation_angle_(GetTouchParamFromXEvent(native_event_2,
403 TouchFactory::TP_ORIENTATION, 422 TouchFactory::TP_ORIENTATION,
404 0.0)), 423 0.0)),
405 force_(GetTouchForceFromXEvent(native_event_2)) { 424 force_(GetTouchForceFromXEvent(native_event_2)) {
425 #if !defined(USE_XI2_MT)
406 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { 426 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) {
407 TouchFactory* factory = TouchFactory::GetInstance(); 427 TouchFactory* factory = TouchFactory::GetInstance();
408 float slot; 428 float slot;
409 if (factory->ExtractTouchParam(*native_event_2, 429 if (factory->ExtractTouchParam(*native_event_2,
410 TouchFactory::TP_SLOT_ID, &slot)) { 430 TouchFactory::TP_SLOT_ID, &slot)) {
411 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); 431 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED);
412 } 432 }
413 } 433 }
434 #endif
414 } 435 }
415 436
416 } // namespace views 437 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698