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

Unified Diff: ui/events/x/hotplug_event_handler_x11.cc

Issue 618283003: Adds special support to the device manager for keyboards devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« ui/events/keyboard_device.h ('K') | « ui/events/x/hotplug_event_handler_x11.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/x/hotplug_event_handler_x11.cc
diff --git a/ui/events/x/hotplug_event_handler_x11.cc b/ui/events/x/hotplug_event_handler_x11.cc
index 16f42f7dbe15ba8e329a5953558a62dd0edde838..84b49a6a044f17c0f233bb108a631def6469756f 100644
--- a/ui/events/x/hotplug_event_handler_x11.cc
+++ b/ui/events/x/hotplug_event_handler_x11.cc
@@ -7,6 +7,7 @@
#include <X11/extensions/XInput.h>
#include <X11/extensions/XInput2.h>
+#include <algorithm>
#include <cmath>
#include <set>
#include <string>
@@ -19,6 +20,7 @@
#include "base/strings/string_util.h"
#include "base/sys_info.h"
#include "ui/events/device_hotplug_event_observer.h"
+#include "ui/events/keyboard_device.h"
#include "ui/events/touchscreen_device.h"
#include "ui/gfx/x/x11_types.h"
@@ -26,6 +28,18 @@ namespace ui {
namespace {
+// The name of the xinput device corresponding to the internal keyboard.
+const char kInternalKeyboardName[] = "AT Translated Set 2 keyboard";
sadrul 2014/10/02 15:53:53 Is this only on chromeos? (i.e. does x11/linux dev
rsadam 2014/10/02 22:52:27 I believe this is Unix wide. (http://unix.stackexc
+
+// The name of the xinput device corresponding to the test keyboard.
+const char kTestKeyboardName[] = "Virtual core XTEST keyboard";
+
+// Filters our all devices that do not contain the substring "keyboard".
+bool IsKnownKeyboard(std::string name) {
sadrul 2014/10/02 15:53:53 const &, and make an internal copy if you need to
rsadam 2014/10/02 22:52:27 Done.
+ std::transform(name.begin(), name.end(), name.begin(), ::tolower);
+ return name.find("keyboard") != std::string::npos;
+}
+
// We consider the touchscreen to be internal if it is an I2c device.
// With the device id, we can query X to get the device's dev input
// node eventXXX. Then we search all the dev input nodes registered
@@ -116,6 +130,33 @@ void HotplugEventHandlerX11::OnHotplugEvent() {
const XIDeviceList& device_list =
DeviceListCacheX::GetInstance()->GetXI2DeviceList(gfx::GetXDisplay());
HandleTouchscreenDevices(device_list);
+ HandleKeyboardDevices(device_list);
+ delegate_->OnInputDeviceConfigurationChanged();
+}
+
+void HotplugEventHandlerX11::HandleKeyboardDevices(
+ const XIDeviceList& x11_devices) {
+ std::vector<KeyboardDevice> devices;
+
+ for (int i = 0; i < x11_devices.count; i++) {
+ if (!x11_devices[i].enabled || x11_devices[i].use != XISlaveKeyboard)
+ continue; // Assume all keyboards are keyboard slaves
+ std::string device_name(x11_devices[i].name);
+ base::TrimWhitespaceASCII(device_name, base::TRIM_TRAILING,
+ &device_name);
+ KeyboardDeviceType type;
+ if (device_name == kInternalKeyboardName) {
+ type = KeyboardDeviceType::INTERNAL;
+ } else if (device_name == kTestKeyboardName) {
+ type = KeyboardDeviceType::TEST;
+ } else if (IsKnownKeyboard(device_name)) {
+ type = KeyboardDeviceType::EXTERNAL;
+ } else {
+ type = KeyboardDeviceType::UNKNOWN;
+ }
+ devices.push_back(KeyboardDevice(x11_devices[i].deviceid, type));
+ }
+ delegate_->OnKeyboardDevicesUpdated(devices);
}
void HotplugEventHandlerX11::HandleTouchscreenDevices(
« ui/events/keyboard_device.h ('K') | « ui/events/x/hotplug_event_handler_x11.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698