From 10215f57e8b34a044e10b7407cac8fac4b93bbbc Mon Sep 17 00:00:00 2001 From: Matthew Wraith Date: Mon, 8 Mar 2021 12:21:39 -0600 Subject: [PATCH] Gestures obey natural-scroll touchpad setting (#373) Closes #371 Right now when I three-finger scroll in Wayland, moving my hand to the right makes the windows move to the right as if dragging the proverbial paper. As in, scrolling moves the content, not the view. In Gnome's mouse/trackpad settings, this is referred to as "Natural Scrolling". One can disable "Natural Scrolling" such that two-finger scrolling results in moving the view, not the content. This commit makes PaperWM respect the natural-scroll touchpad global setting. If unnatural scrolling is enabled in Gnome's global settings, then PaperWM will use unnatural scroll touchpad gestures, and vice versa. The scroll direction is encoded as either a 1 or -1 and checks the Gnome settings every Clutter.TouchpadGesturePhase.BEGIN. There could be an extension added to this to make this setting toggle-able separately from Gnome's global settings. There could be a separate setting that overrides the Gnome global setting. There could be people who prefer unnatural scrolling for their browser and such but natural scrolling for PaperWM. --- gestures.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gestures.js b/gestures.js index f827027..f21e718 100644 --- a/gestures.js +++ b/gestures.js @@ -39,11 +39,17 @@ var time; var vState; var navigator; var direction = undefined; +// 1 is natural scrolling, -1 is unnatural +var natural = 1; function enable() { // Touchpad swipes only works in Wayland if (!Meta.is_wayland_compositor()) return; + var touchpadSettings = new Gio.Settings({ + schema_id: 'org.gnome.desktop.peripherals.touchpad' + }); + signals.destroy(); /** In order for the space.background actors to get any input we need to hide @@ -75,12 +81,13 @@ function enable() { } } if (direction === DIRECTIONS.Vertical) { - updateVertical(-dy*prefs.swipe_sensitivity[1], event.get_time()); + updateVertical(-dy*natural*prefs.swipe_sensitivity[1], event.get_time()); return Clutter.EVENT_STOP; } return Clutter.EVENT_PROPAGATE; case Clutter.TouchpadGesturePhase.BEGIN: time = event.get_time(); + natural = touchpadSettings.get_boolean("natural-scroll") ? 1 : -1; direction = undefined; navigator = Navigator.getNavigator(); navigator.connect('destroy', () => { @@ -126,7 +133,7 @@ function horizontalScroll(actor, event) { Tweener.removeTweens(this.cloneContainer); direction = DIRECTIONS.Horizontal; } - return update(this, -dx*prefs.swipe_sensitivity[0], event.get_time()); + return update(this, -dx*natural*prefs.swipe_sensitivity[0], event.get_time()); case Clutter.TouchpadGesturePhase.CANCEL: case Clutter.TouchpadGesturePhase.END: this.hState = phase;