[gnome-sudoku] Make earmark popup open on long press



commit 9cba07b686fcf8d08327891b73ea7e3bff8db99e
Author: Abbe98 <albin post gmail com>
Date:   Sat Sep 24 16:18:44 2022 +0200

    Make earmark popup open on long press
    
    This makes earmarks accessible on touch-only devices.
    
    Fixes #7

 src/sudoku-view.vala | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
---
diff --git a/src/sudoku-view.vala b/src/sudoku-view.vala
index 656e81b..b773bdc 100644
--- a/src/sudoku-view.vala
+++ b/src/sudoku-view.vala
@@ -40,6 +40,8 @@ private class SudokuCellView : DrawingArea
     private bool left_control;
     private bool right_control;
 
+    public Gtk.GestureLongPress long_press;
+
     public int value
     {
         get { return game.board [row, col]; }
@@ -162,6 +164,14 @@ private class SudokuCellView : DrawingArea
         return false;
     }
 
+    public void long_press_event ()
+    {
+        if (game.mode == GameMode.PLAY && (is_fixed || game.paused))
+            return;
+
+        show_earmark_picker ();
+    }
+
     private void create_earmark_picker ()
     {
         earmark_picker = new NumberPicker (ref game.board, true);
@@ -694,6 +704,12 @@ public class SudokuView : AspectFrame
                     return false;
                 });
 
+                cell.long_press = new Gtk.GestureLongPress (cell);
+                cell.long_press.set_propagation_phase (Gtk.PropagationPhase.TARGET);
+                cell.long_press.pressed.connect (() => {
+                    cell.long_press_event ();
+                });
+
                 cell.notify["value"].connect ((s, p)=> {
                     if (_show_possibilities || _show_warnings || game.board.broken || 
previous_board_broken_state)
                         previous_board_broken_state = game.board.broken;


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