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

Side by Side Diff: ui/events/devices/device_util_linux.cc

Issue 791743004: events: Generalize IsTouchscreenInternal to any device type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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/devices/device_util_linux.h" 5 #include "ui/events/devices/device_util_linux.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 14
15 namespace ui { 15 namespace ui {
16 16
17 // We consider the touchscreen to be internal if it is an I2c device. 17 InputDeviceType GetInputDeviceTypeFromPath(const base::FilePath& path) {
18 bool IsTouchscreenInternal(const base::FilePath& path) {
19 DCHECK(!base::MessageLoopForUI::IsCurrent()); 18 DCHECK(!base::MessageLoopForUI::IsCurrent());
20 std::string event_node = path.BaseName().value(); 19 std::string event_node = path.BaseName().value();
21 if (event_node.empty() || !StartsWithASCII(event_node, "event", false)) 20 if (event_node.empty() || !StartsWithASCII(event_node, "event", false))
22 return false; 21 return InputDeviceType::INPUT_DEVICE_UNKNOWN;
23 22
24 // Find sysfs device path for this device. 23 // Find sysfs device path for this device.
25 base::FilePath sysfs_path = 24 base::FilePath sysfs_path =
26 base::FilePath(FILE_PATH_LITERAL("/sys/class/input")); 25 base::FilePath(FILE_PATH_LITERAL("/sys/class/input"));
27 sysfs_path = sysfs_path.Append(path.BaseName()); 26 sysfs_path = sysfs_path.Append(path.BaseName());
28 sysfs_path = base::MakeAbsoluteFilePath(sysfs_path); 27 sysfs_path = base::MakeAbsoluteFilePath(sysfs_path);
29 28
30 // Device does not exist. 29 // Device does not exist.
31 if (sysfs_path.empty()) 30 if (sysfs_path.empty())
32 return false; 31 return InputDeviceType::INPUT_DEVICE_UNKNOWN;
33 32
34 // Check all parent devices. If any of them is the "i2c" subsystem, 33 // Check ancestor devices for a known bus attachment.
35 // consider the device internal. Otherwise consider it external.
36 const base::FilePath i2c_subsystem(FILE_PATH_LITERAL("/sys/bus/i2c"));
37 for (base::FilePath path = sysfs_path; path != base::FilePath("/"); 34 for (base::FilePath path = sysfs_path; path != base::FilePath("/");
38 path = path.DirName()) { 35 path = path.DirName()) {
39 if (base::MakeAbsoluteFilePath( 36 std::string subsystem_path =
40 path.Append(FILE_PATH_LITERAL("subsystem"))) == i2c_subsystem) 37 base::MakeAbsoluteFilePath(path.Append(FILE_PATH_LITERAL("subsystem")))
41 return true; 38 .value();
39 if (subsystem_path.empty())
40 continue;
41
42 // Internal bus attachments.
43 if (subsystem_path == "/sys/bus/pci")
44 return InputDeviceType::INPUT_DEVICE_INTERNAL;
45 if (subsystem_path == "/sys/bus/i2c")
46 return InputDeviceType::INPUT_DEVICE_INTERNAL;
47 if (subsystem_path == "/sys/bus/acpi")
48 return InputDeviceType::INPUT_DEVICE_INTERNAL;
49 if (subsystem_path == "/sys/bus/serio")
50 return InputDeviceType::INPUT_DEVICE_INTERNAL;
51 if (subsystem_path == "/sys/bus/platform")
52 return InputDeviceType::INPUT_DEVICE_INTERNAL;
53
54 // External bus attachments.
55 if (subsystem_path == "/sys/bus/usb")
56 return InputDeviceType::INPUT_DEVICE_EXTERNAL;
57 if (subsystem_path == "/sys/class/bluetooth")
58 return InputDeviceType::INPUT_DEVICE_EXTERNAL;
42 } 59 }
43 60
44 return false; 61 return InputDeviceType::INPUT_DEVICE_UNKNOWN;
45 } 62 }
46 63
47 } // namespace 64 } // namespace
OLDNEW
« no previous file with comments | « ui/events/devices/device_util_linux.h ('k') | ui/events/ozone/evdev/touch_event_converter_evdev.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698