[geary] Handle window maximization in separate callback



commit e2b1cfb12fca86c46c9016261ea479aac9ca589c
Author: Jakob Unterwurzacher <jakobunt gmail com>
Date:   Fri Mar 21 23:19:58 2014 +0100

    Handle window maximization in separate callback
    
    The old code queried the maximized state from within the window
    resize callback configure_event, getting a stale value sometimes
    ( https://bugzilla.gnome.org/show_bug.cgi?id=724951 ).
    
    The correct approach is having a separate
    window_state_event callback to handle maximization.
    
    Test case for Geary main window:
    1) Maximize
    2) Unmaximize
    3) Close
    4) Re-Open
    Before patch: Opens maximized
    After patch:  Opens unmaximized
    (Or just watch the output of "dconf watch /org/yorba/geary/")

 src/client/components/main-window.vala |   40 +++++++++++++++++--------------
 1 files changed, 22 insertions(+), 18 deletions(-)
---
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index 31fdc14..b42162b 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -92,28 +92,32 @@ public class MainWindow : Gtk.ApplicationWindow {
         
         return true;
     }
-    
+
+    // Fired on window resize, window move and possibly other events
+    // We want to save the window size for the next start
     public override bool configure_event(Gdk.EventConfigure event) {
-        // Get window state and dimensions.
-        // Note: A window move triggers this event with no changed values.
-        bool maximized = ((get_window().get_state() & Gdk.WindowState.MAXIMIZED) != 0);
-        // Writing the window_* variables triggers a dconf database update. Only write if
-        // the value has changed.
+
+        // Writing the window_* variables triggers a dconf database update.
+        // Only write if the value has changed.
+        if(window_width != event.width)
+            window_width = event.width;
+        if(window_height != event.height)
+            window_height = event.height;
+
+        return base.configure_event(event);
+    }
+
+    // Fired on [un]maximize and possibly other events
+    // We want to save the maximized state for the next start
+    public override bool window_state_event(Gdk.EventWindowState event) {
+        bool maximized = ((event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0);
+
+        // Writing the window_* variables triggers a dconf database update.
+        // Only write if the value has changed.
         if(window_maximized != maximized)
             window_maximized = maximized;
 
-        if (!maximized) {
-            // can't use properties as out variables
-            int width, height;
-            get_size(out width, out height);
-            
-            if(window_width != width)
-                window_width = width;
-            if(window_height != height)
-                window_height = height;
-        }
-        
-        return base.configure_event(event);
+        return base.window_state_event(event);
     }
     
     private void create_layout() {


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