Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "views/touchui/touch_factory.h" | |
| 6 | |
| 7 #include <gdk/gdkx.h> | |
| 8 #include <X11/extensions/XInput2.h> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 | |
| 12 namespace views { | |
| 13 | |
| 14 // static | |
| 15 TouchFactory* TouchFactory::GetInstance() { | |
| 16 return Singleton<TouchFactory>::get(); | |
| 17 } | |
| 18 | |
| 19 TouchFactory::TouchFactory() : touch_device_lookup_(), | |
|
sky
2011/01/19 19:34:54
put these on the next line and indented 4 spaces.
sadrul
2011/01/19 20:10:17
Done.
| |
| 20 touch_device_list_() { | |
| 21 } | |
| 22 | |
| 23 void TouchFactory::SetTouchDeviceList( | |
| 24 const std::vector<unsigned int>& devices) { | |
| 25 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | |
|
sky
2011/01/19 19:34:54
Do you need to clear out touch_device_lookup_ and
sadrul
2011/01/19 20:10:17
At this moment, this is called exactly once. But r
| |
| 26 iter != devices.end(); ++iter) { | |
|
sky
2011/01/19 19:34:54
indent one more space
sadrul
2011/01/19 20:10:17
Done.
| |
| 27 DCHECK(*iter < touch_device_lookup_.size()); | |
| 28 touch_device_lookup_[*iter] = true; | |
| 29 touch_device_list_.push_back(*iter); | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 bool TouchFactory::IsTouchDevice(unsigned deviceid) { | |
| 34 return deviceid < touch_device_lookup_.size() ? | |
| 35 touch_device_lookup_[deviceid] : false; | |
| 36 } | |
| 37 | |
| 38 bool TouchFactory::GrabTouchDevices(Display* display, ::Window window) { | |
| 39 if (touch_device_list_.size() == 0) | |
|
sky
2011/01/19 19:34:54
empty
sadrul
2011/01/19 20:10:17
Done.
| |
| 40 return true; | |
| 41 | |
| 42 unsigned char mask[(XI_LASTEVENT + 7) / 8]; | |
| 43 bool success = true; | |
| 44 | |
| 45 memset(mask, 0, sizeof(mask)); | |
| 46 XISetMask(mask, XI_ButtonPress); | |
| 47 XISetMask(mask, XI_ButtonRelease); | |
| 48 XISetMask(mask, XI_Motion); | |
| 49 | |
| 50 XIEventMask evmask; | |
| 51 evmask.mask_len = sizeof(mask); | |
| 52 evmask.mask = mask; | |
| 53 for (std::vector<int>::const_iterator iter = | |
| 54 touch_device_list_.begin(); | |
| 55 iter != touch_device_list_.end(); ++iter) { | |
| 56 evmask.deviceid = *iter; | |
| 57 Status status = XIGrabDevice(display, *iter, window, CurrentTime, None, | |
| 58 GrabModeAsync, GrabModeAsync, False, &evmask); | |
| 59 success = success && status == GrabSuccess; | |
| 60 } | |
| 61 | |
| 62 return success; | |
| 63 } | |
| 64 | |
| 65 bool TouchFactory::UngrabTouchDevices(Display* display) { | |
| 66 bool success = true; | |
| 67 for (std::vector<int>::const_iterator iter = | |
| 68 touch_device_list_.begin(); | |
| 69 iter != touch_device_list_.end(); ++iter) { | |
| 70 Status status = XIUngrabDevice(display, *iter, CurrentTime); | |
| 71 success = success && status == GrabSuccess; | |
| 72 } | |
| 73 return success; | |
| 74 } | |
| 75 | |
| 76 } // namespace views | |
| OLD | NEW |