diff options
author | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-20 04:31:58 +0000 |
---|---|---|
committer | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-20 04:31:58 +0000 |
commit | 6c8599ef074ab0773c78a35743c851d1db790f47 (patch) | |
tree | b9e261edc7782d61ad3108c0e584d363dbfac2f3 /chrome/browser/chromeos | |
parent | 231a96b7799ebfe9704dd6ec7a7f24c39bd3f220 (diff) | |
download | chromium_src-6c8599ef074ab0773c78a35743c851d1db790f47.zip chromium_src-6c8599ef074ab0773c78a35743c851d1db790f47.tar.gz chromium_src-6c8599ef074ab0773c78a35743c851d1db790f47.tar.bz2 |
Support for mousecontrol script
Create a common pointer_settings::SetSensitivity call applicable to all input pointer devices.
Pull common code for mouse and touchpad into common functions.
Add calls for mouse status, swap left-right and sensitivity.
BUG=chromium-os:22305
TEST=plug in a mouse on a chromeos device. Mouse settings should appear in chrome://settings/system. Swap and pointer speed should work as expected.
Review URL: https://chromiumcodereview.appspot.com/9250023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r-- | chrome/browser/chromeos/preferences.cc | 6 | ||||
-rw-r--r-- | chrome/browser/chromeos/system/input_device_settings.cc | 115 | ||||
-rw-r--r-- | chrome/browser/chromeos/system/input_device_settings.h | 12 |
3 files changed, 75 insertions, 58 deletions
diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc index ec63d33..e4e0cdc 100644 --- a/chrome/browser/chromeos/preferences.cc +++ b/chrome/browser/chromeos/preferences.cc @@ -320,7 +320,7 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) { } if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) { int sensitivity = sensitivity_.GetValue(); - system::touchpad_settings::SetSensitivity(sensitivity); + system::pointer_settings::SetSensitivity(sensitivity); if (pref_name) { UMA_HISTOGRAM_CUSTOM_COUNTS( "Touchpad.Sensitivity.Changed", sensitivity, 1, 5, 5); @@ -333,9 +333,9 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) { const bool right = primary_mouse_button_right_.GetValue(); system::mouse_settings::SetPrimaryButtonRight(right); if (pref_name) - UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonLeft.Changed", right); + UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Changed", right); else - UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonLeft.Started", right); + UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Started", right); } // We don't handle prefs::kLanguageCurrentInputMethod and PreviousInputMethod diff --git a/chrome/browser/chromeos/system/input_device_settings.cc b/chrome/browser/chromeos/system/input_device_settings.cc index e22e2e2..d5b4e42 100644 --- a/chrome/browser/chromeos/system/input_device_settings.cc +++ b/chrome/browser/chromeos/system/input_device_settings.cc @@ -1,9 +1,10 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/chromeos/system/input_device_settings.h" +#include <stdarg.h> #include <string> #include <vector> @@ -22,17 +23,24 @@ using content::BrowserThread; namespace chromeos { namespace system { -namespace touchpad_settings { namespace { -const char* kTpControl = "/opt/google/touchpad/tpcontrol"; +const char kTpControl[] = "/opt/google/touchpad/tpcontrol"; +const char kMouseControl[] = "/opt/google/mouse/mousecontrol"; -bool TPCtrlExists() { - return file_util::PathExists(FilePath(kTpControl)); +bool ScriptExists(const std::string& script) { + return file_util::PathExists(FilePath(script)); } -// Launches the tpcontrol command asynchronously, if it exists. -void LaunchTpControl(const std::vector<std::string>& argv) { - if (!TPCtrlExists()) +// Executes the input control script asynchronously, if it exists. +void ExecuteScriptOnFileThread(const std::vector<std::string>& argv) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); + DCHECK(!argv.empty()); + const std::string& script(argv[0]); + + // Script must exist on device. + DCHECK(!runtime_environment::IsRunningOnChromeOS() || ScriptExists(script)); + + if (!ScriptExists(script)) return; base::LaunchOptions options; @@ -40,61 +48,67 @@ void LaunchTpControl(const std::vector<std::string>& argv) { base::LaunchProcess(CommandLine(argv), options, NULL); } -} // namespace +void ExecuteScript(int argc, ...) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + std::vector<std::string> argv; + va_list vl; + va_start(vl, argc); + for (int i = 0; i < argc; ++i) { + argv.push_back(va_arg(vl, const char*)); + } + va_end(vl); -bool TouchpadExists() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - static bool init = false; - static bool exists = false; + BrowserThread::PostTask( + BrowserThread::FILE, FROM_HERE, + base::Bind(&ExecuteScriptOnFileThread, argv)); +} - if (init) - return exists; +void SetPointerSensitivity(const char* script, int value) { + DCHECK(value > 0 && value < 6); + ExecuteScript(3, script, "sensitivity", StringPrintf("%d", value).c_str()); +} - init = true; - if (!TPCtrlExists()) - return exists; +bool DeviceExists(const char* script) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); + if (!ScriptExists(script)) + return false; std::vector<std::string> argv; - argv.push_back(kTpControl); + argv.push_back(script); argv.push_back("status"); std::string output; - // On devices with no touchpad, output is empty. - exists = base::GetAppOutput(CommandLine(argv), &output) && !output.empty(); - return exists; + // Output is empty if the device is not found. + return base::GetAppOutput(CommandLine(argv), &output) && !output.empty(); } -void SetSensitivity(int value) { - // Run this on the FILE thread. - if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - base::Bind(&SetSensitivity, value)); - return; - } +} // namespace - std::vector<std::string> argv; - argv.push_back(kTpControl); - argv.push_back("sensitivity"); - argv.push_back(StringPrintf("%d", value)); +namespace pointer_settings { - LaunchTpControl(argv); +void SetSensitivity(int value) { + SetPointerSensitivity(kTpControl, value); + SetPointerSensitivity(kMouseControl, value); } -void SetTapToClick(bool enabled) { - // Run this on the FILE thread. - if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - base::Bind(&SetTapToClick, enabled)); - return; - } +} // namespace pointer_settings - std::vector<std::string> argv; - argv.push_back(kTpControl); - argv.push_back("taptoclick"); - argv.push_back(enabled ? "on" : "off"); +namespace touchpad_settings { + +bool TouchpadExists() { + // We only need to do this check once, assuming no pluggable touchpad devices. + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); + static bool init = false; + static bool exists = false; - LaunchTpControl(argv); + if (!init) { + init = true; + exists = DeviceExists(kTpControl); + } + return exists; +} + +void SetTapToClick(bool enabled) { + ExecuteScript(3, kTpControl, "taptoclick", enabled ? "on" : "off"); } } // namespace touchpad_settings @@ -102,12 +116,11 @@ void SetTapToClick(bool enabled) { namespace mouse_settings { bool MouseExists() { - // TODO(achuith, adlr): Call mouse_ctrl when it exists. - return false; + return DeviceExists(kMouseControl); } void SetPrimaryButtonRight(bool right) { - // TODO(achuith, adlr): Call mouse_ctrl when it exists. + ExecuteScript(3, kMouseControl, "swap_left_right", right ? "1" : "0"); } } // namespace mouse_settings diff --git a/chrome/browser/chromeos/system/input_device_settings.h b/chrome/browser/chromeos/system/input_device_settings.h index 51e64ff..156ae09 100644 --- a/chrome/browser/chromeos/system/input_device_settings.h +++ b/chrome/browser/chromeos/system/input_device_settings.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,13 +9,17 @@ namespace chromeos { namespace system { +namespace pointer_settings { + +// Sets the pointer sensitivity in the range [1, 5]. +void SetSensitivity(int value); + +} // namespace pointer_settings + namespace touchpad_settings { bool TouchpadExists(); -// Sets the touchpad sensitivity in range from 1 to 5. -void SetSensitivity(int value); - // Turns tap to click on / off. void SetTapToClick(bool enabled); |