summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/system/touchpad_settings.cc
blob: 0257cc1e7049019a5595a61717ed271fe07d20d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2011 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/touchpad_settings.h"

#include "base/bind.h"
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/process_util.h"
#include "base/stringprintf.h"
#include "chrome/browser/chromeos/system/runtime_environment.h"
#include "content/browser/browser_thread.h"

namespace chromeos {
namespace system {
namespace touchpad_settings {
namespace {
const char* kTpControl = "/opt/google/touchpad/tpcontrol";
}  // namespace

// Launches the tpcontrol command asynchronously, if it exists.
void LaunchTpControl(const std::vector<std::string>& argv) {
  if (!system::runtime_environment::IsRunningOnChromeOS()) {
    // Do nothing on Linux desktop, as the command does not exist.
    return;
  }

  if (!file_util::PathExists(FilePath(argv[0]))) {
    LOG(ERROR) << argv[0] << " not found";
    return;
  }

  base::LaunchOptions options;
  options.wait = false;  // Launch asynchronously.

  base::LaunchProcess(CommandLine(argv), options, NULL);
}

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;
  }

  std::vector<std::string> argv;
  argv.push_back(kTpControl);
  argv.push_back("sensitivity");
  argv.push_back(StringPrintf("%d", value));

  LaunchTpControl(argv);
}

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;
  }

  std::vector<std::string> argv;
  argv.push_back(kTpControl);
  argv.push_back("taptoclick");
  argv.push_back(enabled ? "on" : "off");

  LaunchTpControl(argv);
}

}  // namespace touchpad_settings
}  // namespace system
}  // namespace chromeos