[gnome-music/wip/jfelder/gtk4-v3: 16/21] songwidget: Handle click gesture




commit 2bdac08f89ab07455246290779e5ab459d172100
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Feb 11 11:28:20 2022 +0100

    songwidget: Handle click gesture

 data/ui/SongWidget.ui            |  6 ++++++
 gnomemusic/views/searchview.py   | 13 +------------
 gnomemusic/widgets/discbox.py    | 23 ++---------------------
 gnomemusic/widgets/songwidget.py | 12 ++++++++++++
 4 files changed, 21 insertions(+), 33 deletions(-)
---
diff --git a/data/ui/SongWidget.ui b/data/ui/SongWidget.ui
index 51924b44b..24c50c7b3 100644
--- a/data/ui/SongWidget.ui
+++ b/data/ui/SongWidget.ui
@@ -186,6 +186,12 @@
         </child>
       </object>
     </child>
+    <child>
+      <object class="GtkGestureClick">
+        <property name="button">1</property>
+        <signal name="released" handler="_on_click" swapped="no"/>
+      </object>
+    </child>
     <style>
       <class name="songwidget"/>
     </style>
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 44a8a00de..5ff2a6ef0 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -28,7 +28,7 @@ from gettext import gettext as _
 from typing import Optional
 import typing
 
-from gi.repository import Gdk, GObject, Gtk
+from gi.repository import GObject, Gtk
 
 from gnomemusic.search import Search
 from gnomemusic.utils import ArtSize
@@ -159,10 +159,6 @@ class SearchView(Gtk.Stack):
             GObject.BindingFlags.BIDIRECTIONAL
             | GObject.BindingFlags.SYNC_CREATE)
 
-        ctrl = Gtk.GestureClick()
-        song_widget.add_controller(ctrl)
-        ctrl.connect("released", self._on_song_widget_click)
-
         return song_widget
 
     def _create_album_cover(self, corealbum: CoreAlbum) -> AlbumCover:
@@ -245,13 +241,6 @@ class SearchView(Gtk.Stack):
 
         return True
 
-    def _on_song_widget_click(self, gesture_click, n_click, x, y):
-        state = gesture_click.get_current_event_state()
-        modifiers = Gtk.accelerator_get_default_mod_mask()
-        if (state & modifiers == Gdk.ModifierType.CONTROL_MASK
-                and not self.props.selection_mode):
-            self.props.selection_mode = True
-
     def _on_window_width_change(self, widget, value):
         allocation = self._album_flowbox.get_allocation()
         # FIXME: Just a bit of guesswork here.
diff --git a/gnomemusic/widgets/discbox.py b/gnomemusic/widgets/discbox.py
index 318615159..85bcd379d 100644
--- a/gnomemusic/widgets/discbox.py
+++ b/gnomemusic/widgets/discbox.py
@@ -26,7 +26,7 @@ from __future__ import annotations
 from gettext import gettext as _
 import typing
 
-from gi.repository import Gio, GObject, Gtk
+from gi.repository import Gdk, Gio, GObject, Gtk
 
 from gnomemusic.widgets.songwidget import SongWidget
 from gnomemusic.widgets.songwidgetmenu import SongWidgetMenu
@@ -107,29 +107,10 @@ class DiscBox(Gtk.ListBoxRow):
     @Gtk.Template.Callback()
     def _song_activated(
             self, list_box: Gtk.ListBox, song_widget: SongWidget) -> bool:
-        if song_widget.props.select_click:
-            song_widget.props.select_click = False
-            return True
-
-        # FIXME:
-        # With GTK4, the get_current_event api has been removed. Instead,
-        # it relies on getting the event information from the underlying
-        # controller. However, it's not possible to access it.
-        # event = Gtk.get_current_event()
-        # (_, state) = event.get_state()
-        # mod_mask = Gtk.accelerator_get_default_mod_mask()
-        # if ((state & mod_mask) == Gdk.ModifierType.CONTROL_MASK
-        #         and not self.props.selection_mode):
-        #     self.props.selection_mode = True
-        #     song_widget.props.select_click = True
-        #     song_widget.props.coresong.props.selected = True
-        #     return True
-
         if self.props.selection_mode:
-            song_widget.props.select_click = True
             selection_state = song_widget.props.coresong.props.selected
             song_widget.props.coresong.props.selected = not selection_state
         else:
             self.emit("song-activated", song_widget)
 
-        return True
+        return Gdk.EVENT_STOP
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index 5048ee49b..0f4ed60d5 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -201,6 +201,18 @@ class SongWidget(Gtk.ListBoxRow):
         # (one event in SongWidget and the other one in select_button).
         self.props.select_click = not self.props.select_click
 
+    @Gtk.Template.Callback()
+    def _on_click(
+            self, gesture_click: Gtk.GestureClick, n_click: int, x: int,
+            y: int) -> bool:
+        state = gesture_click.get_current_event_state()
+        modifiers = Gtk.accelerator_get_default_mod_mask()
+        if (state & modifiers == Gdk.ModifierType.CONTROL_MASK
+                and not self.props.selection_mode):
+            self.props.selection_mode = True
+
+        return Gdk.EVENT_STOP
+
     @Gtk.Template.Callback()
     def _on_star_toggle(
             self, controller: Gtk.GestureClick, n_press: int, x: float,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]