Skip to content

Commit

Permalink
TouchpadOnOff extension: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Rmano committed Dec 30, 2023
0 parents commit add7102
Show file tree
Hide file tree
Showing 10 changed files with 566 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*~
*.swp
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# TouchPad On-Off

By Romano Giannetti <[email protected]> , <[email protected]>

### Rationale

Most laptops have a key combination (usually some Fn-*thing*) to enable/disable the touchpad.
But not all of them. My Lenovo Yoga L13, for example, doesn't have one.
This extension just enables/disables the touchpad;
by default it restores the touchpad in the enabled state when you logout and login,
but you can choose to just remember the old state in the options.

### Features

Click on the icon to change from Touchpad On to Off.

Each click toggle the status.

### Options

* You can choose to have a notification for each change of status or not.
(default yes)
* You can choose if the touchpad starts enabled after login (default yes) or if it remembers the last value.

![screenshot](screenshot.png)

### I'm stuck!

If you are stuck without mouse or touchpad, open a terminal window
or the command prompt of gnome shell (with Alt-F2) and issue

dconf write /org/gnome/desktop/peripherals/touchpad/send-events true

...and you'll have your touchpad back.

89 changes: 89 additions & 0 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Touchpad On Off extension (c) 2024 Romano Giannetti <[email protected]>
// License: GPLv2+, see http://www.gnu.org/licenses/gpl-2.0.txt
//
import Clutter from 'gi://Clutter';
import St from 'gi://St';
import Gio from 'gi://Gio';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';

import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';

let button, icon_on, icon_off, wm_prefs, my_prefs;

function _switch() {
let what=wm_prefs.get_string('send-events');
let pNotify=my_prefs.get_boolean('show-notifications');
if (what == 'enabled') {
if (pNotify) {
Main.notify("Touchpad On Off", "Switching touchpad off");
}
// not needed, set by the callback
// button.set_child(icon_off);
wm_prefs.set_string('send-events', 'disabled');
} else {
if (pNotify) {
Main.notify("Touchpad On Off", "Switchin touchpad on");
}
// not needed, set by the callback
// button.set_child(icon_on);
wm_prefs.set_string('send-events', 'enabled');
}
}

function _sync() {
let what=wm_prefs.get_string('send-events');
if (what == 'enabled') {
button.set_child(icon_on);
} else {
button.set_child(icon_off);
}
}

export default class TouchpadOnOff extends Extension {
constructor(metadata) {
super(metadata);
this._metadata = metadata;
this._first_time = true;
}
enable() {
button = new St.Bin({ style_class: 'panel-button',
reactive: true,
can_focus: true,
track_hover: true });
let dir;
dir = this._metadata.path;
icon_on = new St.Icon({ style_class: 'system-status-icon'});
icon_on.gicon = Gio.icon_new_for_string(dir + '/icons/touchpadon.svg');
icon_off = new St.Icon({ style_class: 'system-status-icon'});
icon_off.gicon = Gio.icon_new_for_string(dir + '/icons/touchpadoff.svg');
wm_prefs=new Gio.Settings({schema: 'org.gnome.desktop.peripherals.touchpad'});
// get settings
my_prefs= this.getSettings();
// let activate the touchpad on login. Useful if you get stuck
// without any pointing device!
if (this._first_time) {
let enable_on_login=my_prefs.get_boolean('enable-on-login');
if (enable_on_login) {
wm_prefs.set_string('send-events', 'enabled');
this._first_time = false;
}
}
this._connectionId = button.connect('button-press-event', _switch);
this._setconnectionId = wm_prefs.connect('changed::send-events', (s, k) => { _sync() });
// start with the current status --- sync icon
_sync();
Main.panel._rightBox.insert_child_at_index(button, 0);
}
disable() {
button.disconnect(this._connectionId);
wm_prefs.disconnect(this._setconnectionId);
Main.panel._rightBox.remove_child(button);
button?.destroy();
button = null;
wm_prefs = null;
my_prefs = null;
icon_on = null;
icon_off = null;
}
}

181 changes: 181 additions & 0 deletions [email protected]/icons/touchpadoff.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit add7102

Please sign in to comment.