| 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/system/input_device_settings.h" | 5 #include "chrome/browser/chromeos/system/input_device_settings.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/process/kill.h" | 16 #include "base/process/kill.h" |
| 17 #include "base/process/launch.h" | 17 #include "base/process/launch.h" |
| 18 #include "base/process/process_handle.h" | 18 #include "base/process/process_handle.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
| 22 #include "base/task_runner.h" | 22 #include "base/task_runner.h" |
| 23 #include "base/threading/sequenced_worker_pool.h" | 23 #include "base/threading/sequenced_worker_pool.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "ui/events/base_event_utils.h" |
| 26 #include "ui/events/devices/x11/device_data_manager_x11.h" |
| 27 #include "ui/events/devices/x11/device_list_cache_x11.h" |
| 28 #include "ui/gfx/x/x11_types.h" |
| 25 | 29 |
| 26 namespace chromeos { | 30 namespace chromeos { |
| 27 namespace system { | 31 namespace system { |
| 28 | 32 |
| 29 namespace { | 33 namespace { |
| 30 | 34 |
| 31 InputDeviceSettings* g_instance = nullptr; | 35 InputDeviceSettings* g_instance = nullptr; |
| 32 InputDeviceSettings* g_test_instance = nullptr; | 36 InputDeviceSettings* g_test_instance = nullptr; |
| 33 | 37 |
| 34 const char kDeviceTypeTouchpad[] = "touchpad"; | 38 const char kDeviceTypeTouchpad[] = "touchpad"; |
| 35 const char kDeviceTypeMouse[] = "mouse"; | 39 const char kDeviceTypeMouse[] = "mouse"; |
| 36 const char kInputControl[] = "/opt/google/input/inputcontrol"; | 40 const char kInputControl[] = "/opt/google/input/inputcontrol"; |
| 37 | 41 |
| 42 // The name of the xinput device corresponding to the internal touchpad. |
| 43 const char kInternalTouchpadName[] = "Elan Touchpad"; |
| 44 |
| 38 typedef base::RefCountedData<bool> RefCountedBool; | 45 typedef base::RefCountedData<bool> RefCountedBool; |
| 39 | 46 |
| 40 bool ScriptExists(const std::string& script) { | 47 bool ScriptExists(const std::string& script) { |
| 41 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 48 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 42 return base::PathExists(base::FilePath(script)); | 49 return base::PathExists(base::FilePath(script)); |
| 43 } | 50 } |
| 44 | 51 |
| 45 // Executes the input control script asynchronously, if it exists. | 52 // Executes the input control script asynchronously, if it exists. |
| 46 void ExecuteScriptOnFileThread(const std::vector<std::string>& argv) { | 53 void ExecuteScriptOnFileThread(const std::vector<std::string>& argv) { |
| 47 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 54 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 void SetTapToClick(bool enabled) override; | 160 void SetTapToClick(bool enabled) override; |
| 154 void SetThreeFingerClick(bool enabled) override; | 161 void SetThreeFingerClick(bool enabled) override; |
| 155 void SetTapDragging(bool enabled) override; | 162 void SetTapDragging(bool enabled) override; |
| 156 void SetNaturalScroll(bool enabled) override; | 163 void SetNaturalScroll(bool enabled) override; |
| 157 void MouseExists(const DeviceExistsCallback& callback) override; | 164 void MouseExists(const DeviceExistsCallback& callback) override; |
| 158 void UpdateMouseSettings(const MouseSettings& settings) override; | 165 void UpdateMouseSettings(const MouseSettings& settings) override; |
| 159 void SetMouseSensitivity(int value) override; | 166 void SetMouseSensitivity(int value) override; |
| 160 void SetPrimaryButtonRight(bool right) override; | 167 void SetPrimaryButtonRight(bool right) override; |
| 161 void ReapplyTouchpadSettings() override; | 168 void ReapplyTouchpadSettings() override; |
| 162 void ReapplyMouseSettings() override; | 169 void ReapplyMouseSettings() override; |
| 170 void SetInternalTouchpadEnabled(bool enabled) override; |
| 171 void SetTouchscreensEnabled(bool enabled) override; |
| 163 | 172 |
| 164 // Generate arguments for the inputcontrol script. | 173 // Generate arguments for the inputcontrol script. |
| 165 // | 174 // |
| 166 // |argv| is filled with arguments of script, that should be launched in order | 175 // |argv| is filled with arguments of script, that should be launched in order |
| 167 // to apply update. | 176 // to apply update. |
| 168 void GenerateTouchpadArguments(std::vector<std::string>* argv); | 177 void GenerateTouchpadArguments(std::vector<std::string>* argv); |
| 169 void GenerateMouseArguments(std::vector<std::string>* argv); | 178 void GenerateMouseArguments(std::vector<std::string>* argv); |
| 170 | 179 |
| 171 TouchpadSettings current_touchpad_settings_; | 180 TouchpadSettings current_touchpad_settings_; |
| 172 MouseSettings current_mouse_settings_; | 181 MouseSettings current_mouse_settings_; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 current_touchpad_settings_ = TouchpadSettings(); | 263 current_touchpad_settings_ = TouchpadSettings(); |
| 255 UpdateTouchpadSettings(settings); | 264 UpdateTouchpadSettings(settings); |
| 256 } | 265 } |
| 257 | 266 |
| 258 void InputDeviceSettingsImplX11::ReapplyMouseSettings() { | 267 void InputDeviceSettingsImplX11::ReapplyMouseSettings() { |
| 259 MouseSettings settings = current_mouse_settings_; | 268 MouseSettings settings = current_mouse_settings_; |
| 260 current_mouse_settings_ = MouseSettings(); | 269 current_mouse_settings_ = MouseSettings(); |
| 261 UpdateMouseSettings(settings); | 270 UpdateMouseSettings(settings); |
| 262 } | 271 } |
| 263 | 272 |
| 273 void InputDeviceSettingsImplX11::SetInternalTouchpadEnabled(bool enabled) { |
| 274 ui::DeviceDataManagerX11* device_data_manager = |
| 275 ui::DeviceDataManagerX11::GetInstance(); |
| 276 if (!device_data_manager->IsXInput2Available()) |
| 277 return; |
| 278 |
| 279 const XIDeviceList& xi_dev_list = |
| 280 ui::DeviceListCacheX11::GetInstance()->GetXI2DeviceList( |
| 281 gfx::GetXDisplay()); |
| 282 for (int i = 0; i < xi_dev_list.count; ++i) { |
| 283 std::string device_name(xi_dev_list[i].name); |
| 284 base::TrimWhitespaceASCII(device_name, base::TRIM_TRAILING, &device_name); |
| 285 if (device_name == kInternalTouchpadName) { |
| 286 if (enabled) |
| 287 device_data_manager->EnableDevice(xi_dev_list[i].deviceid); |
| 288 else |
| 289 device_data_manager->DisableDevice(xi_dev_list[i].deviceid); |
| 290 |
| 291 return; |
| 292 } |
| 293 } |
| 294 } |
| 295 |
| 296 void InputDeviceSettingsImplX11::SetTouchscreensEnabled(bool enabled) { |
| 297 ui::SetTouchEventsEnabled(enabled); |
| 298 } |
| 299 |
| 264 void InputDeviceSettingsImplX11::GenerateTouchpadArguments( | 300 void InputDeviceSettingsImplX11::GenerateTouchpadArguments( |
| 265 std::vector<std::string>* argv) { | 301 std::vector<std::string>* argv) { |
| 266 argv->push_back(kInputControl); | 302 argv->push_back(kInputControl); |
| 267 if (current_touchpad_settings_.IsSensitivitySet()) { | 303 if (current_touchpad_settings_.IsSensitivitySet()) { |
| 268 AddSensitivityArguments(kDeviceTypeTouchpad, | 304 AddSensitivityArguments(kDeviceTypeTouchpad, |
| 269 current_touchpad_settings_.GetSensitivity(), argv); | 305 current_touchpad_settings_.GetSensitivity(), argv); |
| 270 } | 306 } |
| 271 if (current_touchpad_settings_.IsTapToClickSet()) { | 307 if (current_touchpad_settings_.IsTapToClickSet()) { |
| 272 AddTPControlArguments("tapclick", | 308 AddTPControlArguments("tapclick", |
| 273 current_touchpad_settings_.GetTapToClick(), argv); | 309 current_touchpad_settings_.GetTapToClick(), argv); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 void InputDeviceSettings::SetSettingsForTesting( | 351 void InputDeviceSettings::SetSettingsForTesting( |
| 316 InputDeviceSettings* test_settings) { | 352 InputDeviceSettings* test_settings) { |
| 317 if (g_test_instance == test_settings) | 353 if (g_test_instance == test_settings) |
| 318 return; | 354 return; |
| 319 delete g_test_instance; | 355 delete g_test_instance; |
| 320 g_test_instance = test_settings; | 356 g_test_instance = test_settings; |
| 321 } | 357 } |
| 322 | 358 |
| 323 } // namespace system | 359 } // namespace system |
| 324 } // namespace chromeos | 360 } // namespace chromeos |
| OLD | NEW |