[gnome-music/wip/mschraal/gtk4-v2: 5/60] GTK4 gestures rework




commit d0770c9c0e59241e24649897199bd47c2983a3da
Author: Marinus Schraal <mschraal gnome org>
Date:   Sun Apr 11 14:13:43 2021 +0200

    GTK4 gestures rework

 data/ui/AlbumsView.ui                 | 13 +++++++------
 data/ui/LastfmDialog.ui               |  9 +++++----
 data/ui/PlaylistsWidget.ui            | 12 ++++++------
 data/ui/SongsView.ui                  | 11 ++++++-----
 gnomemusic/mediakeys.py               |  8 ++++----
 gnomemusic/widgets/lastfmdialog.py    |  1 -
 gnomemusic/widgets/playlistswidget.py |  1 -
 gnomemusic/widgets/smoothscale.py     |  8 ++++----
 gnomemusic/window.py                  |  8 ++++----
 9 files changed, 36 insertions(+), 35 deletions(-)
---
diff --git a/data/ui/AlbumsView.ui b/data/ui/AlbumsView.ui
index 78ad992e6..a27e51c3b 100644
--- a/data/ui/AlbumsView.ui
+++ b/data/ui/AlbumsView.ui
@@ -26,15 +26,16 @@
             <style>
               <class name="content-view"/>
             </style>
+            <child>
+              <object class="GtkGestureLongPress" id="_flowbox_long_press">
+                <property name="propagation-phase">capture</property>
+                <signal name="begin" handler="_on_flowbox_press_begin" swapped="no"/>
+                <signal name="cancel" handler="_on_flowbox_press_cancel" swapped="no"/>
+              </object>
+            </child>
           </object>
         </child>
       </object>
     </child>
   </template>
-  <object class="GtkGestureLongPress" id="_flowbox_long_press">
-    <property name="propagation-phase">capture</property>
-    <property name="widget">_flowbox</property>
-    <signal name="begin" handler="_on_flowbox_press_begin" swapped="no"/>
-    <signal name="cancel" handler="_on_flowbox_press_cancel" swapped="no"/>
-  </object>
 </interface>
diff --git a/data/ui/LastfmDialog.ui b/data/ui/LastfmDialog.ui
index 6096f608d..1ec99eac0 100644
--- a/data/ui/LastfmDialog.ui
+++ b/data/ui/LastfmDialog.ui
@@ -56,6 +56,11 @@
         </child>
         <child>
           <object class="GtkButton" id="_action_button">
+            <child>
+              <object class="GtkGestureClick">
+                <signal name="released" handler="_on_action_button_clicked" swapped="no"/>
+              </object>
+            </child>
             <property name="halign">start</property>
             <property name="label" translatable="yes">Login</property>
             <property name="margin-bottom">8</property>
@@ -65,8 +70,4 @@
       </object>
     </child>
   </template>
-  <object class="GtkGestureMultiPress" id="_action_button_gesture">
-    <property name="widget">_action_button</property>
-    <signal name="released" handler="_on_action_button_clicked" swapped="no"/>
-  </object>
 </interface>
diff --git a/data/ui/PlaylistsWidget.ui b/data/ui/PlaylistsWidget.ui
index cbfb68d97..5d3508820 100644
--- a/data/ui/PlaylistsWidget.ui
+++ b/data/ui/PlaylistsWidget.ui
@@ -14,6 +14,12 @@
         <property name="visible">True</property>
         <child>
           <object class="GtkListBox" id="_songs_list">
+            <child>
+              <object class="GtkGestureClick">
+                <property name="button">3</property>
+                <signal name="pressed" handler="_songs_list_right_click" swapped="no"/>
+              </object>
+            </child>
             <property name="margin-bottom">20</property>
             <property name="margin-end">80</property>
             <property name="margin-start">80</property>
@@ -28,10 +34,4 @@
       </object>
     </child>
   </template>
-  <object class="GtkGestureMultiPress" id="_songs_list_ctrlr">
-    <property name="widget">_songs_list</property>
-    <property name="propagation-phase">capture</property>
-    <property name="button">3</property>
-    <signal name="pressed" handler="_songs_list_right_click" swapped="no"/>
-  </object>
 </interface>
diff --git a/data/ui/SongsView.ui b/data/ui/SongsView.ui
index 223df3758..433243d02 100644
--- a/data/ui/SongsView.ui
+++ b/data/ui/SongsView.ui
@@ -15,6 +15,12 @@
         <style>
           <class name="songs-list-old"/>
         </style>
+        <child>
+          <object class="GtkGestureClick" id="_songs_ctrlr">
+            <property name="propagation-phase">capture</property>
+            <signal name="released" handler="_on_view_clicked" swapped="no"/>
+          </object>
+        </child>
         <child internal-child="selection">
           <object class="GtkTreeSelection">
             <property name="mode">single</property>
@@ -115,9 +121,4 @@
       </object>
     </child>
   </template>
-  <object class="GtkGestureMultiPress" id="_songs_ctrlr">
-    <property name="widget">_songs_view</property>
-    <property name="propagation-phase">capture</property>
-    <signal name="released" handler="_on_view_clicked" swapped="no"/>
-  </object>
 </interface>
diff --git a/gnomemusic/mediakeys.py b/gnomemusic/mediakeys.py
index f0ba16236..a88f6384e 100644
--- a/gnomemusic/mediakeys.py
+++ b/gnomemusic/mediakeys.py
@@ -74,11 +74,11 @@ class MediaKeys(GObject.GObject):
 
         self._media_keys_proxy.connect("g-signal", self._handle_media_keys)
 
-        self._ctrlr = Gtk.EventControllerKey().new(self._window)
-        self._ctrlr.props.propagation_phase = Gtk.PropagationPhase.CAPTURE
-        self._ctrlr.connect("focus-in", self._grab_media_player_keys)
+        ctrl = Gtk.EventControllerKey()
+        ctrl.connect("focus-in", self._grab_media_player_keys)
+        self._window.add_controller(ctrl)
 
-    def _grab_media_player_keys(self, controllerkey=None):
+    def _grab_media_player_keys(self, controller, mode, detail):
         def proxy_call_finished(proxy, result, data=None):
             try:
                 proxy.call_finish(result)
diff --git a/gnomemusic/widgets/lastfmdialog.py b/gnomemusic/widgets/lastfmdialog.py
index 5ba226563..1cf32cf11 100644
--- a/gnomemusic/widgets/lastfmdialog.py
+++ b/gnomemusic/widgets/lastfmdialog.py
@@ -36,7 +36,6 @@ class LastfmDialog(Gtk.Dialog):
     __gtype_name__ = "LastfmDialog"
 
     _action_button = Gtk.Template.Child()
-    _action_button_gesture = Gtk.Template.Child()
     _action_label = Gtk.Template.Child()
     _status_label = Gtk.Template.Child()
 
diff --git a/gnomemusic/widgets/playlistswidget.py b/gnomemusic/widgets/playlistswidget.py
index 00f9fbcd2..ddc4e4820 100644
--- a/gnomemusic/widgets/playlistswidget.py
+++ b/gnomemusic/widgets/playlistswidget.py
@@ -39,7 +39,6 @@ class PlaylistsWidget(Gtk.Box):
 
     _pl_ctrls = Gtk.Template.Child()
     _songs_list = Gtk.Template.Child()
-    _songs_list_ctrlr = Gtk.Template.Child()
 
     def __init__(self, application, playlists_view):
         """Initialize the PlaylistsWidget.
diff --git a/gnomemusic/widgets/smoothscale.py b/gnomemusic/widgets/smoothscale.py
index d1f6d3f9d..51e977174 100644
--- a/gnomemusic/widgets/smoothscale.py
+++ b/gnomemusic/widgets/smoothscale.py
@@ -46,10 +46,10 @@ class SmoothScale(Gtk.Scale):
 
         self._timeout = None
 
-        self._controller = Gtk.GestureMultiPress().new(self)
-        self._controller.props.propagation_phase = Gtk.PropagationPhase.CAPTURE
-        self._controller.connect("pressed", self._on_button_pressed)
-        self._controller.connect("released", self._on_button_released)
+        ctrl = Gtk.GestureClick()
+        ctrl.connect("pressed", self._on_button_pressed)
+        ctrl.connect("released", self._on_button_released)
+        self.add_controller(ctrl)
 
         self.connect('change-value', self._on_smooth_scale_seek)
 
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index b4ca3676d..8c1db5a3f 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -230,11 +230,11 @@ class Window(Gtk.ApplicationWindow):
             'notify::visible-child', self._on_notify_mode)
         self.connect('destroy', self._notify_mode_disconnect)
 
-        self._btn_ctrl = Gtk.GestureMultiPress().new(self)
-        self._btn_ctrl.props.propagation_phase = Gtk.PropagationPhase.CAPTURE
+        ctrl = Gtk.GestureClick().new()
         # Mouse button 8 is the back button.
-        self._btn_ctrl.props.button = 8
-        self._btn_ctrl.connect("pressed", self._on_back_button_pressed)
+        ctrl.props.button = 8
+        ctrl.connect("pressed", self._on_back_button_pressed)
+        self.add_controller(ctrl)
 
         self.views[View.EMPTY].props.state = EmptyView.State.SEARCH
 


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