Skip to content

Commit

Permalink
Add insane hack to workaround the problem
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende committed Dec 28, 2023
1 parent 1be8d73 commit 95f134b
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions cozy/ui/widgets/seek_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 95f134b

Please sign in to comment.