[four-in-a-row/arnaudb/wip/gtk4: 11/42] Use GestureClick.



commit 0e31d041b5e6cfe6bc21076d93d09d80ff638018
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Apr 19 19:38:29 2020 +0200

    Use GestureClick.
    
    And other EventController things.

 src/four-in-a-row.vala   | 12 +++++++-----
 src/game-board-view.vala | 29 ++++++++++++++++++-----------
 2 files changed, 25 insertions(+), 16 deletions(-)
---
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index dcfd7ce..d4f68f6 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -1018,12 +1018,14 @@ private class FourInARow : Gtk.Application
 
     private inline void init_keyboard ()
     {
-        window_key_controller = new EventControllerKey (window);
+        window_key_controller = new EventControllerKey ();
         window_key_controller.set_propagation_phase (PropagationPhase.CAPTURE);
         window_key_controller.key_pressed.connect (on_window_key_pressed);
+        ((Widget) window).add_controller (window_key_controller);
 
-        board_key_controller = new EventControllerKey (game_board_view);
+        board_key_controller = new EventControllerKey ();
         board_key_controller.key_pressed.connect (on_board_key_pressed);
+        game_board_view.add_controller (board_key_controller);
     }
 
     private inline bool on_window_key_pressed (EventControllerKey _window_key_controller, uint keyval, uint 
keycode, Gdk.ModifierType state)
@@ -1059,10 +1061,10 @@ private class FourInARow : Gtk.Application
 
     private inline bool on_board_key_pressed (EventControllerKey _board_key_controller, uint keyval, uint 
keycode, Gdk.ModifierType state)
     {
-        Gdk.Event? event = Gtk.get_current_event ();
+        Gdk.Event? event = _board_key_controller.get_current_event ();
         bool is_modifier;
-        if (event != null && ((!) event).type == Gdk.EventType.KEY_PRESS)
-            is_modifier = ((Gdk.EventKey) (!) event).is_modifier == 1;
+        if (event != null && ((!) event) is Gdk.KeyEvent)
+            is_modifier = ((Gdk.KeyEvent) (!) event).is_modifier ();
         else    // ?
             is_modifier = false;
 
diff --git a/src/game-board-view.vala b/src/game-board-view.vala
index f16307c..6b592a0 100644
--- a/src/game-board-view.vala
+++ b/src/game-board-view.vala
@@ -213,13 +213,14 @@ private class GameBoardView : Gtk.DrawingArea
     * * mouse play
     \*/
 
-    private Gtk.GestureMultiPress click_controller;     // for keeping in memory
+    private Gtk.GestureClick click_controller;          // for keeping in memory
 
     private inline void init_mouse ()
     {
-        click_controller = new Gtk.GestureMultiPress (this);
+        click_controller = new Gtk.GestureClick ();
         click_controller.set_button (/* all buttons */ 0);
         click_controller.pressed.connect (on_click);
+        add_controller (click_controller);
     }
 
     /**
@@ -233,25 +234,31 @@ private class GameBoardView : Gtk.DrawingArea
      */
     internal signal bool column_clicked (uint8 column);
 
-    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)
     {
         uint button = _click_controller.get_current_button ();
         if (button != Gdk.BUTTON_PRIMARY && button != Gdk.BUTTON_SECONDARY)
             return;
 
-        Gdk.Event? event = Gtk.get_current_event ();
-        if (event == null && ((!) event).type != Gdk.EventType.BUTTON_PRESS)
+        Gdk.Event? event = _click_controller.get_current_event ();
+        if (event == null)
             assert_not_reached ();
 
-        int x;
-        int y;
-        Gdk.Window? window = get_window ();
-        if (window == null)
+        double x;
+        double y;
+        Gtk.Native? native = get_native ();
+        if (native == null)
             assert_not_reached ();
-        ((!) window).get_device_position (((Gdk.EventButton) (!) event).device, out x, out y, null);
+        Gdk.Surface? surface = ((!) native).get_surface ();
+        if (surface == null)
+            assert_not_reached ();
+        Gdk.Device? device = ((!) event).get_device ();
+        if (device == null)
+            assert_not_reached ();
+        ((!) surface).get_device_position ((!) device, out x, out y, null);
 
         uint8 col;
-        if (get_column (x, y, out col))
+        if (get_column ((int) x, (int) y, out col))
             column_clicked (col);
     }
 


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