| Index: chrome/browser/chromeos/system/input_device_settings.cc
|
| ===================================================================
|
| --- chrome/browser/chromeos/system/input_device_settings.cc (revision 118341)
|
| +++ chrome/browser/chromeos/system/input_device_settings.cc (working copy)
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "chrome/browser/chromeos/system/input_device_settings.h"
|
|
|
| +#include <stdarg.h>
|
| #include <string>
|
| #include <vector>
|
|
|
| @@ -22,17 +23,24 @@
|
| 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,74 +48,79 @@
|
| 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 {
|
|
|
| - LaunchTpControl(argv);
|
| +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;
|
| +
|
| + if (!init) {
|
| + init = true;
|
| + exists = DeviceExists(kTpControl);
|
| + }
|
| + return exists;
|
| }
|
|
|
| +void SetTapToClick(bool enabled) {
|
| + ExecuteScript(3, kTpControl, "taptoclick", enabled ? "on" : "off");
|
| +}
|
| +
|
| } // namespace touchpad_settings
|
|
|
| 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
|
|
|