| OLD | NEW |
| 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 "chrome/browser/chromeos/events/event_rewriter.h" | 5 #include "chrome/browser/chromeos/events/event_rewriter.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/sticky_keys/sticky_keys_controller.h" | 9 #include "ash/sticky_keys/sticky_keys_controller.h" |
| 10 #include "ash/wm/window_state.h" | 10 #include "ash/wm/window_state.h" |
| 11 #include "ash/wm/window_util.h" | 11 #include "ash/wm/window_util.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
| 18 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 18 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| 19 #include "chrome/browser/extensions/extension_commands_global_registry.h" | 19 #include "chrome/browser/extensions/extension_commands_global_registry.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 22 #include "chromeos/chromeos_switches.h" | 22 #include "chromeos/chromeos_switches.h" |
| 23 #include "components/user_manager/user_manager.h" | 23 #include "components/user_manager/user_manager.h" |
| 24 #include "ui/base/ime/chromeos/ime_keyboard.h" | 24 #include "ui/base/ime/chromeos/ime_keyboard.h" |
| 25 #include "ui/base/ime/chromeos/input_method_manager.h" | 25 #include "ui/base/ime/chromeos/input_method_manager.h" |
| 26 #include "ui/events/devices/device_data_manager.h" |
| 26 #include "ui/events/event.h" | 27 #include "ui/events/event.h" |
| 27 #include "ui/events/event_utils.h" | 28 #include "ui/events/event_utils.h" |
| 28 #include "ui/events/keycodes/keyboard_code_conversion.h" | 29 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 29 #include "ui/wm/core/window_util.h" | 30 #include "ui/wm/core/window_util.h" |
| 30 | 31 |
| 31 #if defined(USE_X11) | 32 #if defined(USE_X11) |
| 32 #include <X11/extensions/XInput2.h> | |
| 33 #include <X11/Xatom.h> | |
| 34 #include <X11/Xlib.h> | 33 #include <X11/Xlib.h> |
| 35 | 34 |
| 36 #ifndef XI_PROP_PRODUCT_ID | |
| 37 #define XI_PROP_PRODUCT_ID "Device Product ID" | |
| 38 #endif | |
| 39 | |
| 40 // Get rid of macros from Xlib.h that conflicts with other parts of the code. | 35 // Get rid of macros from Xlib.h that conflicts with other parts of the code. |
| 41 #undef RootWindow | 36 #undef RootWindow |
| 42 #undef Status | 37 #undef Status |
| 43 | |
| 44 #include "ui/base/x/x11_util.h" | |
| 45 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | |
| 46 #endif | 38 #endif |
| 47 | 39 |
| 48 namespace chromeos { | 40 namespace chromeos { |
| 49 | 41 |
| 50 namespace { | 42 namespace { |
| 51 | 43 |
| 52 // Hotrod controller vendor/product ids. | 44 // Hotrod controller vendor/product ids. |
| 53 const int kHotrodRemoteVendorId = 0x0471; | 45 const int kHotrodRemoteVendorId = 0x0471; |
| 54 const int kHotrodRemoteProductId = 0x21cc; | 46 const int kHotrodRemoteProductId = 0x21cc; |
| 55 const int kUnknownVendorId = -1; | 47 const int kUnknownVendorId = -1; |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 VLOG(1) << "Unknown keyboard '" << device_name << "' connected: " | 875 VLOG(1) << "Unknown keyboard '" << device_name << "' connected: " |
| 884 << "id=" << device_id; | 876 << "id=" << device_id; |
| 885 } | 877 } |
| 886 // Always overwrite the existing device_id since the X server may reuse a | 878 // Always overwrite the existing device_id since the X server may reuse a |
| 887 // device id for an unattached device. | 879 // device id for an unattached device. |
| 888 device_id_to_type_[device_id] = type; | 880 device_id_to_type_[device_id] = type; |
| 889 return type; | 881 return type; |
| 890 } | 882 } |
| 891 | 883 |
| 892 EventRewriter::DeviceType EventRewriter::KeyboardDeviceAdded(int device_id) { | 884 EventRewriter::DeviceType EventRewriter::KeyboardDeviceAdded(int device_id) { |
| 893 #if defined(USE_X11) | 885 if (!ui::DeviceDataManager::HasInstance()) |
| 894 DCHECK_NE(XIAllDevices, device_id); | |
| 895 DCHECK_NE(XIAllMasterDevices, device_id); | |
| 896 if (device_id == XIAllDevices || device_id == XIAllMasterDevices) { | |
| 897 LOG(ERROR) << "Unexpected device_id passed: " << device_id; | |
| 898 return kDeviceUnknown; | 886 return kDeviceUnknown; |
| 887 const std::vector<ui::KeyboardDevice>& keyboards = |
| 888 ui::DeviceDataManager::GetInstance()->keyboard_devices(); |
| 889 for (const auto& keyboard : keyboards) { |
| 890 if (keyboard.id == device_id) { |
| 891 return KeyboardDeviceAddedInternal( |
| 892 keyboard.id, keyboard.name, keyboard.vendor_id, keyboard.product_id); |
| 893 } |
| 899 } | 894 } |
| 900 | 895 return kDeviceUnknown; |
| 901 Atom product_id_atom = | |
| 902 XInternAtom(gfx::GetXDisplay(), XI_PROP_PRODUCT_ID, 1); | |
| 903 | |
| 904 int ndevices_return = 0; | |
| 905 XIDeviceInfo* device_info = | |
| 906 XIQueryDevice(gfx::GetXDisplay(), device_id, &ndevices_return); | |
| 907 | |
| 908 // Since |device_id| is neither XIAllDevices nor XIAllMasterDevices, | |
| 909 // the number of devices found should be either 0 (not found) or 1. | |
| 910 if (!device_info) { | |
| 911 LOG(ERROR) << "XIQueryDevice: Device ID " << device_id << " is unknown."; | |
| 912 return kDeviceUnknown; | |
| 913 } | |
| 914 | |
| 915 DeviceType dev_type = kDeviceUnknown; | |
| 916 DCHECK_EQ(1, ndevices_return); | |
| 917 for (int i = 0; i < ndevices_return; ++i) { | |
| 918 // Get keyboard product and vendor id. | |
| 919 int vendor_id = kUnknownVendorId; | |
| 920 int product_id = kUnknownProductId; | |
| 921 uint32* product_info = NULL; | |
| 922 Atom type; | |
| 923 int format_return; | |
| 924 unsigned long num_items_return; | |
| 925 unsigned long bytes_after_return; | |
| 926 if (XIGetProperty(gfx::GetXDisplay(), | |
| 927 device_info[i].deviceid, | |
| 928 product_id_atom, | |
| 929 0, | |
| 930 2, | |
| 931 0, | |
| 932 XA_INTEGER, | |
| 933 &type, | |
| 934 &format_return, | |
| 935 &num_items_return, | |
| 936 &bytes_after_return, | |
| 937 reinterpret_cast<unsigned char **>(&product_info)) == 0 && | |
| 938 product_info) { | |
| 939 vendor_id = product_info[0]; | |
| 940 product_id = product_info[1]; | |
| 941 } | |
| 942 | |
| 943 DCHECK_EQ(device_id, device_info[i].deviceid); // see the comment above. | |
| 944 DCHECK(device_info[i].name); | |
| 945 dev_type = KeyboardDeviceAddedInternal(device_info[i].deviceid, | |
| 946 device_info[i].name, | |
| 947 vendor_id, | |
| 948 product_id); | |
| 949 } | |
| 950 XIFreeDeviceInfo(device_info); | |
| 951 return dev_type; | |
| 952 #else | |
| 953 // TODO(spang): Figure out where we can get keyboard vendor/product id from in | |
| 954 // Ozone/Freon version. | |
| 955 return KeyboardDeviceAddedInternal(device_id, | |
| 956 "keyboard", | |
| 957 kUnknownVendorId, | |
| 958 kUnknownProductId); | |
| 959 #endif | |
| 960 } | 896 } |
| 961 | 897 |
| 962 } // namespace chromeos | 898 } // namespace chromeos |
| OLD | NEW |