Chromium Code Reviews| 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 "ui/base/touch/touch_factory.h" | 5 #include "ui/base/touch/touch_factory.h" |
| 6 | 6 |
| 7 #include <X11/cursorfont.h> | 7 #include <X11/cursorfont.h> |
| 8 #include <X11/extensions/XInput.h> | 8 #include <X11/extensions/XInput.h> |
| 9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
| 10 #include <X11/extensions/XIproto.h> | 10 #include <X11/extensions/XIproto.h> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "ui/base/x/x11_util.h" | 16 #include "ui/base/x/x11_util.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Keeps track of a string returned by an X function (e.g. XGetAtomName) and | |
| 21 // makes sure it's XFree'd. | |
| 22 class XScopedString { | |
|
sky
2012/02/06 21:43:00
Should this live in ui/base/x?
sadrul
2012/02/07 19:45:24
Sounds like a good idea. I moved this into x11_uti
| |
| 23 public: | |
| 24 explicit XScopedString(const char *str) : string_(str) { } | |
| 25 ~XScopedString() { | |
| 26 XFree(string_); | |
| 27 } | |
| 28 | |
| 29 const char *string() const { return string_; } | |
| 30 | |
| 31 private: | |
| 32 const char *string_; | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(XScopedString); | |
| 35 }; | |
| 36 | |
| 20 // The X cursor is hidden if it is idle for kCursorIdleSeconds seconds. | 37 // The X cursor is hidden if it is idle for kCursorIdleSeconds seconds. |
| 21 int kCursorIdleSeconds = 5; | 38 int kCursorIdleSeconds = 5; |
| 22 | 39 |
| 23 // Given the TouchParam, return the correspoding XIValuatorClassInfo using | 40 // Given the TouchParam, return the correspoding XIValuatorClassInfo using |
| 24 // the X device information through Atom name matching. | 41 // the X device information through Atom name matching. |
| 25 XIValuatorClassInfo* FindTPValuator(Display* display, | 42 XIValuatorClassInfo* FindTPValuator(Display* display, |
| 26 XIDeviceInfo* info, | 43 XIDeviceInfo* info, |
| 27 ui::TouchFactory::TouchParam tp) { | 44 ui::TouchFactory::TouchParam tp) { |
| 28 // Lookup table for mapping TouchParam to Atom string used in X. | 45 // Lookup table for mapping TouchParam to Atom string used in X. |
| 29 // A full set of Atom strings can be found at xserver-properties.h. | 46 // A full set of Atom strings can be found at xserver-properties.h. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 57 if (!atom_tp) | 74 if (!atom_tp) |
| 58 return NULL; | 75 return NULL; |
| 59 | 76 |
| 60 for (int i = 0; i < info->num_classes; i++) { | 77 for (int i = 0; i < info->num_classes; i++) { |
| 61 if (info->classes[i]->type != XIValuatorClass) | 78 if (info->classes[i]->type != XIValuatorClass) |
| 62 continue; | 79 continue; |
| 63 XIValuatorClassInfo* v = | 80 XIValuatorClassInfo* v = |
| 64 reinterpret_cast<XIValuatorClassInfo*>(info->classes[i]); | 81 reinterpret_cast<XIValuatorClassInfo*>(info->classes[i]); |
| 65 | 82 |
| 66 if (v->label) { | 83 if (v->label) { |
| 67 const char* atom = XGetAtomName(display, v->label); | 84 XScopedString atom(XGetAtomName(display, v->label)); |
| 68 if (atom && strcmp(atom, atom_tp) == 0) | 85 if (atom.string() && strcmp(atom.string(), atom_tp) == 0) |
| 69 return v; | 86 return v; |
| 70 } | 87 } |
| 71 } | 88 } |
| 72 | 89 |
| 73 return NULL; | 90 return NULL; |
| 74 } | 91 } |
| 75 | 92 |
| 76 } // namespace | 93 } // namespace |
| 77 | 94 |
| 78 namespace ui { | 95 namespace ui { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 // If XInput2 is not supported, this will return null (with count of -1) so | 161 // If XInput2 is not supported, this will return null (with count of -1) so |
| 145 // we assume there cannot be any touch devices. | 162 // we assume there cannot be any touch devices. |
| 146 int count = 0; | 163 int count = 0; |
| 147 touch_device_available_ = false; | 164 touch_device_available_ = false; |
| 148 touch_device_lookup_.reset(); | 165 touch_device_lookup_.reset(); |
| 149 touch_device_list_.clear(); | 166 touch_device_list_.clear(); |
| 150 #if !defined(USE_XI2_MT) | 167 #if !defined(USE_XI2_MT) |
| 151 XDeviceInfo* devlist = XListInputDevices(display, &count); | 168 XDeviceInfo* devlist = XListInputDevices(display, &count); |
| 152 for (int i = 0; i < count; i++) { | 169 for (int i = 0; i < count; i++) { |
| 153 if (devlist[i].type) { | 170 if (devlist[i].type) { |
| 154 const char* devtype = XGetAtomName(display, devlist[i].type); | 171 XScopedString devtype(XGetAtomName(display, devlist[i].type)); |
| 155 if (devtype && !strcmp(devtype, XI_TOUCHSCREEN)) { | 172 if (devtype.string() && !strcmp(devtype.string(), XI_TOUCHSCREEN)) { |
| 156 touch_device_lookup_[devlist[i].id] = true; | 173 touch_device_lookup_[devlist[i].id] = true; |
| 157 touch_device_list_[devlist[i].id] = true; | 174 touch_device_list_[devlist[i].id] = true; |
| 158 touch_device_available_ = true; | 175 touch_device_available_ = true; |
| 159 } | 176 } |
| 160 } | 177 } |
| 161 } | 178 } |
| 162 if (devlist) | 179 if (devlist) |
| 163 XFreeDeviceList(devlist); | 180 XFreeDeviceList(devlist); |
| 164 #endif | 181 #endif |
| 165 | 182 |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 float* max) { | 510 float* max) { |
| 494 if (valuator_lookup_[deviceid][tp] >= 0) { | 511 if (valuator_lookup_[deviceid][tp] >= 0) { |
| 495 *min = touch_param_min_[deviceid][tp]; | 512 *min = touch_param_min_[deviceid][tp]; |
| 496 *max = touch_param_max_[deviceid][tp]; | 513 *max = touch_param_max_[deviceid][tp]; |
| 497 return true; | 514 return true; |
| 498 } | 515 } |
| 499 return false; | 516 return false; |
| 500 } | 517 } |
| 501 | 518 |
| 502 } // namespace ui | 519 } // namespace ui |
| OLD | NEW |