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..88230af76bcf06ae68af9dbecddd2c74ce7b8b12 100644 |
--- a/ui/events/x/hotplug_event_handler_x11.cc |
+++ b/ui/events/x/hotplug_event_handler_x11.cc |
@@ -19,6 +19,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 +27,19 @@ namespace ui { |
namespace { |
+// The name of the xinput device corresponding to the internal keyboard. |
+const char kInternalKeyboardName[] = "AT Translated Set 2 keyboard"; |
+ |
+// The name of the xinput device corresponding to the test keyboard. |
+const char kTestKeyboardName[] = "Virtual core XTEST keyboard"; |
+ |
+// Filters out devices like the power button which are also SlaveKeyboards but |
+// not true keyboards. |
+bool IsKeyboard(std::string name) { |
dnicoara
2014/10/02 13:58:20
Not sure if this would cover all keyboard devices.
rsadam
2014/10/02 14:59:31
Added an UNKNOWN Enum, and marked these devices as
flackr
2014/10/02 15:41:10
Agreed. I think false negatives are okay for how w
|
+ 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,31 @@ 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); |
+ if (!IsKeyboard(device_name)) |
+ continue; |
+ KeyboardDeviceType type = KeyboardDeviceType::EXTERNAL; |
+ if (device_name == kInternalKeyboardName) { |
+ type = KeyboardDeviceType::INTERNAL; |
+ } else if (device_name == kTestKeyboardName) { |
dnicoara
2014/10/02 13:58:20
Is there anything special about test devices?
rsadam
2014/10/02 14:59:31
Each Master device has a XTEST device associated t
flackr
2014/10/02 15:41:10
This device shouldn't be considered a user accessi
|
+ type = KeyboardDeviceType::TEST; |
+ } |
+ devices.push_back(KeyboardDevice(x11_devices[i].deviceid, type)); |
+ } |
+ delegate_->OnKeyboardDevicesUpdated(devices); |
} |
void HotplugEventHandlerX11::HandleTouchscreenDevices( |