[aisleriot] conf: Fix storing window size



commit 87b15aa3b60feac2c1acb99657a2c78a6413c461
Author: Christian Persch <chpe gnome org>
Date:   Sat Mar 5 19:15:49 2016 +0100

    conf: Fix storing window size
    
    With newer gtk+, storing the size from the configure-event makes the window
    grow on restore, since that size will include the CSD borders. Use
    size-allocate event instead and gtk_window_get_size().

 src/lib/ar-conf.c      |   29 ++++++++++++++++-------------
 src/lib/ar-gsettings.c |   26 ++++++++++++++------------
 2 files changed, 30 insertions(+), 25 deletions(-)
---
diff --git a/src/lib/ar-conf.c b/src/lib/ar-conf.c
index aa1572f..eadf914 100644
--- a/src/lib/ar-conf.c
+++ b/src/lib/ar-conf.c
@@ -134,23 +134,28 @@ free_window_state (WindowState *state)
   g_slice_free (WindowState, state);
 }
 
-static gboolean
-window_configure_event_cb (GtkWidget *widget,
-                           GdkEventConfigure *event,
-                           WindowState *state)
+static void
+window_size_allocate_cb (GtkWidget *widget,
+                         GtkAllocation *allocation,
+                         WindowState *state)
 {
+  int width, height;
+
+  gtk_window_get_size (GTK_WINDOW (widget), &width, &height);
+
+
   ar_debug_print (AR_DEBUG_WINDOW_STATE,
-                      "[window %p] configure event current %dx%d new %dx%d [state: is-maximised:%s 
is-fullscreen:%s]\n",
+                  "[window %p] size allocate %dx%d new %dx%d [state: is-maximised:%s is-fullscreen:%s]\n",
                       state->window,
                       state->width, state->height,
-                      event->width, event->height,
+                      width, height,
                       state->is_maximised ? "t" : "f",
                       state->is_fullscreen ? "t" : "f");
 
   if (!state->is_maximised && !state->is_fullscreen &&
-      (state->width != event->width || state->height != event->height)) {
-    state->width = event->width;
-    state->height = event->height;
+      (state->width != width || state->height != height)) {
+    state->width = width;
+    state->height = height;
 
   ar_debug_print (AR_DEBUG_WINDOW_STATE,
                       "[window %p] scheduling save of new window size\n",
@@ -162,8 +167,6 @@ window_configure_event_cb (GtkWidget *widget,
                                                  state);
     }
   }
-
-  return FALSE;
 }
 
 static gboolean
@@ -1284,8 +1287,8 @@ ar_conf_add_window (GtkWindow *window,
   g_object_set_data_full (G_OBJECT (window), "ArConf::WindowState",
                           state, (GDestroyNotify) free_window_state);
 
-  g_signal_connect (window, "configure-event",
-                    G_CALLBACK (window_configure_event_cb), state);
+  g_signal_connect_after (window, "size-allocate",
+                          G_CALLBACK (window_size_allocate_cb), state);
   g_signal_connect (window, "window-state-event",
                     G_CALLBACK (window_state_event_cb), state);
 
diff --git a/src/lib/ar-gsettings.c b/src/lib/ar-gsettings.c
index 8e4165a..e127818 100644
--- a/src/lib/ar-gsettings.c
+++ b/src/lib/ar-gsettings.c
@@ -57,25 +57,27 @@ free_window_state (WindowState *state)
   g_slice_free (WindowState, state);
 }
 
-static gboolean
-window_configure_event_cb (GtkWidget *widget,
-                           GdkEventConfigure *event,
-                           WindowState *state)
+static void
+window_size_allocate_cb (GtkWidget *widget,
+                         GtkAllocation *allocation,
+                         WindowState *state)
 {
+  int width, height;
+
+  gtk_window_get_size (GTK_WINDOW (widget), &width, &height);
+
   ar_debug_print (AR_DEBUG_WINDOW_STATE,
-                      "[window %p] configure event current %dx%d new %dx%d [state: is-maximised:%s 
is-fullscreen:%s]\n",
+                  "[window %p] size allocate current %dx%d new %dx%d [state: is-maximised:%s 
is-fullscreen:%s]\n",
                       state->window,
                       state->width, state->height,
-                      event->width, event->height,
+                      width, height,
                       state->is_maximised ? "t" : "f",
                       state->is_fullscreen ? "t" : "f");
 
   if (!state->is_maximised && !state->is_fullscreen) {
-    state->width = event->width;
-    state->height = event->height;
+    state->width = width;
+    state->height = height;
   }
-
-  return FALSE;
 }
 
 static gboolean
@@ -224,8 +226,8 @@ ar_gsettings_bind_window_state (const char *path,
   g_object_set_data_full (G_OBJECT (window), "GamesSettings::WindowState",
                           state, (GDestroyNotify) free_window_state);
 
-  g_signal_connect (window, "configure-event",
-                    G_CALLBACK (window_configure_event_cb), state);
+  g_signal_connect_after (window, "size-allocate",
+                          G_CALLBACK (window_size_allocate_cb), state);
   g_signal_connect (window, "window-state-event",
                     G_CALLBACK (window_state_event_cb), state);
 


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