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 aura::client::GetCursorClient( | |
92 Shell::GetInstance()->GetPrimaryRootWindow())->HideCursor(); | |
oshima
2015/10/29 23:38:43
ditto
afakhry
2015/10/30 05:18:03
Done.
| |
93 } | |
90 } else if (device_name == kCoreKeyboardName) { | 94 } else if (device_name == kCoreKeyboardName) { |
91 core_keyboard_device_id_ = xi_dev_list[i].deviceid; | 95 core_keyboard_device_id_ = xi_dev_list[i].deviceid; |
92 device_data_manager->DisableDevice(core_keyboard_device_id_); | 96 device_data_manager->DisableDevice(core_keyboard_device_id_); |
93 } | 97 } |
94 } | 98 } |
95 | 99 |
96 for (const ui::KeyboardDevice& device : | 100 for (const ui::KeyboardDevice& device : |
97 device_data_manager->keyboard_devices()) { | 101 device_data_manager->keyboard_devices()) { |
98 if (device.type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) { | 102 if (device.type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) { |
99 keyboard_device_id_ = device.id; | 103 keyboard_device_id_ = device.id; |
(...skipping 11 matching lines...) Expand all Loading... | |
111 excepted_keys->insert(ui::VKEY_POWER); | 115 excepted_keys->insert(ui::VKEY_POWER); |
112 device_data_manager->SetDisabledKeyboardAllowedKeys(excepted_keys.Pass()); | 116 device_data_manager->SetDisabledKeyboardAllowedKeys(excepted_keys.Pass()); |
113 ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); | 117 ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); |
114 } | 118 } |
115 | 119 |
116 ScopedDisableInternalMouseAndKeyboardX11:: | 120 ScopedDisableInternalMouseAndKeyboardX11:: |
117 ~ScopedDisableInternalMouseAndKeyboardX11() { | 121 ~ScopedDisableInternalMouseAndKeyboardX11() { |
118 ui::DeviceDataManagerX11* device_data_manager = | 122 ui::DeviceDataManagerX11* device_data_manager = |
119 static_cast<ui::DeviceDataManagerX11*>( | 123 static_cast<ui::DeviceDataManagerX11*>( |
120 ui::DeviceDataManager::GetInstance()); | 124 ui::DeviceDataManager::GetInstance()); |
121 if (touchpad_device_id_ != kDeviceIdNone) | 125 if (touchpad_device_id_ != kDeviceIdNone) { |
122 device_data_manager->EnableDevice(touchpad_device_id_); | 126 device_data_manager->EnableDevice(touchpad_device_id_); |
127 aura::client::GetCursorClient( | |
128 Shell::GetInstance()->GetPrimaryRootWindow())->ShowCursor(); | |
129 } | |
123 if (keyboard_device_id_ != kDeviceIdNone) | 130 if (keyboard_device_id_ != kDeviceIdNone) |
124 device_data_manager->EnableDevice(keyboard_device_id_); | 131 device_data_manager->EnableDevice(keyboard_device_id_); |
125 if (core_keyboard_device_id_ != kDeviceIdNone) | 132 if (core_keyboard_device_id_ != kDeviceIdNone) |
126 device_data_manager->EnableDevice(core_keyboard_device_id_); | 133 device_data_manager->EnableDevice(core_keyboard_device_id_); |
127 device_data_manager->SetDisabledKeyboardAllowedKeys( | 134 device_data_manager->SetDisabledKeyboardAllowedKeys( |
128 scoped_ptr<std::set<ui::KeyboardCode> >()); | 135 scoped_ptr<std::set<ui::KeyboardCode> >()); |
129 ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); | 136 ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); |
130 } | 137 } |
131 | 138 |
132 void ScopedDisableInternalMouseAndKeyboardX11::WillProcessEvent( | 139 void ScopedDisableInternalMouseAndKeyboardX11::WillProcessEvent( |
(...skipping 20 matching lines...) Expand all Loading... | |
153 // blocked. Move the mouse cursor back to its last known location resulting | 160 // 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. | 161 // from an external mouse to prevent the internal touchpad from moving it. |
155 SetMouseLocationInScreen(last_mouse_location_); | 162 SetMouseLocationInScreen(last_mouse_location_); |
156 } else { | 163 } else { |
157 // Track the last location seen from an external mouse event. | 164 // Track the last location seen from an external mouse event. |
158 last_mouse_location_ = GetMouseLocationInScreen(); | 165 last_mouse_location_ = GetMouseLocationInScreen(); |
159 } | 166 } |
160 } | 167 } |
161 | 168 |
162 } // namespace ash | 169 } // namespace ash |
OLD | NEW |