[devhelp] Do not save/restore GtkWindows x/y positions



commit 4007888a43229df952c3e86f3fd21a0d5433e3bd
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Dec 15 06:20:34 2017 +0100

    Do not save/restore GtkWindows x/y positions
    
    See: https://bugzilla.gnome.org/show_bug.cgi?id=786008#c5
    
    "Given that the window manager might want to place you in a different
    spot on launch, and that this isn't even in the application's control on
    Wayland, I'd make this as simple as possible"

 data/devhelp.convert               |    4 --
 data/org.gnome.devhelp.gschema.xml |   20 ------------
 src/dh-util.c                      |   61 ++++++++++++-----------------------
 3 files changed, 21 insertions(+), 64 deletions(-)
---
diff --git a/data/devhelp.convert b/data/devhelp.convert
index 3b0a721..dd47f6b 100644
--- a/data/devhelp.convert
+++ b/data/devhelp.convert
@@ -2,15 +2,11 @@
 maximized=/apps/devhelp/state/main/window/maximized
 width=/apps/devhelp/state/main/window/width
 height=/apps/devhelp/state/main/window/height
-x-position=/apps/devhelp/state/main/window/x_position
-y-position=/apps/devhelp/state/main/window/y_position
 
 [org.gnome.devhelp.state.assistant.window]
 maximized=/apps/devhelp/state/assistant/window/maximized
 width=/apps/devhelp/state/assistant/window/width
 height=/apps/devhelp/state/assistant/window/height
-x-position=/apps/devhelp/state/assistant/window/x_position
-y-position=/apps/devhelp/state/assistant/window/y_position
 
 [org.gnome.devhelp.state.main.paned]
 position=/apps/devhelp/state/main/paned/position
diff --git a/data/org.gnome.devhelp.gschema.xml b/data/org.gnome.devhelp.gschema.xml
index 2f69201..399e2bc 100644
--- a/data/org.gnome.devhelp.gschema.xml
+++ b/data/org.gnome.devhelp.gschema.xml
@@ -28,16 +28,6 @@
       <summary>Height of main window</summary>
       <description>The height of the main window.</description>
     </key>
-    <key name="x-position" type="i">
-      <default>100</default>
-      <summary>X position of main window</summary>
-      <description>The X position of the main window.</description>
-    </key>
-    <key name="y-position" type="i">
-      <default>100</default>
-      <summary>Y position of main window</summary>
-      <description>The Y position of the main window.</description>
-    </key>
   </schema>
   <schema id="org.gnome.devhelp.state.main.paned" path="/org/gnome/devhelp/state/main/paned/">
     <key name="position" type="i">
@@ -77,16 +67,6 @@
       <summary>Height of assistant window</summary>
       <description>The height of the assistant window.</description>
     </key>
-    <key name="x-position" type="i">
-      <default>0</default>
-      <summary>X position of assistant window</summary>
-      <description>The X position of the assistant window.</description>
-    </key>
-    <key name="y-position" type="i">
-      <default>0</default>
-      <summary>Y position of assistant window</summary>
-      <description>The Y position of the assistant window.</description>
-    </key>
   </schema>
   <schema id="org.gnome.devhelp.fonts" path="/org/gnome/devhelp/fonts/">
     <key name="use-system-fonts" type="b">
diff --git a/src/dh-util.c b/src/dh-util.c
index 81860db..24e217c 100644
--- a/src/dh-util.c
+++ b/src/dh-util.c
@@ -139,58 +139,49 @@ dh_util_view_set_font (WebKitWebView *view, const gchar *font_name_fixed, const
 }
 
 void
-dh_util_window_settings_save (GtkWindow *window, GSettings *settings, gboolean has_maximize)
+dh_util_window_settings_save (GtkWindow *window,
+                              GSettings *settings,
+                              gboolean   has_maximize)
 {
-        GdkWindowState  state;
-        gboolean        maximized;
-        gint            width, height;
-        gint            x, y;
-
+        gint width;
+        gint height;
 
         if (has_maximize) {
+                GdkWindowState state;
+                gboolean maximized;
+
                 state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
-                if (state & GDK_WINDOW_STATE_MAXIMIZED) {
-                        maximized = TRUE;
-                } else {
-                        maximized = FALSE;
-                }
+                maximized = (state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
 
                 g_settings_set_boolean (settings, "maximized", maximized);
 
-                /* If maximized don't save the size and position. */
-                if (maximized) {
+                /* If maximized don't save the size. */
+                if (maximized)
                         return;
-                }
         }
 
-        /* store the dimensions */
+        /* Store the dimensions */
         gtk_window_get_size (GTK_WINDOW (window), &width, &height);
         g_settings_set_int (settings, "width", width);
         g_settings_set_int (settings, "height", height);
-
-        /* store the position */
-        gtk_window_get_position (GTK_WINDOW (window), &x, &y);
-        g_settings_set_int (settings, "x-position", x);
-        g_settings_set_int (settings, "y-position", y);
 }
 
 void
 dh_util_window_settings_restore (GtkWindow *window,
                                  GSettings *settings,
-                                 gboolean has_maximize)
+                                 gboolean   has_maximize)
 {
-        gboolean   maximized;
-        gint       width, height;
-        gint       x, y;
-        GdkScreen *screen;
-        gint       max_width, max_height;
+        gint width;
+        gint height;
 
         width = g_settings_get_int (settings, "width");
         height = g_settings_get_int (settings, "height");
-        x = g_settings_get_int (settings, "x-position");
-        y = g_settings_get_int (settings, "y-position");
 
         if (width > 1 && height > 1) {
+                GdkScreen *screen;
+                gint max_width;
+                gint max_height;
+
                 screen = gtk_widget_get_screen (GTK_WIDGET (window));
                 max_width = gdk_screen_get_width (screen);
                 max_height = gdk_screen_get_height (screen);
@@ -198,21 +189,11 @@ dh_util_window_settings_restore (GtkWindow *window,
                 width = CLAMP (width, 0, max_width);
                 height = CLAMP (height, 0, max_height);
 
-                x = CLAMP (x, 0, max_width - width);
-                y = CLAMP (y, 0, max_height - height);
-
                 gtk_window_set_default_size (window, width, height);
         }
 
-        gtk_window_move (window, x, y);
-
-        if (has_maximize) {
-                maximized = g_settings_get_boolean (settings, "maximized");
-
-                if (maximized) {
-                        gtk_window_maximize (window);
-                }
-        }
+        if (has_maximize && g_settings_get_boolean (settings, "maximized"))
+                gtk_window_maximize (window);
 }
 
 /* Adds q2 onto the end of q1, and frees q2. */


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