OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/system/input_device_settings.h" |
| 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" |
| 12 #include "base/file_path.h" |
| 13 #include "base/file_util.h" |
| 14 #include "base/message_loop.h" |
| 15 #include "base/process_util.h" |
| 16 #include "base/stringprintf.h" |
| 17 #include "chrome/browser/chromeos/system/runtime_environment.h" |
| 18 #include "content/public/browser/browser_thread.h" |
| 19 |
| 20 using content::BrowserThread; |
| 21 |
| 22 namespace chromeos { |
| 23 namespace system { |
| 24 |
| 25 namespace touchpad_settings { |
| 26 namespace { |
| 27 const char* kTpControl = "/opt/google/touchpad/tpcontrol"; |
| 28 |
| 29 bool TPCtrlExists() { |
| 30 return file_util::PathExists(FilePath(kTpControl)); |
| 31 } |
| 32 |
| 33 // Launches the tpcontrol command asynchronously, if it exists. |
| 34 void LaunchTpControl(const std::vector<std::string>& argv) { |
| 35 if (!TPCtrlExists()) |
| 36 return; |
| 37 |
| 38 base::LaunchOptions options; |
| 39 options.wait = true; |
| 40 base::LaunchProcess(CommandLine(argv), options, NULL); |
| 41 } |
| 42 |
| 43 } // namespace |
| 44 |
| 45 bool TouchpadExists() { |
| 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 47 static bool init = false; |
| 48 static bool exists = false; |
| 49 |
| 50 if (init) |
| 51 return exists; |
| 52 |
| 53 init = true; |
| 54 if (!TPCtrlExists()) |
| 55 return exists; |
| 56 |
| 57 std::vector<std::string> argv; |
| 58 argv.push_back(kTpControl); |
| 59 argv.push_back("status"); |
| 60 std::string output; |
| 61 // On devices with no touchpad, output is empty. |
| 62 exists = base::GetAppOutput(CommandLine(argv), &output) && !output.empty(); |
| 63 return exists; |
| 64 } |
| 65 |
| 66 void SetSensitivity(int value) { |
| 67 // Run this on the FILE thread. |
| 68 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 69 BrowserThread::PostTask( |
| 70 BrowserThread::FILE, FROM_HERE, |
| 71 base::Bind(&SetSensitivity, value)); |
| 72 return; |
| 73 } |
| 74 |
| 75 std::vector<std::string> argv; |
| 76 argv.push_back(kTpControl); |
| 77 argv.push_back("sensitivity"); |
| 78 argv.push_back(StringPrintf("%d", value)); |
| 79 |
| 80 LaunchTpControl(argv); |
| 81 } |
| 82 |
| 83 void SetTapToClick(bool enabled) { |
| 84 // Run this on the FILE thread. |
| 85 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 86 BrowserThread::PostTask( |
| 87 BrowserThread::FILE, FROM_HERE, |
| 88 base::Bind(&SetTapToClick, enabled)); |
| 89 return; |
| 90 } |
| 91 |
| 92 std::vector<std::string> argv; |
| 93 argv.push_back(kTpControl); |
| 94 argv.push_back("taptoclick"); |
| 95 argv.push_back(enabled ? "on" : "off"); |
| 96 |
| 97 LaunchTpControl(argv); |
| 98 } |
| 99 |
| 100 } // namespace touchpad_settings |
| 101 |
| 102 namespace mouse_settings { |
| 103 |
| 104 void SetPrimaryButtonRight(bool right) { |
| 105 // TODO(achuith, adlr): Call mouse_ctrl when it exists. |
| 106 } |
| 107 |
| 108 } // namespace mouse_settings |
| 109 |
| 110 } // namespace system |
| 111 } // namespace chromeos |
OLD | NEW |