2
* Copyright 2011-2013 Armin Köhler <orangeshirt at web.de>
4
* Thanks to Lorenzo Carbonell Cerezo and Miguel Angel Santamaría Rogado
5
* which has written touchpad-indicator
6
* (https://launchpad.net/touchpad-indicator) as python app and inspired
7
* myself to write this extension for gnome-shell.
9
* This program is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU General Public License as published by the Free
11
* Software Foundation; either version 2 of the License, or (at your option)
14
* This program is distributed in the hope that it will be useful, but WITHOUT
15
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19
* You should have received a copy of the GNU General Public License along with
20
* this program; if not, write to:
21
* The Free Software Foundation, Inc.,
22
* 51 Franklin Street, Fifth Floor
23
* Boston, MA 02110-1301, USA.
27
const GLib = imports.gi.GLib;
28
const Gio = imports.gi.Gio;
30
const Gettext = imports.gettext.domain('touchpad-indicator@orangeshirt');
31
const _ = Gettext.gettext;
33
const Me = imports.misc.extensionUtils.getCurrentExtension();
36
const StoragePath = '.local/share/gnome-shell/extensions/'+
37
Me.metadata.uuid.toString();
38
GLib.mkdir_with_parents(StoragePath, parseInt('0775', 8));
40
// Debug Mode Settings
41
var DEBUG = false; // overwritten by settings
42
const FORCE_DEBUG = false;
43
var DEBUG_TO_FILE = false; // overwritten by settings
44
var DEBUG_INFO = 'Extension '+ Me.metadata.name.toString() +': ';
45
var DEBUG_LOG_FILE = GLib.build_filenamev([StoragePath,
46
'touchpad-indicator.log']);
47
if (GLib.file_test(DEBUG_LOG_FILE, GLib.FileTest.EXISTS) === false)
48
GLib.file_set_contents(DEBUG_LOG_FILE, "");
54
const TOUCHPADS = new Array('touchpad','glidepoint','fingersensingpad',
55
'bcm5974','trackpad','smartpad');
56
var ALL_TOUCHPADS = TOUCHPADS.slice();
57
const TRACKPOINTS = new Array('trackpoint','accu point','trackstick',
58
'touchstyk','pointing stick','dualpoint stick');
59
const FINGER_TOUCHES = Array('finger touch');
60
const TOUCHSCREENS = Array('touchscreen', 'maxtouch');
61
const PENS = Array('pen stylus', 'pen eraser');
62
const OTHERS = new Array();
63
var ALL_OTHERS = OTHERS.slice();
65
// Methods to en- or disable the touchpad
73
const SETTINGS_SCHEMA = 'org.gnome.shell.extensions.touchpad-indicator';
74
const TOUCHPAD_SETTINGS_SCHEMA =
75
'org.gnome.desktop.peripherals.touchpad';
81
logtxt = GLib.file_get_contents(DEBUG_LOG_FILE)[1].toString();
83
logtxt = _("Sorry could not read logfile!\n") + err;
88
function logging(message, debug, debug_to_file) {
89
if (debug === undefined) {
94
if (debug_to_file === undefined) {
95
debug_to_file = DEBUG_TO_FILE;
97
DEBUG_TO_FILE = debug_to_file;
99
if (debug || FORCE_DEBUG) {
100
let timestamp = format_time(new Date(new Date().getTime()));
101
message = timestamp + " " + message + "\n";
102
global.log(DEBUG_INFO + message);
104
let file = get_logs();
105
let txt = file + message;
106
GLib.file_set_contents(DEBUG_LOG_FILE, txt);
111
function format_time(d) {
112
function pad(n) { return n < 10 ? '0' + n : n; }
113
return d.getUTCFullYear()+'-'
114
+ pad(d.getUTCMonth()+1)+'-'
115
+ pad(d.getUTCDate())+'T'
116
+ pad(d.getUTCHours())+':'
117
+ pad(d.getUTCMinutes())+':'
118
+ pad(d.getUTCSeconds())+'Z';
121
function execute_sync(command) {
123
return GLib.spawn_command_line_sync(command);
125
logging(err.message.toString());
130
function execute_async(command) {
132
return GLib.spawn_command_line_async(command);
134
logging(err.message.toString());
139
function list_mouse_devices() {
140
logging('Lib.list_mouse_devices()');
141
let comp = execute_sync('cat /proc/bus/input/devices');
143
let where = comp[1].toString().split("\n\n"),
144
mouses = new Array(),
147
for (let x = 0; x < where.length; x++) {
148
if (!(where[x].indexOf('mouse') == -1)) {
149
let data = where[x].toString().split("\n");
150
for (let z = 0; z < data.length; z++) {
151
if (!(data[z].indexOf("N: Name=") == -1)) {
152
name = data[z].split("\"")[1];
153
logging('Lib.list_mouse_devices(): Device found: '
155
mouses[hits] = name.toString();
162
return [true, mouses];
164
logging('Lib.list_mouse_devices(): Could not detect a mouse device');
165
return [false, _(" - No mouse device detected.") + "\n"];
168
logging('Lib.list_mouse_devices(): Sorry "cat" has no output');
169
return [false, _(" - No mouse device detected.") + "\n"];
172
function search_touchpads() {
173
logging('Lib.search_touchpads()');
174
var where = list_mouse_devices();
179
for (let x = 0; x < where.length; x++) {
180
for (let tpd = 0; tpd < TOUCHPADS.length; tpd++) {
181
if (!(where[x].toLowerCase().indexOf(
182
TOUCHPADS[tpd].toString()) == -1)) {
183
logging('Lib.search_touchpads(): Touchpad found: '
184
+ where[x].toString());
187
touchpads += where[x].toString();
192
if (touchpads != "") {
193
return [true, touchpads + "\n"];
195
logging('Lib.search_touchpads(): Could not detect a touchpad');
196
return [false, _("No Touchpad detected.") + "\n"];
199
logging('Lib.search_touchpads(): Sorry "cat" has no output');
200
return [false, _("No Touchpad detected.") + "\n"];
203
function list_mouses(skip_excluded) {
204
logging('Lib.list_mouses()');
205
let where = list_mouse_devices(),
206
mouses = new Array(false, []);
207
logging('Lib.list_mouses(): ' + where.toString());
211
for (let x = 0; x < where.length; x++) {
212
for (let tpd = 0; tpd < TOUCHPADS.length; tpd++) {
213
if (!(where[x].toLowerCase().indexOf(
214
TOUCHPADS[tpd].toString()) == -1)) {
215
logging('Lib.list_mouses(): Touchpad found: '
216
+ where[x].toString());
221
for (let tpt = 0; tpt < TRACKPOINTS.length; tpt++) {
222
if (!(where[x].toLowerCase().indexOf(
223
TRACKPOINTS[tpt].toString()) == -1)) {
224
logging('Lib.list_mouses(): Trackpoint found: '
225
+ where[x].toString());
230
for (let tch = 0; tch < TOUCHSCREENS.length; tch++) {
231
if (!(where[x].toLowerCase().indexOf(
232
TOUCHSCREENS[tch].toString()) == -1)) {
233
logging('Lib.list_mouses(): Touchscreen found: '
234
+ where[x].toString());
239
for (let tch = 0; tch < FINGER_TOUCHES.length; tch++) {
240
if (!(where[x].toLowerCase().indexOf(
241
FINGER_TOUCHES[tch].toString()) == -1)) {
242
logging('Lib.list_mouses(): Fingertouch found: '
243
+ where[x].toString());
248
for (let pen = 0; pen < PENS.length; pen++) {
249
if (!(where[x].toLowerCase().indexOf(
250
PENS[pen].toString()) == -1)) {
251
logging('Lib.list_mouses(): Pen found: '
252
+ where[x].toString());
258
for (let oth = 0; oth < ALL_OTHERS.length; oth++) {
259
if (!(where[x].toLowerCase().indexOf(
260
ALL_OTHERS[oth].toString()) == -1)) {
262
logging('Lib.list_mouses(): Other device to ignore'
263
+ ' found: '+ where[x].toString());
269
logging('Lib.list_mouses(): Mouse found: '
270
+ where[x].toString());
272
mouses[1][mouses[1].length] = where[x].toString();
279
logging('Lib.list_mouses(): Could not detect a mouse ');
283
function watch_mouse() {
284
let file = Gio.file_new_for_path("/dev/input")
285
return file.monitor_directory(Gio.FileMonitorFlags.NONE, null);
288
function load_excluded_mouses(excluded_mouses) {
289
ALL_OTHERS = OTHERS.slice();
290
for(var key in excluded_mouses) {
291
if (excluded_mouses[key])
292
ALL_OTHERS[ALL_OTHERS.length] = key.toString().toLowerCase();