Skip to content

Commit

Permalink
Gestures obey natural-scroll touchpad setting (#373)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wraithm authored Mar 8, 2021
1 parent 68e0ef7 commit 10215f5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions gestures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 10215f5

Please sign in to comment.