[gnome-chess] Do not hammer dconf on resize.



commit 911113cde87e81c32cc5936deda2b60cdf4cbddf
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Feb 24 21:01:24 2015 +0100

    Do not hammer dconf on resize.

 data/gnome-chess.ui  |    2 -
 src/gnome-chess.vala |   54 +++++++++++++++++++++++++++----------------------
 2 files changed, 30 insertions(+), 26 deletions(-)
---
diff --git a/data/gnome-chess.ui b/data/gnome-chess.ui
index e2be90a..1d7a5a0 100644
--- a/data/gnome-chess.ui
+++ b/data/gnome-chess.ui
@@ -12,9 +12,7 @@
   <object class="GtkApplicationWindow" id="gnome_chess_app">
     <property name="can_focus">False</property>
     <property name="default_width">700</property>
-    <signal name="configure-event" handler="gnome_chess_app_configure_event_cb" swapped="no"/>
     <signal name="delete-event" handler="gnome_chess_app_delete_event_cb" swapped="no"/>
-    <signal name="window-state-event" handler="gnome_chess_app_window_state_event_cb" swapped="no"/>
     <child type="titlebar">
       <object class="GtkHeaderBar" id="headerbar">
         <property name="visible">True</property>
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 134d8d3..888bd80 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -12,6 +12,11 @@
 
 public class ChessApplication : Gtk.Application
 {
+    private bool is_tiled;
+    private bool is_maximized;
+    private int window_width;
+    private int window_height;
+
     private Settings settings;
     private Gtk.Builder builder;
     private Gtk.Builder preferences_builder;
@@ -151,6 +156,8 @@ public class ChessApplication : Gtk.Application
         window.set_default_size (settings.get_int ("width"), settings.get_int ("height"));
         if (settings.get_boolean ("maximized"))
             window.maximize ();
+        window.size_allocate.connect (size_allocate_cb);
+        window.window_state_event.connect (window_state_event_cb);
 
         pause_resume_button = (Gtk.Button) builder.get_object ("pause_button");
         first_move_button = (Gtk.Widget) builder.get_object ("first_move_button");
@@ -258,6 +265,29 @@ public class ChessApplication : Gtk.Application
             opponent_engine.stop ();
 
         base.shutdown ();
+
+        /* Save window state */
+        settings.set_int ("width", window_width);
+        settings.set_int ("height", window_height);
+        settings.set_boolean ("maximized", is_maximized);
+    }
+
+    private void size_allocate_cb (Gtk.Allocation allocation)
+    {
+        if (is_maximized || is_tiled)
+            return;
+        window_width = allocation.width;
+        window_height = allocation.height;
+    }
+
+    private bool window_state_event_cb (Gdk.EventWindowState event)
+    {
+        if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
+            is_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0;
+        /* We don’t save this state, but track it for saving size allocation */
+        if ((event.changed_mask & Gdk.WindowState.TILED) != 0)
+            is_tiled = (event.new_window_state & Gdk.WindowState.TILED) != 0;
+        return false;
     }
 
     public PieceType? show_promotion_type_selector ()
@@ -1326,30 +1356,6 @@ public class ChessApplication : Gtk.Application
         return false;
     }
 
-    [CCode (cname = "G_MODULE_EXPORT gnome_chess_app_configure_event_cb", instance_pos = -1)]
-    public bool gnome_chess_app_configure_event_cb (Gtk.Widget widget, Gdk.EventConfigure event)
-    {
-        if (!settings.get_boolean ("maximized"))
-        {
-            settings.set_int ("width", event.width);
-            settings.set_int ("height", event.height);
-        }
-
-        return false;
-    }
-
-    [CCode (cname = "G_MODULE_EXPORT gnome_chess_app_window_state_event_cb", instance_pos = -1)]
-    public bool gnome_chess_app_window_state_event_cb (Gtk.Widget widget, Gdk.EventWindowState event)
-    {
-        if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
-        {
-            var is_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0;
-            settings.set_boolean ("maximized", is_maximized);
-        }
-
-        return false;
-    }
-
     private bool prompt_save_game (string prompt_text)
     {
         if (!game_needs_saving)


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