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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } // namespace | 66 } // namespace |
67 | 67 |
68 ScopedDisableInternalMouseAndKeyboardX11:: | 68 ScopedDisableInternalMouseAndKeyboardX11:: |
69 ScopedDisableInternalMouseAndKeyboardX11() | 69 ScopedDisableInternalMouseAndKeyboardX11() |
70 : touchpad_device_id_(kDeviceIdNone), | 70 : touchpad_device_id_(kDeviceIdNone), |
71 keyboard_device_id_(kDeviceIdNone), | 71 keyboard_device_id_(kDeviceIdNone), |
72 core_keyboard_device_id_(kDeviceIdNone), | 72 core_keyboard_device_id_(kDeviceIdNone), |
73 last_mouse_location_(GetMouseLocationInScreen()) { | 73 last_mouse_location_(GetMouseLocationInScreen()) { |
74 | 74 |
75 ui::DeviceDataManagerX11* device_data_manager = | 75 ui::DeviceDataManagerX11* device_data_manager = |
76 static_cast<ui::DeviceDataManagerX11*>( | 76 ui::DeviceDataManagerX11::GetInstance(); |
77 ui::DeviceDataManager::GetInstance()); | |
78 if (device_data_manager->IsXInput2Available()) { | 77 if (device_data_manager->IsXInput2Available()) { |
79 const XIDeviceList& xi_dev_list = | 78 const XIDeviceList& xi_dev_list = |
80 ui::DeviceListCacheX11::GetInstance()->GetXI2DeviceList( | 79 ui::DeviceListCacheX11::GetInstance()->GetXI2DeviceList( |
81 gfx::GetXDisplay()); | 80 gfx::GetXDisplay()); |
82 for (int i = 0; i < xi_dev_list.count; ++i) { | 81 for (int i = 0; i < xi_dev_list.count; ++i) { |
83 std::string device_name(xi_dev_list[i].name); | 82 std::string device_name(xi_dev_list[i].name); |
84 base::TrimWhitespaceASCII(device_name, base::TRIM_TRAILING, &device_name); | 83 base::TrimWhitespaceASCII(device_name, base::TRIM_TRAILING, &device_name); |
85 if (device_name == kInternalTouchpadName) { | 84 if (device_name == kInternalTouchpadName) { |
86 touchpad_device_id_ = xi_dev_list[i].deviceid; | 85 if (device_data_manager->IsDeviceEnabled(xi_dev_list[i].deviceid)) { |
87 device_data_manager->DisableDevice(touchpad_device_id_); | 86 // If the touchpad is already disabled we will do nothing about it. |
88 aura::client::GetCursorClient( | 87 // This will result in doing nothing in the destructor as well since |
89 Shell::GetInstance()->GetPrimaryRootWindow())->HideCursor(); | 88 // |touchpad_device_id_| will remain |kDeviceIdNone|. |
| 89 touchpad_device_id_ = xi_dev_list[i].deviceid; |
| 90 device_data_manager->DisableDevice(touchpad_device_id_); |
| 91 Shell::GetInstance()->cursor_manager()->HideCursor(); |
| 92 } |
90 } else if (device_name == kCoreKeyboardName) { | 93 } else if (device_name == kCoreKeyboardName) { |
91 core_keyboard_device_id_ = xi_dev_list[i].deviceid; | 94 core_keyboard_device_id_ = xi_dev_list[i].deviceid; |
92 device_data_manager->DisableDevice(core_keyboard_device_id_); | 95 device_data_manager->DisableDevice(core_keyboard_device_id_); |
93 } | 96 } |
94 } | 97 } |
95 | 98 |
96 for (const ui::KeyboardDevice& device : | 99 for (const ui::KeyboardDevice& device : |
97 device_data_manager->keyboard_devices()) { | 100 device_data_manager->keyboard_devices()) { |
98 if (device.type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) { | 101 if (device.type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) { |
99 keyboard_device_id_ = device.id; | 102 keyboard_device_id_ = device.id; |
(...skipping 11 matching lines...) Expand all Loading... |
111 excepted_keys->insert(ui::VKEY_POWER); | 114 excepted_keys->insert(ui::VKEY_POWER); |
112 device_data_manager->SetDisabledKeyboardAllowedKeys(excepted_keys.Pass()); | 115 device_data_manager->SetDisabledKeyboardAllowedKeys(excepted_keys.Pass()); |
113 ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); | 116 ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); |
114 } | 117 } |
115 | 118 |
116 ScopedDisableInternalMouseAndKeyboardX11:: | 119 ScopedDisableInternalMouseAndKeyboardX11:: |
117 ~ScopedDisableInternalMouseAndKeyboardX11() { | 120 ~ScopedDisableInternalMouseAndKeyboardX11() { |
118 ui::DeviceDataManagerX11* device_data_manager = | 121 ui::DeviceDataManagerX11* device_data_manager = |
119 static_cast<ui::DeviceDataManagerX11*>( | 122 static_cast<ui::DeviceDataManagerX11*>( |
120 ui::DeviceDataManager::GetInstance()); | 123 ui::DeviceDataManager::GetInstance()); |
121 if (touchpad_device_id_ != kDeviceIdNone) | 124 if (touchpad_device_id_ != kDeviceIdNone) { |
122 device_data_manager->EnableDevice(touchpad_device_id_); | 125 device_data_manager->EnableDevice(touchpad_device_id_); |
| 126 Shell::GetInstance()->cursor_manager()->ShowCursor(); |
| 127 } |
123 if (keyboard_device_id_ != kDeviceIdNone) | 128 if (keyboard_device_id_ != kDeviceIdNone) |
124 device_data_manager->EnableDevice(keyboard_device_id_); | 129 device_data_manager->EnableDevice(keyboard_device_id_); |
125 if (core_keyboard_device_id_ != kDeviceIdNone) | 130 if (core_keyboard_device_id_ != kDeviceIdNone) |
126 device_data_manager->EnableDevice(core_keyboard_device_id_); | 131 device_data_manager->EnableDevice(core_keyboard_device_id_); |
127 device_data_manager->SetDisabledKeyboardAllowedKeys( | 132 device_data_manager->SetDisabledKeyboardAllowedKeys( |
128 scoped_ptr<std::set<ui::KeyboardCode> >()); | 133 scoped_ptr<std::set<ui::KeyboardCode> >()); |
129 ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); | 134 ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); |
130 } | 135 } |
131 | 136 |
132 void ScopedDisableInternalMouseAndKeyboardX11::WillProcessEvent( | 137 void ScopedDisableInternalMouseAndKeyboardX11::WillProcessEvent( |
(...skipping 20 matching lines...) Expand all Loading... |
153 // blocked. Move the mouse cursor back to its last known location resulting | 158 // blocked. Move the mouse cursor back to its last known location resulting |
154 // from an external mouse to prevent the internal touchpad from moving it. | 159 // from an external mouse to prevent the internal touchpad from moving it. |
155 SetMouseLocationInScreen(last_mouse_location_); | 160 SetMouseLocationInScreen(last_mouse_location_); |
156 } else { | 161 } else { |
157 // Track the last location seen from an external mouse event. | 162 // Track the last location seen from an external mouse event. |
158 last_mouse_location_ = GetMouseLocationInScreen(); | 163 last_mouse_location_ = GetMouseLocationInScreen(); |
159 } | 164 } |
160 } | 165 } |
161 | 166 |
162 } // namespace ash | 167 } // namespace ash |
OLD | NEW |