Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/display/chromeos/x11/touchscreen_device_manager_x11.h" | 5 #include "ui/display/chromeos/x11/touchscreen_device_manager_x11.h" |
| 6 | 6 |
| 7 #include <X11/extensions/XInput.h> | 7 #include <X11/extensions/XInput.h> |
| 8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include "base/command_line.h" | |
| 14 #include "base/logging.h" | |
| 15 #include "base/process/launch.h" | |
| 16 #include "base/sys_info.h" | |
| 13 #include "ui/gfx/x/x11_types.h" | 17 #include "ui/gfx/x/x11_types.h" |
| 14 | 18 |
| 19 namespace { | |
| 20 | |
| 21 bool IsTouchscreenInternal(Display* dpy, int device_id) { | |
| 22 bool ret = false; | |
|
Daniel Erat
2014/07/16 02:59:46
i don't see any benefit from declaring this so ear
Yufeng Shen (Slow to review)
2014/07/16 20:20:28
Done.
| |
| 23 if (!base::SysInfo::IsRunningOnChromeOS()) | |
| 24 return ret; | |
| 25 | |
| 26 // Input device has a property "Device Node" pointing to its dev input node, | |
| 27 // e.g. Device Node (250): "/dev/input/event8" | |
| 28 Atom device_node = XInternAtom(dpy, "Device Node", False); | |
| 29 if (device_node == None) | |
| 30 return ret; | |
| 31 | |
| 32 Atom act_type; | |
| 33 int act_format; | |
|
Daniel Erat
2014/07/16 02:59:46
nit: remove double-space between int and act_forma
Yufeng Shen (Slow to review)
2014/07/16 20:20:28
Done.
| |
| 34 unsigned long nitems, bytes_after; | |
| 35 unsigned char *data; | |
|
Daniel Erat
2014/07/16 02:59:46
* goes on left side of space
Yufeng Shen (Slow to review)
2014/07/16 20:20:28
Done.
| |
| 36 XDevice* dev = XOpenDevice(dpy, device_id); | |
| 37 if (!dev) | |
| 38 return ret; | |
| 39 | |
| 40 if (XGetDeviceProperty(dpy, dev, device_node, 0, 1000, False, | |
| 41 AnyPropertyType, &act_type, &act_format, | |
| 42 &nitems, &bytes_after, &data) == Success) { | |
| 43 // Script is_touchscreen_internal takes in the dev input node and | |
| 44 // returns if the according touchscreen is an internal touchscreen. | |
| 45 CommandLine command( | |
| 46 base::FilePath("/opt/google/touchscreen/is_touchscreen_internal")); | |
|
Daniel Erat
2014/07/16 02:59:46
why is this a separate script? putting the logic i
Yufeng Shen (Slow to review)
2014/07/16 20:20:28
yeah, why not.
done.
| |
| 47 command.AppendArg(reinterpret_cast<char*>(data)); | |
| 48 std::string output; | |
| 49 ret = GetAppOutput(command, &output); | |
| 50 XFree(data); | |
| 51 XCloseDevice(dpy, dev); | |
| 52 } | |
| 53 return ret; | |
| 54 } | |
| 55 | |
| 56 } | |
| 57 | |
| 15 namespace ui { | 58 namespace ui { |
| 16 | 59 |
| 17 TouchscreenDeviceManagerX11::TouchscreenDeviceManagerX11() | 60 TouchscreenDeviceManagerX11::TouchscreenDeviceManagerX11() |
| 18 : display_(gfx::GetXDisplay()) {} | 61 : display_(gfx::GetXDisplay()) {} |
| 19 | 62 |
| 20 TouchscreenDeviceManagerX11::~TouchscreenDeviceManagerX11() {} | 63 TouchscreenDeviceManagerX11::~TouchscreenDeviceManagerX11() {} |
| 21 | 64 |
| 22 std::vector<TouchscreenDevice> TouchscreenDeviceManagerX11::GetDevices() { | 65 std::vector<TouchscreenDevice> TouchscreenDeviceManagerX11::GetDevices() { |
| 23 std::vector<TouchscreenDevice> devices; | 66 std::vector<TouchscreenDevice> devices; |
| 24 int num_devices = 0; | 67 int num_devices = 0; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 XITouchClassInfo* touch_info = | 106 XITouchClassInfo* touch_info = |
| 64 reinterpret_cast<XITouchClassInfo*>(class_info); | 107 reinterpret_cast<XITouchClassInfo*>(class_info); |
| 65 is_direct_touch = touch_info->mode == XIDirectTouch; | 108 is_direct_touch = touch_info->mode == XIDirectTouch; |
| 66 } | 109 } |
| 67 #endif | 110 #endif |
| 68 } | 111 } |
| 69 | 112 |
| 70 // Touchscreens should have absolute X and Y axes, and be direct touch | 113 // Touchscreens should have absolute X and Y axes, and be direct touch |
| 71 // devices. | 114 // devices. |
| 72 if (width > 0.0 && height > 0.0 && is_direct_touch) { | 115 if (width > 0.0 && height > 0.0 && is_direct_touch) { |
| 116 bool is_internal = IsTouchscreenInternal(display_, info[i].deviceid); | |
| 73 devices.push_back(TouchscreenDevice(info[i].deviceid, | 117 devices.push_back(TouchscreenDevice(info[i].deviceid, |
| 74 gfx::Size(width, height))); | 118 gfx::Size(width, height), |
| 119 is_internal)); | |
| 75 } | 120 } |
| 76 } | 121 } |
| 77 | 122 |
| 78 XIFreeDeviceInfo(info); | 123 XIFreeDeviceInfo(info); |
| 79 return devices; | 124 return devices; |
| 80 } | 125 } |
| 81 | 126 |
| 82 } // namespace ui | 127 } // namespace ui |
| OLD | NEW |