Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if natural-scroll is enabled, invert scroll inputs #113

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class MprisLabel extends PanelMenu.Button {
const EXTENSION_PLACE = this.settings.get_string('extension-place');
const REPOSITION_DELAY = this.settings.get_int('reposition-delay');

this.mouseSettings = new Gio.Settings({ schema: 'org.gnome.desktop.peripherals.mouse' });
this.touchpadSettings = new Gio.Settings({ schema: 'org.gnome.desktop.peripherals.touchpad' });

this.box = new St.BoxLayout({
x_align: Clutter.ActorAlign.FILL
});
Expand Down Expand Up @@ -171,9 +174,6 @@ class MprisLabel extends PanelMenu.Button {
if(SCROLL_ACTION == 'none')
return Clutter.EVENT_STOP

if (event.is_pointer_emulated())
return Clutter.EVENT_PROPAGATE;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this was initially added. It seems like my touchpad has a lot of scroll events that are considered emulated but otherwise look normal. This was causing problems for me because I have another extension with scroll event handling on the entire menu bar. A bunch of scroll events would hit this and propagate through, even though I just wanted to interact with the mpris label.
So that's why I removed it. Could also just make it return EVENT_STOP instead.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this was initially added.

I don't remember, though gnome-shell's code does the same.

This was causing problems for me because I have another extension with scroll event handling on the entire menu bar.

We found the same issue you are describing with Dash-to-panel (#47).

So that's why I removed it. Could also just make it return EVENT_STOP instead.

I'm not sure if we want "emulated scroll events" to trigger the scrolling action, this would probably change the volume increasing/decreasing speed in some hardware (can you test if this is the case in yours?). The idea is to follow gnome's volume widget on behaviour, though we are changing scroll direction here... speed, so I'm more inclined to change EVENT_PROPAGATE to EVENT_STOP.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this bugzilla thread: https://bugzilla.gnome.org/show_bug.cgi?id=687573, and these commits: https://gitlab.gnome.org/GNOME/gnome-shell/-/commit/7d4e14f38455977ffb103acd85239ed6b1a9d816, https://gitlab.gnome.org/GNOME/gnome-shell/-/commit/c9741ae3d5f661b2aee352c50ce21fab16694fbe (the last one is somewhat confusing to me since I definitely observe events with is_pointer_emulated() true).
It seems that some events are essentially duplicated, one emulated and one not emulated... I don't have the historical reasoning for why this is the case but my impression is that it has to do with retrofitting touchpad support into X11.

I suppose ideally other extensions should also be checking this, but in practice it doesn't make a lot of sense to propagate the events instead of just ignoring them completely.

Upshot: happy to use EVENT_STOP, makes sense.

let delta = 0;
const time_delta = Date.now() - this.last_scroll;
switch (event.get_scroll_direction()) {
Expand All @@ -198,6 +198,22 @@ class MprisLabel extends PanelMenu.Button {
return Clutter.EVENT_PROPAGATE;
}

// If natural-scroll is enabled, the scroll event we get is inverted.
// We need to invert it back.
switch (event.get_source_device().get_device_type()) {
case Clutter.InputDeviceType.POINTER_DEVICE:
// mouse
if(this.mouseSettings.get_boolean('natural-scroll'))
delta = -delta;
break;

case Clutter.InputDeviceType.TOUCHPAD_DEVICE:
// touchpad
if(this.touchpadSettings.get_boolean('natural-scroll'))
delta = -delta;
break;
}

if(!delta == 0)
switch(SCROLL_ACTION) {
case "volume-controls":
Expand Down