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 "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.h" | 5 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 namespace ash { | 29 namespace ash { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 // The name of the xinput device corresponding to the internal touchpad. | 33 // The name of the xinput device corresponding to the internal touchpad. |
34 const char kInternalTouchpadName[] = "Elan Touchpad"; | 34 const char kInternalTouchpadName[] = "Elan Touchpad"; |
35 | 35 |
36 // The name of the xinput device corresponding to the internal keyboard. | 36 // The name of the xinput device corresponding to the internal keyboard. |
37 const char kInternalKeyboardName[] = "AT Translated Set 2 keyboard"; | 37 const char kInternalKeyboardName[] = "AT Translated Set 2 keyboard"; |
38 | 38 |
| 39 // Repeated key events have their source set to the core keyboard device. |
| 40 // These must be disabled also until http://crbug.com/402898 is resolved. |
| 41 const char kCoreKeyboardName[] = "Virtual core keyboard"; |
| 42 |
39 // Device id used to indicate that a device has not been detected. | 43 // Device id used to indicate that a device has not been detected. |
40 const int kDeviceIdNone = -1; | 44 const int kDeviceIdNone = -1; |
41 | 45 |
42 gfx::Point GetMouseLocationInScreen() { | 46 gfx::Point GetMouseLocationInScreen() { |
43 return aura::Env::GetInstance()->last_mouse_location(); | 47 return aura::Env::GetInstance()->last_mouse_location(); |
44 } | 48 } |
45 | 49 |
46 void SetMouseLocationInScreen(const gfx::Point& screen_location) { | 50 void SetMouseLocationInScreen(const gfx::Point& screen_location) { |
47 gfx::Display display = ash::ScreenUtil::FindDisplayContainingPoint( | 51 gfx::Display display = ash::ScreenUtil::FindDisplayContainingPoint( |
48 screen_location); | 52 screen_location); |
49 if (!display.is_valid()) | 53 if (!display.is_valid()) |
50 return; | 54 return; |
51 aura::Window* root_window = Shell::GetInstance()->display_controller()-> | 55 aura::Window* root_window = Shell::GetInstance()->display_controller()-> |
52 GetRootWindowForDisplayId(display.id()); | 56 GetRootWindowForDisplayId(display.id()); |
53 gfx::Point host_location(screen_location); | 57 gfx::Point host_location(screen_location); |
54 aura::client::ScreenPositionClient* client = | 58 aura::client::ScreenPositionClient* client = |
55 aura::client::GetScreenPositionClient(root_window); | 59 aura::client::GetScreenPositionClient(root_window); |
56 if (client) | 60 if (client) |
57 client->ConvertPointFromScreen(root_window, &host_location); | 61 client->ConvertPointFromScreen(root_window, &host_location); |
58 root_window->GetHost()->MoveCursorTo(host_location); | 62 root_window->GetHost()->MoveCursorTo(host_location); |
59 } | 63 } |
60 | 64 |
61 } // namespace | 65 } // namespace |
62 | 66 |
63 ScopedDisableInternalMouseAndKeyboardX11:: | 67 ScopedDisableInternalMouseAndKeyboardX11:: |
64 ScopedDisableInternalMouseAndKeyboardX11() | 68 ScopedDisableInternalMouseAndKeyboardX11() |
65 : touchpad_device_id_(kDeviceIdNone), | 69 : touchpad_device_id_(kDeviceIdNone), |
66 keyboard_device_id_(kDeviceIdNone), | 70 keyboard_device_id_(kDeviceIdNone), |
| 71 core_keyboard_device_id_(kDeviceIdNone), |
67 last_mouse_location_(GetMouseLocationInScreen()) { | 72 last_mouse_location_(GetMouseLocationInScreen()) { |
68 | 73 |
69 ui::DeviceDataManagerX11* device_data_manager = | 74 ui::DeviceDataManagerX11* device_data_manager = |
70 static_cast<ui::DeviceDataManagerX11*>( | 75 static_cast<ui::DeviceDataManagerX11*>( |
71 ui::DeviceDataManager::GetInstance()); | 76 ui::DeviceDataManager::GetInstance()); |
72 if (device_data_manager->IsXInput2Available()) { | 77 if (device_data_manager->IsXInput2Available()) { |
73 XIDeviceList xi_dev_list = ui::DeviceListCacheX::GetInstance()-> | 78 XIDeviceList xi_dev_list = ui::DeviceListCacheX::GetInstance()-> |
74 GetXI2DeviceList(gfx::GetXDisplay()); | 79 GetXI2DeviceList(gfx::GetXDisplay()); |
75 for (int i = 0; i < xi_dev_list.count; ++i) { | 80 for (int i = 0; i < xi_dev_list.count; ++i) { |
76 std::string device_name(xi_dev_list[i].name); | 81 std::string device_name(xi_dev_list[i].name); |
77 base::TrimWhitespaceASCII(device_name, base::TRIM_TRAILING, &device_name); | 82 base::TrimWhitespaceASCII(device_name, base::TRIM_TRAILING, &device_name); |
78 if (device_name == kInternalTouchpadName) { | 83 if (device_name == kInternalTouchpadName) { |
79 touchpad_device_id_ = xi_dev_list[i].deviceid; | 84 touchpad_device_id_ = xi_dev_list[i].deviceid; |
80 device_data_manager->DisableDevice(touchpad_device_id_); | 85 device_data_manager->DisableDevice(touchpad_device_id_); |
81 } else if (device_name == kInternalKeyboardName) { | 86 } else if (device_name == kInternalKeyboardName) { |
82 keyboard_device_id_ = xi_dev_list[i].deviceid; | 87 keyboard_device_id_ = xi_dev_list[i].deviceid; |
83 device_data_manager->DisableDevice(keyboard_device_id_); | 88 device_data_manager->DisableDevice(keyboard_device_id_); |
| 89 } else if (device_name == kCoreKeyboardName) { |
| 90 core_keyboard_device_id_ = xi_dev_list[i].deviceid; |
| 91 device_data_manager->DisableDevice(core_keyboard_device_id_); |
84 } | 92 } |
85 } | 93 } |
86 } | 94 } |
87 // Allow the accessible keys present on the side of some devices to continue | 95 // Allow the accessible keys present on the side of some devices to continue |
88 // working. | 96 // working. |
89 scoped_ptr<std::set<ui::KeyboardCode> > excepted_keys( | 97 scoped_ptr<std::set<ui::KeyboardCode> > excepted_keys( |
90 new std::set<ui::KeyboardCode>); | 98 new std::set<ui::KeyboardCode>); |
91 excepted_keys->insert(ui::VKEY_VOLUME_DOWN); | 99 excepted_keys->insert(ui::VKEY_VOLUME_DOWN); |
92 excepted_keys->insert(ui::VKEY_VOLUME_UP); | 100 excepted_keys->insert(ui::VKEY_VOLUME_UP); |
93 excepted_keys->insert(ui::VKEY_POWER); | 101 excepted_keys->insert(ui::VKEY_POWER); |
94 device_data_manager->SetDisabledKeyboardAllowedKeys(excepted_keys.Pass()); | 102 device_data_manager->SetDisabledKeyboardAllowedKeys(excepted_keys.Pass()); |
95 ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); | 103 ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); |
96 } | 104 } |
97 | 105 |
98 ScopedDisableInternalMouseAndKeyboardX11:: | 106 ScopedDisableInternalMouseAndKeyboardX11:: |
99 ~ScopedDisableInternalMouseAndKeyboardX11() { | 107 ~ScopedDisableInternalMouseAndKeyboardX11() { |
100 ui::DeviceDataManagerX11* device_data_manager = | 108 ui::DeviceDataManagerX11* device_data_manager = |
101 static_cast<ui::DeviceDataManagerX11*>( | 109 static_cast<ui::DeviceDataManagerX11*>( |
102 ui::DeviceDataManager::GetInstance()); | 110 ui::DeviceDataManager::GetInstance()); |
103 if (touchpad_device_id_ != kDeviceIdNone) | 111 if (touchpad_device_id_ != kDeviceIdNone) |
104 device_data_manager->EnableDevice(touchpad_device_id_); | 112 device_data_manager->EnableDevice(touchpad_device_id_); |
105 if (keyboard_device_id_ != kDeviceIdNone) | 113 if (keyboard_device_id_ != kDeviceIdNone) |
106 device_data_manager->EnableDevice(keyboard_device_id_); | 114 device_data_manager->EnableDevice(keyboard_device_id_); |
| 115 if (core_keyboard_device_id_ != kDeviceIdNone) |
| 116 device_data_manager->EnableDevice(core_keyboard_device_id_); |
107 device_data_manager->SetDisabledKeyboardAllowedKeys( | 117 device_data_manager->SetDisabledKeyboardAllowedKeys( |
108 scoped_ptr<std::set<ui::KeyboardCode> >()); | 118 scoped_ptr<std::set<ui::KeyboardCode> >()); |
109 ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); | 119 ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); |
110 } | 120 } |
111 | 121 |
112 void ScopedDisableInternalMouseAndKeyboardX11::WillProcessEvent( | 122 void ScopedDisableInternalMouseAndKeyboardX11::WillProcessEvent( |
113 const ui::PlatformEvent& event) { | 123 const ui::PlatformEvent& event) { |
114 } | 124 } |
115 | 125 |
116 void ScopedDisableInternalMouseAndKeyboardX11::DidProcessEvent( | 126 void ScopedDisableInternalMouseAndKeyboardX11::DidProcessEvent( |
(...skipping 16 matching lines...) Expand all Loading... |
133 // blocked. Move the mouse cursor back to its last known location resulting | 143 // blocked. Move the mouse cursor back to its last known location resulting |
134 // from an external mouse to prevent the internal touchpad from moving it. | 144 // from an external mouse to prevent the internal touchpad from moving it. |
135 SetMouseLocationInScreen(last_mouse_location_); | 145 SetMouseLocationInScreen(last_mouse_location_); |
136 } else { | 146 } else { |
137 // Track the last location seen from an external mouse event. | 147 // Track the last location seen from an external mouse event. |
138 last_mouse_location_ = GetMouseLocationInScreen(); | 148 last_mouse_location_ = GetMouseLocationInScreen(); |
139 } | 149 } |
140 } | 150 } |
141 | 151 |
142 } // namespace ash | 152 } // namespace ash |
OLD | NEW |