Skip to content

Commit

Permalink
Fix crash on Wayland
Browse files Browse the repository at this point in the history
The extension should continue to work under Wayland with limited functionality. Since Xinput/Synclient can not be used, GSettings will be set as the (only available) switching method.

see #11
  • Loading branch information
askmrsinh committed Apr 8, 2020
1 parent 5a20ebd commit a1e088b
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 62 deletions.
101 changes: 64 additions & 37 deletions Settings.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1
<!-- Generated with glade 3.22.2
TouchpadIndicator - Touchpad management GNOME Shell Extension.
Orignal work Copyright (C) 2011-2013 Armin Köhler <orangeshirt at web.de>
Expand Down Expand Up @@ -112,7 +112,7 @@ Author: Ashesh Singh
<object class="GtkComboBoxText" id="switchmethod_combo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">0</property>
<property name="active_id">gsettings</property>
<items>
<item id="gsettings">GSettings</item>
<item id="synclient">synclient</item>
Expand Down Expand Up @@ -673,12 +673,12 @@ Author: Ashesh Singh
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
<property name="label">Switch Method:</property>
<property name="label">xinpt:</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="top_attach">7</property>
</packing>
</child>
<child>
Expand All @@ -687,21 +687,22 @@ Author: Ashesh Singh
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
<property name="label">Touchpad(s):</property>
<property name="label">synclient:</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text">org.gnome.desktop.peripherals.touchpad send-events</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
<property name="label">synclient:</property>
<property name="label">'send-events' key:</property>
<property name="selectable">True</property>
</object>
<packing>
Expand All @@ -713,31 +714,61 @@ Author: Ashesh Singh
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text">org.gnome.shell.extensions.touchpad-indicator trackpoint-enabled</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
<property name="label">xinpt:</property>
<property name="label">'touchpad-enabled' key:</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">6</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkAccelLabel" id="switchmethod">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">-</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
<property name="label">Touchpad(s):</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
<property name="label">Switch Method:</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
<property name="label">Session Type:</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkAccelLabel" id="synclient">
<object class="GtkAccelLabel" id="xinput">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
Expand All @@ -746,25 +777,24 @@ Author: Ashesh Singh
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
<property name="top_attach">7</property>
</packing>
</child>
<child>
<object class="GtkAccelLabel" id="touchpads">
<object class="GtkAccelLabel" id="synclient">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">-</property>
<property name="wrap">True</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
<object class="GtkAccelLabel" id="xinput">
<object class="GtkAccelLabel" id="sendevents">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
Expand All @@ -773,54 +803,51 @@ Author: Ashesh Singh
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">6</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<object class="GtkAccelLabel" id="touchpadenabled">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text">org.gnome.desktop.peripherals.touchpad send-events</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
<property name="label">'send-events' key:</property>
<property name="halign">start</property>
<property name="label">-</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkAccelLabel" id="sendevents">
<object class="GtkAccelLabel" id="touchpads">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">-</property>
<property name="wrap">True</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<object class="GtkAccelLabel" id="switchmethod">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text">org.gnome.shell.extensions.touchpad-indicator trackpoint-enabled</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
<property name="label">'touchpad-enabled' key:</property>
<property name="halign">start</property>
<property name="label">-</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkAccelLabel" id="touchpadenabled">
<object class="GtkAccelLabel" id="sessiontype">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
Expand All @@ -829,7 +856,7 @@ Author: Ashesh Singh
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
Expand Down
6 changes: 6 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class TouchpadIndicatorButton extends PanelMenu.Button {
this.pointingDevices = Lib.listPointingDevices()[1];
logging(`_init(): Pointing devices are ${JSON.stringify(this.pointingDevices)}`);

// Current session type
// You may face issues using this extension under Wayland.
// https://github.com/user501254/TouchpadIndicator/issues/11
this._sessionType = Lib.SESSION_TYPE;
logging(`_init(): Session type is ${this._sessionType}`);

// TODO: Let user set program start touchpad state
// None, Enabled, Disabled

Expand Down
3 changes: 3 additions & 0 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const LOG_PREFIX = `[${Me.uuid}] `;
var DEBUG = false;
var DEBUG_TO_FILE = false;

//Session Type
const SESSION_TYPE = GLib.getenv('XDG_SESSION_TYPE');

// Possible Devices
const TOUCHPADS = ['touchpad', 'glidepoint', 'fingersensingpad', 'bcm5974', 'trackpad', 'smartpad'];
const TRACKPOINTS = ['trackpoint', 'accu point', 'trackstick', 'touchstyk', 'pointing stick', 'dualpoint stick'];
Expand Down
3 changes: 3 additions & 0 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ var Settings = class TouchpadIndicatorSettings {
let touchpads = xinput._filterByType('touchpad').names.toString();
this._builder.get_object('touchpads').set_label(touchpads);

let sessiontype = Lib.SESSION_TYPE;
this._builder.get_object('sessiontype').set_label(sessiontype);

let switchmethod = this._settings.get_string('switchmethod');
this._builder.get_object('switchmethod').set_label(switchmethod);

Expand Down
15 changes: 10 additions & 5 deletions synclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,30 @@ var Synclient = class Synclient {

_init() {
logging('_init()');
this.tpdOff = false;
this.isUsable = this._isUsable();
this.tpdOff = false;
}

_isUsable() {
if (Lib.SESSION_TYPE.indexOf('wayland') !== -1) {
logging('_isUsable(): ignoring synclient on wayland');
return false;
}

if (!USE_SYNCLIENT) {
logging('_isUsable(): synclient manually disabled');
return false;
}

let comp = Lib.executeCmdSync('synclient -l');
if ((comp[0] === false) || (comp[1] === undefined)) {
if ((comp[1] === undefined) || (comp[0] === false)) {
logging('_isUsable(): synclient not found');
return false;
} else if (comp[1].includes("Couldn't find synaptics properties")) {
logging('_isUsable(): no properties found');
return false;
} else if (comp[1].includes('TouchpadOff')) {
logging('_isUsable(): synclient found and ready to use');
logging('_isUsable(): synclient found');
return true;
}

Expand All @@ -69,15 +74,15 @@ var Synclient = class Synclient {
}

_disable() {
logging('_disable()');
if (this.isUsable) {
logging('_disable()');
this.tpdOff = !!Lib.executeCmdAsync('synclient TouchpadOff=1');
}
}

_enable() {
logging('_enable()');
if (this.isUsable) {
logging('_enable()');
this.tpdOff = !!Lib.executeCmdAsync('synclient TouchpadOff=0');
}
}
Expand Down
Loading

0 comments on commit a1e088b

Please sign in to comment.