[evolution] Clamp GSettings values before restoring window size



commit 4f2724115c945215404394f8ed3fbd65862fa84f
Author: Milan Crha <mcrha redhat com>
Date:   Mon Dec 10 11:06:35 2018 +0100

    Clamp GSettings values before restoring window size
    
    The GSettings values can be changed by anything, which means the user
    can override the last stored window size to some large enough that
    the gdk (or WebKitGTK+) will fail to allocated such large pixmap,
    which can lead to a crash. This size clamp helps to avoid it.
    
    Related to downstream bug:
    https://bugzilla.redhat.com/show_bug.cgi?id=1657361

 src/e-util/e-misc-utils.c | 45 ++++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)
---
diff --git a/src/e-util/e-misc-utils.c b/src/e-util/e-misc-utils.c
index afb6fa8616..b6a280b3d7 100644
--- a/src/e-util/e-misc-utils.c
+++ b/src/e-util/e-misc-utils.c
@@ -397,38 +397,45 @@ e_restore_window (GtkWindow *window,
        data->flags = flags;
 
        if (flags & E_RESTORE_WINDOW_SIZE) {
-               gint width, height;
+               GdkScreen *screen;
+               GdkRectangle monitor_area;
+               gint x, y, width, height, monitor;
+
+               x = g_settings_get_int (settings, "x");
+               y = g_settings_get_int (settings, "y");
+
+               screen = gtk_window_get_screen (window);
+               monitor = gdk_screen_get_monitor_at_point (screen, x, y);
+               if (monitor < 0)
+                       monitor = 0;
+
+               if (monitor >= gdk_screen_get_n_monitors (screen))
+                       monitor = 0;
+
+               gdk_screen_get_monitor_workarea (
+                       screen, monitor, &monitor_area);
 
                width = g_settings_get_int (settings, "width");
                height = g_settings_get_int (settings, "height");
 
+               /* Clamp the GSettings value to actual monitor area before restoring the size */
+               if (width > 0 && height > 0) {
+                       if (width > 1.5 * monitor_area.width)
+                               width = 1.5 * monitor_area.width;
+
+                       if (height > 1.5 * monitor_area.height)
+                               height = 1.5 * monitor_area.height;
+               }
+
                if (width > 0 && height > 0)
                        gtk_window_resize (window, width, height);
 
                if (g_settings_get_boolean (settings, "maximized")) {
-                       GdkScreen *screen;
-                       GdkRectangle monitor_area;
-                       gint x, y, monitor;
-
-                       x = g_settings_get_int (settings, "x");
-                       y = g_settings_get_int (settings, "y");
-
-                       screen = gtk_window_get_screen (window);
                        gtk_window_get_size (window, &width, &height);
 
                        data->premax_width = width;
                        data->premax_height = height;
 
-                       monitor = gdk_screen_get_monitor_at_point (screen, x, y);
-                       if (monitor < 0)
-                               monitor = 0;
-
-                       if (monitor >= gdk_screen_get_n_monitors (screen))
-                               monitor = 0;
-
-                       gdk_screen_get_monitor_workarea (
-                               screen, monitor, &monitor_area);
-
                        gtk_window_resize (
                                window,
                                monitor_area.width,


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