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

Side by Side Diff: ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.cc

Issue 990483002: ozone: evdev: Fix possibility of stuck keys with libevdev (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr os.h" 5 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr os.h"
6 6
7 #include <gestures/gestures.h> 7 #include <gestures/gestures.h>
8 #include <libevdev/libevdev.h> 8 #include <libevdev/libevdev.h>
9 #include <linux/input.h> 9 #include <linux/input.h>
10 10
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 static_cast<GestureInterpreterLibevdevCros*>(client_data); 72 static_cast<GestureInterpreterLibevdevCros*>(client_data);
73 interpreter->OnGestureReady(gesture); 73 interpreter->OnGestureReady(gesture);
74 } 74 }
75 75
76 // Convert gestures timestamp (stime_t) to ui::Event timestamp. 76 // Convert gestures timestamp (stime_t) to ui::Event timestamp.
77 base::TimeDelta StimeToTimedelta(stime_t timestamp) { 77 base::TimeDelta StimeToTimedelta(stime_t timestamp) {
78 return base::TimeDelta::FromMicroseconds(timestamp * 78 return base::TimeDelta::FromMicroseconds(timestamp *
79 base::Time::kMicrosecondsPerSecond); 79 base::Time::kMicrosecondsPerSecond);
80 } 80 }
81 81
82 base::TimeDelta TimeValToTimeDelta(const timeval& tv) {
83 return base::TimeDelta::FromMicroseconds(tv.tv_sec * 1000000 + tv.tv_usec);
84 }
85
86 // Number of fingers for scroll gestures. 82 // Number of fingers for scroll gestures.
87 const int kGestureScrollFingerCount = 2; 83 const int kGestureScrollFingerCount = 2;
88 84
89 // Number of fingers for swipe gestures. 85 // Number of fingers for swipe gestures.
90 const int kGestureSwipeFingerCount = 3; 86 const int kGestureSwipeFingerCount = 3;
91 87
92 } // namespace 88 } // namespace
93 89
94 GestureInterpreterLibevdevCros::GestureInterpreterLibevdevCros( 90 GestureInterpreterLibevdevCros::GestureInterpreterLibevdevCros(
95 int id, 91 int id,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 GestureInterpreterSetTimerProvider( 149 GestureInterpreterSetTimerProvider(
154 interpreter_, 150 interpreter_,
155 const_cast<GesturesTimerProvider*>(&kGestureTimerProvider), 151 const_cast<GesturesTimerProvider*>(&kGestureTimerProvider),
156 this); 152 this);
157 GestureInterpreterSetCallback(interpreter_, OnGestureReadyHelper, this); 153 GestureInterpreterSetCallback(interpreter_, OnGestureReadyHelper, this);
158 } 154 }
159 155
160 void GestureInterpreterLibevdevCros::OnLibEvdevCrosEvent(Evdev* evdev, 156 void GestureInterpreterLibevdevCros::OnLibEvdevCrosEvent(Evdev* evdev,
161 EventStateRec* evstate, 157 EventStateRec* evstate,
162 const timeval& time) { 158 const timeval& time) {
163 // If the device has keys no it, dispatch any presses/release. 159 stime_t timestamp = StimeFromTimeval(&time);
164 DispatchChangedKeys(evdev, time); 160
161 // If the device has keys on it, dispatch any presses/release.
162 DispatchChangedKeys(evdev->key_state_bitmask, timestamp);
165 163
166 HardwareState hwstate; 164 HardwareState hwstate;
167 memset(&hwstate, 0, sizeof(hwstate)); 165 memset(&hwstate, 0, sizeof(hwstate));
168 hwstate.timestamp = StimeFromTimeval(&time); 166 hwstate.timestamp = timestamp;
169 167
170 // Mouse. 168 // Mouse.
171 hwstate.rel_x = evstate->rel_x; 169 hwstate.rel_x = evstate->rel_x;
172 hwstate.rel_y = evstate->rel_y; 170 hwstate.rel_y = evstate->rel_y;
173 hwstate.rel_wheel = evstate->rel_wheel; 171 hwstate.rel_wheel = evstate->rel_wheel;
174 hwstate.rel_hwheel = evstate->rel_hwheel; 172 hwstate.rel_hwheel = evstate->rel_hwheel;
175 173
176 // Touch. 174 // Touch.
177 FingerState fingers[Event_Get_Slot_Count(evdev)]; 175 FingerState fingers[Event_Get_Slot_Count(evdev)];
178 memset(&fingers, 0, sizeof(fingers)); 176 memset(&fingers, 0, sizeof(fingers));
(...skipping 21 matching lines...) Expand all
200 if (Event_Get_Button_Left(evdev)) 198 if (Event_Get_Button_Left(evdev))
201 hwstate.buttons_down |= GESTURES_BUTTON_LEFT; 199 hwstate.buttons_down |= GESTURES_BUTTON_LEFT;
202 if (Event_Get_Button_Middle(evdev)) 200 if (Event_Get_Button_Middle(evdev))
203 hwstate.buttons_down |= GESTURES_BUTTON_MIDDLE; 201 hwstate.buttons_down |= GESTURES_BUTTON_MIDDLE;
204 if (Event_Get_Button_Right(evdev)) 202 if (Event_Get_Button_Right(evdev))
205 hwstate.buttons_down |= GESTURES_BUTTON_RIGHT; 203 hwstate.buttons_down |= GESTURES_BUTTON_RIGHT;
206 204
207 GestureInterpreterPushHardwareState(interpreter_, &hwstate); 205 GestureInterpreterPushHardwareState(interpreter_, &hwstate);
208 } 206 }
209 207
208 void GestureInterpreterLibevdevCros::OnLibEvdevCrosStopped(
209 Evdev* evdev,
210 EventStateRec* state) {
211 ReleaseKeys();
212 }
213
210 void GestureInterpreterLibevdevCros::SetAllowedKeys( 214 void GestureInterpreterLibevdevCros::SetAllowedKeys(
211 scoped_ptr<std::set<DomCode>> allowed_keys) { 215 scoped_ptr<std::set<DomCode>> allowed_keys) {
212 if (!allowed_keys) { 216 if (!allowed_keys) {
213 allowed_keys_.reset(); 217 allowed_keys_.reset();
214 return; 218 return;
215 } 219 }
216 220
217 allowed_keys_.reset(new std::set<int>()); 221 allowed_keys_.reset(new std::set<int>());
218 for (const auto& it : *allowed_keys) { 222 for (const auto& it : *allowed_keys) {
219 int evdev_code = 223 int evdev_code =
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 418
415 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button, 419 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button,
416 bool down, 420 bool down,
417 stime_t time) { 421 stime_t time) {
418 bool allow_remap = is_mouse_; 422 bool allow_remap = is_mouse_;
419 dispatcher_->DispatchMouseButtonEvent( 423 dispatcher_->DispatchMouseButtonEvent(
420 MouseButtonEventParams(id_, cursor_->GetLocation(), button, down, 424 MouseButtonEventParams(id_, cursor_->GetLocation(), button, down,
421 allow_remap, StimeToTimedelta(time))); 425 allow_remap, StimeToTimedelta(time)));
422 } 426 }
423 427
424 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev, 428 void GestureInterpreterLibevdevCros::DispatchChangedKeys(
425 const timeval& time) { 429 unsigned long* new_key_state,
430 stime_t timestamp) {
426 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; 431 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)];
427 432
428 // Find changed keys. 433 // Find changed keys.
429 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i) 434 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i)
430 key_state_diff[i] = evdev->key_state_bitmask[i] ^ prev_key_state_[i]; 435 key_state_diff[i] = new_key_state[i] ^ prev_key_state_[i];
431 436
432 // Dispatch events for changed keys. 437 // Dispatch events for changed keys.
433 for (unsigned long key = 0; key < KEY_CNT; ++key) { 438 for (unsigned long key = 0; key < KEY_CNT; ++key) {
434 if (EvdevBitIsSet(key_state_diff, key)) { 439 if (EvdevBitIsSet(key_state_diff, key)) {
435 bool value = EvdevBitIsSet(evdev->key_state_bitmask, key); 440 bool value = EvdevBitIsSet(new_key_state, key);
436 441
437 // Mouse buttons are handled by DispatchMouseButton. 442 // Mouse buttons are handled by DispatchMouseButton.
438 if (key >= BTN_MOUSE && key < BTN_JOYSTICK) 443 if (key >= BTN_MOUSE && key < BTN_JOYSTICK)
439 continue; 444 continue;
440 445
441 // Ignore digi buttons (e.g. BTN_TOOL_FINGER). 446 // Ignore digi buttons (e.g. BTN_TOOL_FINGER).
442 if (key >= BTN_DIGI && key < BTN_WHEEL) 447 if (key >= BTN_DIGI && key < BTN_WHEEL)
443 continue; 448 continue;
444 449
445 if (allowed_keys_ && !allowed_keys_->count(key)) 450 if (allowed_keys_ && !allowed_keys_->count(key))
446 continue; 451 continue;
447 452
448 // Dispatch key press or release to keyboard. 453 // Dispatch key press or release to keyboard.
449 dispatcher_->DispatchKeyEvent( 454 dispatcher_->DispatchKeyEvent(
450 KeyEventParams(id_, key, value, TimeValToTimeDelta(time))); 455 KeyEventParams(id_, key, value, StimeToTimedelta(timestamp)));
451 } 456 }
452 } 457 }
453 458
454 // Update internal key state. 459 // Update internal key state.
455 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) 460 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i)
456 prev_key_state_[i] = evdev->key_state_bitmask[i]; 461 prev_key_state_[i] = new_key_state[i];
462 }
463
464 void GestureInterpreterLibevdevCros::ReleaseKeys() {
465 unsigned long new_key_state[EVDEV_BITS_TO_LONGS(KEY_CNT)];
466 memset(&new_key_state, 0, sizeof(new_key_state));
467
468 DispatchChangedKeys(new_key_state, StimeNow());
457 } 469 }
458 470
459 } // namespace ui 471 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698