[mutter] Don't unmaximize to nearly maximized size



commit c39998efee9489dc011e572fb3f589989ce3ecbb
Author: Adel Gadllah <adel gadllah gmail com>
Date:   Mon Mar 12 17:09:17 2012 +0100

    Don't unmaximize to nearly maximized size
    
    Basically we don't really want to create windows that are almost maximized in
    size but not actually maximized. This creates work for the user and makes it
    very difficult to use and resize manually.
    
    So set the newly unmaximized window size to the previously used size or 80% of the
    size of the current workarea (attempting to retain natural aspect ratio if
    possible), whichever is smaller.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=671677

 src/core/window.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/src/core/window.c b/src/core/window.c
index df80ead..c1cd528 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -48,6 +48,7 @@
 #include <X11/Xatom.h>
 #include <X11/Xlibint.h> /* For display->resource_mask */
 #include <string.h>
+#include <math.h>
 
 #ifdef HAVE_SHAPE
 #include <X11/extensions/shape.h>
@@ -55,6 +56,10 @@
 
 #include <X11/extensions/Xcomposite.h>
 
+/* Windows that unmaximize to a size bigger than that fraction of the workarea
+ * will be scaled down to that size (while maintaining aspect ratio) */
+#define MAX_UNMAXIMIZED_WINDOW_AREA .8
+
 static int destroying_windows_disallowed = 0;
 
 
@@ -3766,6 +3771,9 @@ meta_window_unmaximize_internal (MetaWindow        *window,
       (unmaximize_vertically   && window->maximized_vertically))
     {
       MetaRectangle target_rect;
+      MetaRectangle work_area;
+
+      meta_window_get_work_area_for_monitor (window, window->monitor->number, &work_area);
 
       meta_topic (META_DEBUG_WINDOW_OPS,
                   "Unmaximizing %s%s\n",
@@ -3790,6 +3798,28 @@ meta_window_unmaximize_internal (MetaWindow        *window,
        * being unmaximized.
        */
       meta_window_get_client_root_coords (window, &target_rect);
+
+      /* Avoid unmaximizing to "almost maximized" size when the previous size
+       * is greater then 80% of the work area use MAX_UNMAXIMIZED_WINDOW_AREA of the work area as upper limit
+       * while maintaining the aspect ratio.
+       */
+      if (unmaximize_horizontally && unmaximize_vertically &&
+          desired_rect->width * desired_rect->height > work_area.width * work_area.height * MAX_UNMAXIMIZED_WINDOW_AREA)
+        {
+          if (desired_rect->width > desired_rect->height)
+            {
+              float aspect = (float)desired_rect->height / (float)desired_rect->width;
+              desired_rect->width = MAX (work_area.width * sqrt (MAX_UNMAXIMIZED_WINDOW_AREA), window->size_hints.min_width);
+              desired_rect->height = MAX (desired_rect->width * aspect, window->size_hints.min_height);
+            }
+          else
+            {
+              float aspect = (float)desired_rect->width / (float)desired_rect->height;
+              desired_rect->height = MAX (work_area.height * sqrt (MAX_UNMAXIMIZED_WINDOW_AREA), window->size_hints.min_height);
+              desired_rect->width = MAX (desired_rect->height * aspect, window->size_hints.min_width);
+            }
+        }
+
       if (unmaximize_horizontally)
         {
           target_rect.x     = desired_rect->x;



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