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

Side by Side Diff: ui/display/chromeos/x11/touchscreen_device_manager_x11.cc

Issue 394063004: Associate internal touchscreen to internal display (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove using external script is_touchscreen_internal Created 6 years, 5 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 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 #include <string>
13 #include <vector>
12 14
15 #include "base/command_line.h"
16 #include "base/files/file_enumerator.h"
17 #include "base/logging.h"
18 #include "base/process/launch.h"
19 #include "base/strings/string_util.h"
20 #include "base/sys_info.h"
13 #include "ui/gfx/x/x11_types.h" 21 #include "ui/gfx/x/x11_types.h"
14 22
23 namespace {
24
25 // We consider the touchscreen is internal if it is an I2c device.
Daniel Erat 2014/07/16 20:31:24 nit: s/touchscreen is internal/touchscreen to be i
Yufeng Shen (Slow to review) 2014/07/16 20:42:24 Done.
26 // With the device id, we can query X to get the device's dev input
27 // node eventXXX. Then we search all the dev input nodes registered
28 // by I2C devices to see if we can find eventXXX.
29 bool IsTouchscreenInternal(Display* dpy, int device_id) {
Daniel Erat 2014/07/16 20:31:23 nit: s/Display/XDisplay/ to match x11_types.h
Yufeng Shen (Slow to review) 2014/07/16 20:42:23 Done.
30 using base::FileEnumerator;
31 using base::FilePath;
32
33 if (!base::SysInfo::IsRunningOnChromeOS())
34 return false;
35
36 // Input device has a property "Device Node" pointing to its dev input node,
37 // e.g. Device Node (250): "/dev/input/event8"
38 Atom device_node = XInternAtom(dpy, "Device Node", False);
39 if (device_node == None)
40 return false;
41
42 Atom act_type;
Daniel Erat 2014/07/16 20:31:24 avoid abbreviations: rename this to |actual_type|
Yufeng Shen (Slow to review) 2014/07/16 20:42:24 Done.
43 int act_format;
44 unsigned long nitems, bytes_after;
45 unsigned char* data;
46 XDevice* dev = XOpenDevice(dpy, device_id);
47 if (!dev)
48 return false;
49
50 if (XGetDeviceProperty(dpy, dev, device_node, 0, 1000, False,
51 AnyPropertyType, &act_type, &act_format,
52 &nitems, &bytes_after, &data) != Success)
53 return false;
Daniel Erat 2014/07/16 20:31:23 do you need to call XCloseDevice() before returnin
Yufeng Shen (Slow to review) 2014/07/16 20:42:24 Done.
54 base::FilePath dev_node_path(reinterpret_cast<char*>(data));
55 XFree(data);
56 XCloseDevice(dpy, dev);
57
58 std::string event_node = dev_node_path.BaseName().value();
59 if (event_node.empty() ||
60 !StartsWithASCII(event_node, "event", false)) {
61 return false;
62 }
63
64 // Extract id "XXX" from "eventXXX"
65 std::string event_node_id = event_node.substr(5);
66
67 // I2C input device registers its dev input node at
68 // /sys/bus/i2c/devices/*/input/inputXXX/eventXXX
69 FileEnumerator i2c_enum(FilePath(FILE_PATH_LITERAL("/sys/bus/i2c/devices/")),
70 false,
71 base::FileEnumerator::DIRECTORIES);
72 for (FilePath i2c_name = i2c_enum.Next();
73 !i2c_name.empty();
74 i2c_name = i2c_enum.Next()) {
75 FileEnumerator input_enum(i2c_name.Append(FILE_PATH_LITERAL("input")),
76 false,
77 base::FileEnumerator::DIRECTORIES,
78 FILE_PATH_LITERAL("input*"));
79 for (base::FilePath input = input_enum.Next();
80 !input.empty();
81 input = input_enum.Next()) {
82 if (input.BaseName().value().substr(5) == event_node_id)
83 return true;
84 }
85 }
86
87 return false;
88 }
89
90 }
Daniel Erat 2014/07/16 20:31:24 nit: } // namespace
Yufeng Shen (Slow to review) 2014/07/16 20:42:24 Done.
91
15 namespace ui { 92 namespace ui {
16 93
17 TouchscreenDeviceManagerX11::TouchscreenDeviceManagerX11() 94 TouchscreenDeviceManagerX11::TouchscreenDeviceManagerX11()
18 : display_(gfx::GetXDisplay()) {} 95 : display_(gfx::GetXDisplay()) {}
19 96
20 TouchscreenDeviceManagerX11::~TouchscreenDeviceManagerX11() {} 97 TouchscreenDeviceManagerX11::~TouchscreenDeviceManagerX11() {}
21 98
22 std::vector<TouchscreenDevice> TouchscreenDeviceManagerX11::GetDevices() { 99 std::vector<TouchscreenDevice> TouchscreenDeviceManagerX11::GetDevices() {
23 std::vector<TouchscreenDevice> devices; 100 std::vector<TouchscreenDevice> devices;
24 int num_devices = 0; 101 int num_devices = 0;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 XITouchClassInfo* touch_info = 140 XITouchClassInfo* touch_info =
64 reinterpret_cast<XITouchClassInfo*>(class_info); 141 reinterpret_cast<XITouchClassInfo*>(class_info);
65 is_direct_touch = touch_info->mode == XIDirectTouch; 142 is_direct_touch = touch_info->mode == XIDirectTouch;
66 } 143 }
67 #endif 144 #endif
68 } 145 }
69 146
70 // Touchscreens should have absolute X and Y axes, and be direct touch 147 // Touchscreens should have absolute X and Y axes, and be direct touch
71 // devices. 148 // devices.
72 if (width > 0.0 && height > 0.0 && is_direct_touch) { 149 if (width > 0.0 && height > 0.0 && is_direct_touch) {
150 bool is_internal = IsTouchscreenInternal(display_, info[i].deviceid);
73 devices.push_back(TouchscreenDevice(info[i].deviceid, 151 devices.push_back(TouchscreenDevice(info[i].deviceid,
74 gfx::Size(width, height))); 152 gfx::Size(width, height),
153 is_internal));
75 } 154 }
76 } 155 }
77 156
78 XIFreeDeviceInfo(info); 157 XIFreeDeviceInfo(info);
79 return devices; 158 return devices;
80 } 159 }
81 160
82 } // namespace ui 161 } // namespace ui
OLDNEW
« no previous file with comments | « ui/display/chromeos/touchscreen_delegate_impl_unittest.cc ('k') | ui/display/types/chromeos/touchscreen_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698