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.
This commit is contained in:
Matthew Wraith
2021-03-08 19:21:39 +01:00
committed by GitHub
parent 68e0ef7d9a
commit 10215f57e8
+9 -2
View File
@@ -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;