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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/devices/device_util_linux.cc
diff --git a/ui/events/devices/device_util_linux.cc b/ui/events/devices/device_util_linux.cc
index ec1b4eca3bcef69ee130ee505b10753a18aabb4c..90fad3d96cb651f4ef51a7f023fae5beab9676a2 100644
--- a/ui/events/devices/device_util_linux.cc
+++ b/ui/events/devices/device_util_linux.cc
@@ -14,12 +14,11 @@
namespace ui {
-// We consider the touchscreen to be internal if it is an I2c device.
-bool IsTouchscreenInternal(const base::FilePath& path) {
+InputDeviceType GetInputDeviceTypeFromPath(const base::FilePath& path) {
DCHECK(!base::MessageLoopForUI::IsCurrent());
std::string event_node = path.BaseName().value();
if (event_node.empty() || !StartsWithASCII(event_node, "event", false))
- return false;
+ return InputDeviceType::INPUT_DEVICE_UNKNOWN;
// Find sysfs device path for this device.
base::FilePath sysfs_path =
@@ -29,19 +28,37 @@ bool IsTouchscreenInternal(const base::FilePath& path) {
// Device does not exist.
if (sysfs_path.empty())
- return false;
+ return InputDeviceType::INPUT_DEVICE_UNKNOWN;
- // Check all parent devices. If any of them is the "i2c" subsystem,
- // consider the device internal. Otherwise consider it external.
- const base::FilePath i2c_subsystem(FILE_PATH_LITERAL("/sys/bus/i2c"));
+ // Check ancestor devices for a known bus attachment.
for (base::FilePath path = sysfs_path; path != base::FilePath("/");
path = path.DirName()) {
- if (base::MakeAbsoluteFilePath(
- path.Append(FILE_PATH_LITERAL("subsystem"))) == i2c_subsystem)
- return true;
+ std::string subsystem_path =
+ base::MakeAbsoluteFilePath(path.Append(FILE_PATH_LITERAL("subsystem")))
+ .value();
+ if (subsystem_path.empty())
+ continue;
+
+ // Internal bus attachments.
+ if (subsystem_path == "/sys/bus/pci")
+ return InputDeviceType::INPUT_DEVICE_INTERNAL;
+ if (subsystem_path == "/sys/bus/i2c")
+ return InputDeviceType::INPUT_DEVICE_INTERNAL;
+ if (subsystem_path == "/sys/bus/acpi")
+ return InputDeviceType::INPUT_DEVICE_INTERNAL;
+ if (subsystem_path == "/sys/bus/serio")
+ return InputDeviceType::INPUT_DEVICE_INTERNAL;
+ if (subsystem_path == "/sys/bus/platform")
+ return InputDeviceType::INPUT_DEVICE_INTERNAL;
+
+ // External bus attachments.
+ if (subsystem_path == "/sys/bus/usb")
+ return InputDeviceType::INPUT_DEVICE_EXTERNAL;
+ if (subsystem_path == "/sys/class/bluetooth")
+ return InputDeviceType::INPUT_DEVICE_EXTERNAL;
}
- return false;
+ return InputDeviceType::INPUT_DEVICE_UNKNOWN;
}
} // namespace
« 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