Skip to content

Commit

Permalink
gestures: Remove device detection.
Browse files Browse the repository at this point in the history
The csd-input-helper utility doesn't detect all potential devices,
leaving users that have suitable hardware unable to make use of it.

To reliably check for devices would require root access to read
/dev/input, which isn't something that can be done inside cinnamon
or from cinnamon-settings (other than with setuid).

ref: https://github.com/orgs/linuxmint/discussions/102
  • Loading branch information
mtwebster committed Aug 8, 2023
1 parent a80336b commit 09b9113
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 121 deletions.
157 changes: 67 additions & 90 deletions files/usr/share/cinnamon/cinnamon-settings/modules/cs_gestures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
"pinch-percent-threshold"
]

DEBUG_SHOW_ALL = False


class Module:
name = "gestures"
category = "prefs"
Expand All @@ -33,17 +30,6 @@ def __init__(self, content_box):
self.disabled_box = None

def on_module_selected(self):
have_touchpad = DEBUG_SHOW_ALL
have_touchscreen = DEBUG_SHOW_ALL

# Detect devices.
out = subprocess.getoutput("csd-input-helper").replace("\t", " ").split("\n")[:4]
for line in out:
if "touchpad" in line and line.endswith("yes"):
have_touchpad = True
if "touchscreen" in line and line.endswith("yes"):
have_touchscreen = True

installed = GLib.find_program_in_path("touchegg")
alive = self.test_daemon_alive()

Expand Down Expand Up @@ -72,14 +58,18 @@ def on_module_selected(self):
self.disabled_label = Gtk.Label(expand=True)
box.pack_start(self.disabled_label, False, False, 0)

self.disabled_page_switch = Gtk.Switch(active=self.gesture_settings.get_boolean("enabled"), no_show_all=True)
self.disabled_page_switch = Gtk.Switch(active=self.gesture_settings.get_boolean("enabled"), no_show_all=True, halign=Gtk.Align.CENTER)
self.disabled_page_switch.connect("notify::active", self.enabled_switch_changed)
box.pack_start(self.disabled_page_switch, False, False, 0)

self.disabled_retry_button = Gtk.Button(label=_("Check again"), no_show_all=True, halign=Gtk.Align.CENTER)
self.disabled_retry_button.connect("clicked", lambda w: self.on_module_selected())
box.pack_start(self.disabled_retry_button, False, False, 0)

self.disabled_page_disable_button = Gtk.Button(label=_("Disable"), no_show_all=True, halign=Gtk.Align.CENTER)
self.disabled_page_disable_button.connect("clicked", lambda w: self.gesture_settings.set_boolean("enabled", False))
box.pack_start(self.disabled_page_disable_button, False, False, 0)

ssource = Gio.SettingsSchemaSource.get_default()
schema = ssource.lookup(SCHEMA, True)
all_keys = schema.list_keys()
Expand Down Expand Up @@ -136,97 +126,91 @@ def sort_by_direction(key1, key2):
self.sidePage.stack.add_titled(page, "swipe", _("Swipe"))
size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

if have_touchscreen:
size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)
size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

section = page.add_section(_("Swipe with 2 fingers"), _("Touchscreen only"))
section = page.add_section(_("Swipe with 2 fingers"), _("Touchscreen only"))

for key in keys:
label = self.get_key_label(key, "swipe", 2)
if not label:
continue
for key in keys:
label = self.get_key_label(key, "swipe", 2)
if not label:
continue

widget = GestureComboBox(label, self.gesture_settings, key, actions, size_group=size_group)
section.add_row(widget)
widget = GestureComboBox(label, self.gesture_settings, key, actions, size_group=size_group)
section.add_row(widget)

if have_touchpad or have_touchscreen:
section = page.add_section(_("Swipe with 3 fingers"))
section = page.add_section(_("Swipe with 3 fingers"))

for key in keys:
label = self.get_key_label(key, "swipe", 3)
if not label:
continue
for key in keys:
label = self.get_key_label(key, "swipe", 3)
if not label:
continue

widget = GestureComboBox(label, self.gesture_settings, key, actions, size_group=size_group)
section.add_row(widget)
widget = GestureComboBox(label, self.gesture_settings, key, actions, size_group=size_group)
section.add_row(widget)

section = page.add_section(_("Swipe with 4 fingers"))
section = page.add_section(_("Swipe with 4 fingers"))

for key in keys:
label = self.get_key_label(key, "swipe", 4)
if not label:
continue
for key in keys:
label = self.get_key_label(key, "swipe", 4)
if not label:
continue

widget = GestureComboBox(label, self.gesture_settings, key, actions, size_group=size_group)
section.add_row(widget)
widget = GestureComboBox(label, self.gesture_settings, key, actions, size_group=size_group)
section.add_row(widget)

section = page.add_section(_("Swipe with 5 fingers"), _("Touchscreen only"))

for key in keys:
label = self.get_key_label(key, "swipe", 5)
if not label:
continue

widget = GestureComboBox(label, self.gesture_settings, key, actions, size_group=size_group)
section.add_row(widget)

page = SettingsPage()
self.sidePage.stack.add_titled(page, "pinch", _("Pinch"))
size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

if have_touchscreen:
section = page.add_section(_("Swipe with 5 fingers"), _("Touchscreen only"))
for fingers in range(2, 5):
section = page.add_section(_("Pinch with %d fingers") % fingers)

for key in keys:
label = self.get_key_label(key, "swipe", 5)
label = self.get_key_label(key, "pinch", fingers)

if not label:
continue

widget = GestureComboBox(label, self.gesture_settings, key, actions, size_group=size_group)
section.add_row(widget)

page = SettingsPage()
self.sidePage.stack.add_titled(page, "pinch", _("Pinch"))
size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)
section = page.add_section(_("Pinch with 5 fingers"), _("Touchscreen only"))

if have_touchpad or have_touchscreen:
for fingers in range(2, 5):
section = page.add_section(_("Pinch with %d fingers") % fingers)
for key in keys:
label = self.get_key_label(key, "pinch", 5)

for key in keys:
label = self.get_key_label(key, "pinch", fingers)
if not label:
continue

if not label:
continue
widget = GestureComboBox(label, self.gesture_settings, key, actions, size_group=size_group)
section.add_row(widget)

widget = GestureComboBox(label, self.gesture_settings, key, actions, size_group=size_group)
section.add_row(widget)
page = SettingsPage()
self.sidePage.stack.add_titled(page, "tap", _("Tap"))
size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

if have_touchscreen:
section = page.add_section(_("Pinch with 5 fingers"), _("Touchscreen only"))
section = page.add_section(_("Tap"), _("Touchscreen only"))

for fingers in range(2, 6):
for key in keys:
label = self.get_key_label(key, "pinch", 5)
label = self.get_key_label(key, "tap", fingers)

if not label:
continue

widget = GestureComboBox(label, self.gesture_settings, key, actions, size_group=size_group)
section.add_row(widget)

if have_touchscreen:
page = SettingsPage()
self.sidePage.stack.add_titled(page, "tap", _("Tap"))
size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

section = page.add_section(_("Tap"), _("Touchscreen only"))

for fingers in range(2, 6):
for key in keys:
label = self.get_key_label(key, "tap", fingers)

if not label:
continue

widget = GestureComboBox(label, self.gesture_settings, key, actions, size_group=size_group)
section.add_row(widget)

page = SettingsPage()
self.sidePage.stack.add_titled(page, "tweaks", _("Settings"))

Expand All @@ -248,25 +232,24 @@ def sort_by_direction(key1, key2):

self.disabled_page_switch.set_visible(False)
self.disabled_retry_button.set_visible(False)
self.disabled_page_disable_button.set_visible(False)

if not installed:
text = _("The touchegg package must be installed for gesture support.")
self.disabled_retry_button.show()
elif not self.gesture_settings.get_boolean("enabled"):
self.disabled_page_switch.set_visible(True)
text = _("Gestures are disabled")
elif not alive:
text = _("The Touchegg service is not running")
if self.gesture_settings.get_boolean("enabled"):
self.disabled_page_disable_button.set_visible(True)
self.disabled_retry_button.show()
elif not have_touchpad and not have_touchscreen:
text = _("No compatible devices found")
self.disabled_retry_button.show()
else:
self.disabled_page_switch.set_visible(True)
text = _("Gestures are disabled")

self.disabled_label.set_markup(f"<big><b>{text}</b></big>")

self.sidePage.stack.set_transition_type(Gtk.StackTransitionType.NONE)

if not enabled or not (have_touchpad or have_touchscreen) or not alive or not installed:
if not enabled or not alive or not installed:
self.disabled_label.set_markup(f"<big><b>{text}</b></big>")
page = "disabled"
else:
page = "swipe"
Expand All @@ -292,15 +275,9 @@ def on_enabled_changed(self, settings, key):
pass

enabled = settings.get_boolean("enabled")

self.disabled_page_switch.set_active(enabled)

if enabled:
Gio.Application.get_default().stack_switcher.set_opacity(1.0)
self.sidePage.stack.set_visible_child_full("swipe", Gtk.StackTransitionType.CROSSFADE)
else:
Gio.Application.get_default().stack_switcher.set_opacity(0)
self.sidePage.stack.set_visible_child_full("disabled", Gtk.StackTransitionType.CROSSFADE)
self.on_module_selected()

self.disabled_page_switch.connect("notify::active", self.enabled_switch_changed)

Expand Down
33 changes: 2 additions & 31 deletions js/ui/gestures/gesturesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const NON_GESTURE_KEYS = [
"pinch-percent-threshold"
]

const DEBUG_HAVE_DEVICES = false;
const DEBUG_GESTURES=false;

const GestureDirectionString = [
Expand Down Expand Up @@ -105,11 +104,10 @@ var GesturesManager = class {
this.settings = new Gio.Settings({ schema_id: SCHEMA })
this.signalManager.connect(this.settings, "changed", this.settings_or_devices_changed, this);
this.screenSaverProxy = new ScreenSaver.ScreenSaverProxy();
this.have_device = false;
this.client = null;
this.current_gesture = null;

this.check_for_devices();
this.settings_or_devices_changed()
}

setup_client() {
Expand Down Expand Up @@ -144,7 +142,7 @@ var GesturesManager = class {
}

settings_or_devices_changed(settings, key) {
if (this.settings.get_boolean("enabled") && this.have_device) {
if (this.settings.get_boolean("enabled")) {
this.setup_client();
return;
}
Expand Down Expand Up @@ -268,33 +266,6 @@ var GesturesManager = class {
this.current_gesture.end(direction, percentage, elapsed_time);
this.current_gesture = null;
}

check_for_devices() {
global.log("GesturesManager: Looking for devices.");
Util.spawnCommandLineAsyncIO(
"csd-input-helper",
(stdout, stderr, code) => {
let lines = stdout.replace("\t", " ").split("\n").slice(0, 5);
let have_touchpad = false;
let have_touchscreen = false
for (let line of lines) {
if (line.includes("touchpad") && line.endsWith("yes")) {
have_touchpad = true;
}
else
if (line.includes("touchscreen") && line.endsWith("yes")) {
have_touchscreen = true;
}
}

this.have_device = have_touchpad || have_touchscreen || DEBUG_HAVE_DEVICES;
if (!this.have_device) {
global.log("GesturesManager: No devices.");
}
this.settings_or_devices_changed();
}
);
}
}


0 comments on commit 09b9113

Please sign in to comment.