[gnome-tetravex] Use Back and Forward mouse buttons.



commit f0001e350f25e2c9b5817cd60272580fe23cf376
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Sep 21 02:40:37 2019 +0200

    Use Back and Forward mouse buttons.
    
    Easily undo and redo. Also,
    allow selecting tiles using
    the (usually) right button.

 data/org.gnome.Tetravex.gschema.xml | 23 +++++++++++++++++++++++
 src/gnome-tetravex.vala             |  9 +++++++++
 src/puzzle-view.vala                | 17 ++++++++++++++++-
 3 files changed, 48 insertions(+), 1 deletion(-)
---
diff --git a/data/org.gnome.Tetravex.gschema.xml b/data/org.gnome.Tetravex.gschema.xml
index 4730290..b7138af 100644
--- a/data/org.gnome.Tetravex.gschema.xml
+++ b/data/org.gnome.Tetravex.gschema.xml
@@ -8,6 +8,29 @@
       <!-- Translators: summary of a settings key, see 'dconf-editor /org/gnome/Tetravex/grid-size' -->
       <description>The value of this key is used to decide the size of the playing grid.</description>
     </key>
+    <key type="b" name="mouse-use-extra-buttons">
+      <default>true</default>
+      <!-- Translators: summary of a settings key, see 'dconf-editor 
/org/gnome/Tetravex/mouse-use-extra-buttons' -->
+      <summary>Use “Back” and “Forward” mouse button events</summary>
+      <!-- Translators: description of a settings key, see 'dconf-editor 
/org/gnome/Tetravex/mouse-use-extra-buttons' -->
+      <description>For users which have a mouse with “Forward” and “Back” buttons, this key will determine 
if any action is taken inside of the window when either is pressed.</description>
+    </key>
+    <key type="i" name="mouse-back-button">
+      <default>8</default>
+      <range min="6" max="14"/>
+      <!-- Translators: summary of a settings key, see 'dconf-editor /org/gnome/Tetravex/mouse-back-buttons' 
-->
+      <summary>Mouse button to activate the “Undo” command</summary>
+      <!-- Translators: description of a settings key, see 'dconf-editor 
/org/gnome/Tetravex/mouse-back-buttons' -->
+      <description>For users which have a mouse with “Forward” and “Back” buttons, this key will set which 
button activates the “Undo” command. Possible values range between 6 and 14.</description>
+    </key>
+    <key type="i" name="mouse-forward-button">
+      <default>9</default>
+      <range min="6" max="14"/>
+      <!-- Translators: summary of a settings key, see 'dconf-editor 
/org/gnome/Tetravex/mouse-forward-buttons' -->
+      <summary>Mouse button to activate the “Redo” command</summary>
+      <!-- Translators: description of a settings key, see 'dconf-editor 
/org/gnome/Tetravex/mouse-forward-buttons' -->
+      <description>For users which have a mouse with “Forward” and “Back” buttons, this key will set which 
button activates the “Redo” command. Possible values range between 6 and 14.</description>
+    </key>
     <key name="window-width" type="i">
       <default>600</default>
       <!-- Translators: summary of a settings key, see 'dconf-editor /org/gnome/Tetravex/window-width' -->
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index aba6253..e9a45c2 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -174,6 +174,13 @@ private class Tetravex : Gtk.Application
         view.button_release_event.connect (view_button_release_event);
         grid.attach (view, 0, 0, 3, 1);
 
+        settings.bind ("mouse-use-extra-buttons",   view,
+                       "mouse-use-extra-buttons",   SettingsBindFlags.GET | 
SettingsBindFlags.NO_SENSITIVITY);
+        settings.bind ("mouse-back-button",         view,
+                       "mouse-back-button",         SettingsBindFlags.GET | 
SettingsBindFlags.NO_SENSITIVITY);
+        settings.bind ("mouse-forward-button",      view,
+                       "mouse-forward-button",      SettingsBindFlags.GET | 
SettingsBindFlags.NO_SENSITIVITY);
+
         SizeGroup sizegroup = new SizeGroup (SizeGroupMode.BOTH);
 
         Button play_button      = new BottomButton ("media-playback-start-symbolic",
@@ -305,9 +312,11 @@ private class Tetravex : Gtk.Application
         base.shutdown ();
 
         /* Save window state */
+        settings.delay ();
         settings.set_int ("window-width", window_width);
         settings.set_int ("window-height", window_height);
         settings.set_boolean ("window-is-maximized", is_maximized);
+        settings.apply ();
     }
 
     protected override int handle_local_options (GLib.VariantDict options)
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index 264e1a1..dabefbb 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -489,14 +489,29 @@ private class PuzzleView : Gtk.DrawingArea
         assert_not_reached ();
     }
 
+    [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; }
+
     protected override bool button_press_event (Gdk.EventButton event)
     {
         if (puzzle.paused || puzzle.is_solved)
             return false;
 
-        if (event.button != 1)
+        if (event.button == 1 || event.button == 3)
+            return main_button_pressed (event);
+
+        if (!mouse_use_extra_buttons)
             return false;
+        if (event.button == mouse_back_button)
+            undo ();
+        else if (event.button == mouse_forward_button)
+            redo ();
+        return false;
+    }
 
+    private inline bool main_button_pressed (Gdk.EventButton event)
+    {
         if (event.type == Gdk.EventType.BUTTON_PRESS)
         {
             if (selected_tile == null)


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