From 95f134b3238d24ff33b6948910f50d4179b33540 Mon Sep 17 00:00:00 2001 From: rdbende Date: Thu, 28 Dec 2023 11:24:09 +0100 Subject: [PATCH] Add insane hack to workaround the problem --- cozy/ui/widgets/seek_bar.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/cozy/ui/widgets/seek_bar.py b/cozy/ui/widgets/seek_bar.py index 31c9e5c6..38114297 100644 --- a/cozy/ui/widgets/seek_bar.py +++ b/cozy/ui/widgets/seek_bar.py @@ -19,15 +19,25 @@ def __init__(self, **kwargs): self.progress_scale.connect("value-changed", self._on_progress_scale_changed) - self._progress_scale_gesture = Gtk.GestureClick() - self._progress_scale_gesture.connect("pressed", self._on_progress_scale_press) - self._progress_scale_gesture.connect("end", self._on_progress_scale_release) - self.progress_scale.add_controller(self._progress_scale_gesture) - - self._progress_scale_key = Gtk.EventControllerKey() - self._progress_scale_key.connect("key-pressed", self._on_progress_scale_press) - self._progress_scale_key.connect("key-released", self._on_progress_scale_release) - self.progress_scale.add_controller(self._progress_scale_key) + # HACK: Using a GtkGestureClick here is not possible, as GtkRange's internal + # gesture controller claims the button press event, and thus the released signal doesn't get emitted. + # Therefore we get its internal GtkGestureClick, and add our handlers to that. + # Hacky workaround from: https://gitlab.gnome.org/GNOME/gtk/-/issues/4939 + # Ideally GtkRange would forward these signals, so we wouldn't need this hack + # TODO: Add these signals to Gtk and make a MR? + for controller in self.progress_scale.observe_controllers(): + if isinstance(controller, Gtk.GestureClick): + click_gesture = controller + break + + click_gesture.set_button(0) # Enable all mouse buttons + click_gesture.connect("pressed", self._on_progress_scale_press) + click_gesture.connect("released", self._on_progress_scale_release) + + keyboard_controller = Gtk.EventControllerKey() + keyboard_controller.connect("key-pressed", self._on_progress_scale_press) + keyboard_controller.connect("key-released", self._on_progress_scale_release) + self.progress_scale.add_controller(keyboard_controller) @property def position(self) -> float: @@ -91,7 +101,6 @@ def _on_progress_key_pressed(self, _, event): def _on_progress_scale_press(self, *_): self._progress_scale_pressed = True - return False GObject.signal_new('position-changed', SeekBar, GObject.SIGNAL_RUN_LAST, GObject.TYPE_PYOBJECT,