[gnome-tetravex/arnaudb/wip/gtk4: 22/49] Adapt event stuff.




commit b2c21726f8fae4a99d33bf3b546c6473556e9f5e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Feb 20 21:46:31 2020 +0100

    Adapt event stuff.

 src/gnome-tetravex.vala | 17 ++++++++++-------
 src/puzzle-view.vala    | 29 +++++++++++++----------------
 2 files changed, 23 insertions(+), 23 deletions(-)
---
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index 37a97ad..810047e 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -306,8 +306,9 @@ private class Tetravex : Gtk.Application
 
         window = (ApplicationWindow) builder.get_object ("gnome-tetravex-window");
         this.add_window (window);
-        key_controller = new EventControllerKey (window);
+        key_controller = new EventControllerKey ();
         key_controller.key_pressed.connect (on_key_pressed);
+        ((Widget) window).add_controller (key_controller);
         window.size_allocate.connect (size_allocate_cb);
         window.window_state_event.connect (window_state_event_cb);
         window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
@@ -383,9 +384,10 @@ private class Tetravex : Gtk.Application
         view.vexpand = true;
         view.can_focus = true;
         view.show ();
-        view_click_controller = new GestureMultiPress (view);
+        view_click_controller = new GestureClick ();
         view_click_controller.set_button (/* all buttons */ 0);
         view_click_controller.released.connect (on_release_on_view);
+        view.add_controller (view_click_controller);
         settings.bind ("theme", view, "theme-id", SettingsBindFlags.GET | SettingsBindFlags.NO_SENSITIVITY);
 
         Overlay overlay = new Overlay ();
@@ -454,8 +456,9 @@ private class Tetravex : Gtk.Application
                                                     /* align end */ true,
                                                     sizegroup);
 
-        new_game_button_click_controller = new GestureMultiPress (new_game_button);
+        new_game_button_click_controller = new GestureClick ();
         new_game_button_click_controller.pressed.connect (on_new_game_button_click);
+        new_game_button.add_controller (new_game_button_click_controller);
         new_game_solve_stack = new Stack ();
         new_game_solve_stack.add_named (solve_button, "solve");
         new_game_solve_stack.add_named (new_game_button, "new-game");
@@ -962,14 +965,14 @@ private class Tetravex : Gtk.Application
         return false;
     }
 
-    private GestureMultiPress new_game_button_click_controller;
-    private inline void on_new_game_button_click (GestureMultiPress _new_game_button_click_controller, int 
n_press, double event_x, double event_y)
+    private GestureClick new_game_button_click_controller;
+    private inline void on_new_game_button_click (GestureClick _new_game_button_click_controller, int 
n_press, double event_x, double event_y)
     {
         view.disable_highlight ();
     }
 
-    private GestureMultiPress view_click_controller;
-    private inline void on_release_on_view (GestureMultiPress _view_click_controller, int n_press, double 
event_x, double event_y)
+    private GestureClick view_click_controller;
+    private inline void on_release_on_view (GestureClick _view_click_controller, int n_press, double 
event_x, double event_y)
     {
         /* Cancel pause on click */
         if (puzzle.paused)
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index 7592ee8..46ff3c8 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -677,26 +677,28 @@ private class PuzzleView : Gtk.DrawingArea
     \*/
 
     private Gtk.EventControllerMotion motion_controller;    // for keeping in memory
-    private Gtk.GestureMultiPress click_controller;         // for keeping in memory
+    private Gtk.GestureClick click_controller;              // for keeping in memory
 
     private void init_mouse ()  // called on construct
     {
-        motion_controller = new Gtk.EventControllerMotion (this);
+        motion_controller = new Gtk.EventControllerMotion ();
         motion_controller.motion.connect (on_motion);
-//        motion_controller.enter.connect (on_mouse_in);                        // FIXME should work, 1/8
-//        motion_controller.leave.connect (on_mouse_out);                       // FIXME should work, 2/8
+        motion_controller.enter.connect (on_mouse_in);
+        motion_controller.leave.connect (on_mouse_out);
+        add_controller (motion_controller);
 
-        click_controller = new Gtk.GestureMultiPress (this);
+        click_controller = new Gtk.GestureClick ();
         click_controller.set_button (/* all buttons */ 0);
         click_controller.pressed.connect (on_click);
         click_controller.released.connect (on_release);
+        add_controller (click_controller);
     }
 
     [CCode (notify = false)] internal bool mouse_use_extra_buttons  { private get; internal set; default = 
true; }
     [CCode (notify = false)] internal int  mouse_back_button        { private get; internal set; default = 
8; }
     [CCode (notify = false)] internal int  mouse_forward_button     { private get; internal set; default = 
9; }
 
-    private inline void on_click (Gtk.GestureMultiPress _click_controller, int n_press, double event_x, 
double event_y)
+    private inline void on_click (Gtk.GestureClick _click_controller, int n_press, double event_x, double 
event_y)
     {
         if (puzzle.paused || puzzle.is_solved)
             return;
@@ -770,7 +772,7 @@ private class PuzzleView : Gtk.DrawingArea
         }
     }
 
-    private inline void on_release (Gtk.GestureMultiPress _click_controller, int n_press, double event_x, 
double event_y)
+    private inline void on_release (Gtk.GestureClick _click_controller, int n_press, double event_x, double 
event_y)
     {
         if (puzzle.paused || puzzle.is_solved)
             return;
@@ -803,25 +805,19 @@ private class PuzzleView : Gtk.DrawingArea
         }
     }
 
-//    private inline void on_mouse_out (Gtk.EventControllerMotion _motion_controller)   // FIXME should 
work, 3/8
-    protected override bool leave_notify_event (Gdk.EventCrossing event)                // FIXME should 
work, 4/8
+    private inline void on_mouse_out ()
     {
         if (selected_tile != null)
             ((!) selected_tile).snap_to_cursor = false;
-
-        return false;                                                                   // FIXME should 
work, 5/8
     }
 
-//    private inline void on_mouse_in (Gtk.EventControllerMotion _motion_controller, double event_x, double 
event_y)    // FIXME should work, 6/8
-    protected override bool enter_notify_event (Gdk.EventCrossing event)                                     
           // FIXME should work, 7/8
+    private inline void on_mouse_in ()
     {
         if (selected_tile != null)
         {
             ((!) selected_tile).snap_to_cursor = false;
             ((!) selected_tile).duration = half_animation_duration;
         }
-
-        return false;                                                                   // FIXME should 
work, 8/8
     }
 
     internal void finish ()
@@ -923,8 +919,9 @@ private class PuzzleView : Gtk.DrawingArea
 
     private void init_keyboard ()  // called on construct
     {
-        key_controller = new Gtk.EventControllerKey (this);
+        key_controller = new Gtk.EventControllerKey ();
         key_controller.key_pressed.connect (on_key_pressed);
+        add_controller (key_controller);
     }
 
     private inline bool on_key_pressed (Gtk.EventControllerKey _key_controller, uint keyval, uint keycode, 
Gdk.ModifierType state)


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