From 50b110fc7d6d43ad375c75edb01f809b3109a129 Mon Sep 17 00:00:00 2001 From: Pierre Equoy Date: Wed, 15 Jun 2022 11:52:14 +0800 Subject: Fix:touchpad_test.py: icons Gtk.STOCK_INDEX shows an icon with a few horizontal lines in recent versions of Ubuntu. Replacing this with Gtk.STOCK_DIALOG_QUESTION, an interrogation mark. --- bin/touchpad_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/touchpad_test.py b/bin/touchpad_test.py index 6ecde92..95d096d 100755 --- a/bin/touchpad_test.py +++ b/bin/touchpad_test.py @@ -43,7 +43,7 @@ class GtkScroller(object): # Initialize GTK constants self.ICON_SIZE = Gtk.IconSize.BUTTON self.ICON_TESTED = Gtk.STOCK_YES - self.ICON_UNTESTED = Gtk.STOCK_INDEX + self.ICON_UNTESTED = Gtk.STOCK_DIALOG_QUESTION self.ICON_NOT_REQUIRED = Gtk.STOCK_REMOVE self.button_factory = Gtk.Button @@ -78,7 +78,7 @@ class GtkScroller(object): for direction in self.directions: self._add_label(button_hbox, direction.name) self.icons[direction] = self._add_image( - validation_hbox, Gtk.STOCK_INDEX) + validation_hbox, self.ICON_UNTESTED) self.show_text( _("Please move the mouse cursor to this window.") + -- cgit v1.2.3 From af20bbbdada16cdcb36af1cb7f86918d8ed9f196 Mon Sep 17 00:00:00 2001 From: Pierre Equoy Date: Wed, 15 Jun 2022 11:53:10 +0800 Subject: Fix:touchpad_test.py: Deprecation warnings Fix code to avoid deprecation warnings from Gtk in the logs --- bin/touchpad_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/touchpad_test.py b/bin/touchpad_test.py index 95d096d..9c55196 100755 --- a/bin/touchpad_test.py +++ b/bin/touchpad_test.py @@ -70,7 +70,7 @@ class GtkScroller(object): button_hbox = self._add_hbox(vbox) validation_hbox = self._add_hbox(vbox) self.status = self._add_label(vbox) - self.exit_button = self._add_button(vbox, Gtk.STOCK_CLOSE) + self.exit_button = self._add_button(vbox, "_Close") self.exit_button.connect("clicked", lambda w: self.quit()) # Add widgets for each direction. @@ -85,8 +85,8 @@ class GtkScroller(object): "\n" + _("Then scroll in each direction on your touchpad.")) - def _add_button(self, context, stock): - button = self.button_factory(stock=stock) + def _add_button(self, context, label): + button = self.button_factory.new_with_mnemonic(label) context.add(button) button.show() return button @@ -156,7 +156,7 @@ class GtkScroller(object): def found_direction(self, direction): direction.tested = True - self.icons[direction].set_from_stock( + self.icons[direction].set_from_icon_name( self.ICON_TESTED, size=self.ICON_SIZE) self.check_directions() -- cgit v1.2.3 From f46c63f429b8f2cfaa95a004e38b4bde03b47fbf Mon Sep 17 00:00:00 2001 From: Pierre Equoy Date: Wed, 15 Jun 2022 11:54:54 +0800 Subject: Fix:touchpad_test.py: remove unused gsettings key "horiz-scroll-enabled" has been removed in GNOME 3.34 and was never an official key to begin with (it had to be enabled manually in dconf). --- bin/touchpad_test.py | 8 -------- 1 file changed, 8 deletions(-) (limited to 'bin') diff --git a/bin/touchpad_test.py b/bin/touchpad_test.py index 9c55196..b859730 100755 --- a/bin/touchpad_test.py +++ b/bin/touchpad_test.py @@ -124,15 +124,10 @@ class GtkScroller(object): def run(self): # Save touchpad settings. - if self.horiz_scroll_key: - self.saved_horiz_scroll_enabled = \ - self.touchpad_settings.get_boolean("horiz-scroll-enabled") self.saved_scroll_method = self.touchpad_settings.get_string( "scroll-method") # Set touchpad settings. - if self.horiz_scroll_key: - self.touchpad_settings.set_boolean("horiz-scroll-enabled", True) if self.edge_scroll: self.touchpad_settings.set_string( "scroll-method", "edge-scrolling") @@ -141,9 +136,6 @@ class GtkScroller(object): def quit(self): # Reset touchpad settings. - if self.horiz_scroll_key: - self.touchpad_settings.set_boolean( - "horiz-scroll-enabled", self.saved_horiz_scroll_enabled) self.touchpad_settings.set_string( "scroll-method", self.saved_scroll_method) -- cgit v1.2.3 From 324babd388cf0086f0e76926c4eae876102c56ce Mon Sep 17 00:00:00 2001 From: Pierre Equoy Date: Wed, 15 Jun 2022 12:01:12 +0800 Subject: Fix:touchpad_test.py: Use smooth scrolling events to determine direction "scroll-method" was removed back in 2015[1] and replaced with "edge-scrolling-enabled" and "two-finger-scrolling-enabled" keys (both of them boolean values)[2]. Moreover, Wayland and recent versions of X (libinput) dispatch a GDK_SCROLL_SMOOTH event instead of the old GDK_SCROLL_[UP|DOWN|LEFT|RIGHT]. However, using this, the script has to compute the direction using the deltas provided by event.get_scroll_deltas(). This works on default GNOME settings ("Natural Scrolling" enabled). LP: #1969170 [1] https://github.com/GNOME/gsettings-desktop-schemas/commit/656aca6942c8417ddb3216063b97b7a1336076c9 [2] https://github.com/GNOME/gsettings-desktop-schemas/commit/d9dfe56726e49d3a31354466c3fffa2aaedf5a5e --- bin/touchpad_test.py | 52 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) (limited to 'bin') diff --git a/bin/touchpad_test.py b/bin/touchpad_test.py index b859730..83940ec 100755 --- a/bin/touchpad_test.py +++ b/bin/touchpad_test.py @@ -3,6 +3,7 @@ import gi import sys import gettext +from time import sleep from gettext import gettext as _ gi.require_version('Gdk', '3.0') @@ -124,21 +125,33 @@ class GtkScroller(object): def run(self): # Save touchpad settings. - self.saved_scroll_method = self.touchpad_settings.get_string( - "scroll-method") + self.saved_edge_scrolling_enabled = self.touchpad_settings.get_boolean( + "edge-scrolling-enabled") + self.saved_two_finger_enabled = self.touchpad_settings.get_boolean( + "two-finger-scrolling-enabled") # Set touchpad settings. if self.edge_scroll: - self.touchpad_settings.set_string( - "scroll-method", "edge-scrolling") - + self.touchpad_settings.set_boolean( + "edge-scrolling-enabled", True) + self.touchpad_settings.set_boolean( + "two-finger-scrolling-enabled", False) + else: + self.touchpad_settings.set_boolean( + "two-finger-scrolling-enabled", True) + self.touchpad_settings.set_boolean( + "edge-scrolling-enabled", False) Gtk.main() def quit(self): # Reset touchpad settings. - self.touchpad_settings.set_string( - "scroll-method", self.saved_scroll_method) - + self.touchpad_settings.set_boolean( + "two-finger-scrolling-enabled", self.saved_two_finger_enabled) + # GNOME does not like when both settings are set at the same time, so + # waiting a bit. + sleep(0.1) + self.touchpad_settings.set_boolean( + "edge-scrolling-enabled", self.saved_edge_scrolling_enabled) Gtk.main_quit() def show_text(self, text, widget=None): @@ -161,10 +174,25 @@ class GtkScroller(object): def on_scroll(self, window, event): for direction in self.directions: - if direction.value == event.direction: - self.found_direction(direction) - break - + scroll_delta, delta_x, delta_y = event.get_scroll_deltas() + if scroll_delta: + event_direction = None + # Arbitrarily using 0.8, which requires a little bit of hand + # movement on the touchpads used for testing. + # Note that the directions are based on the default natural + # scrolling settings in GNOME settings. + if delta_x > 0.8: + event_direction = Direction("left") + elif delta_x < -0.8: + event_direction = Direction("right") + if delta_y > 0.8: + event_direction = Direction("up") + elif delta_y < -0.8: + event_direction = Direction("down") + if event_direction: + if direction.value == event_direction.value: + self.found_direction(direction) + break return True -- cgit v1.2.3