From c39998efee9489dc011e572fb3f589989ce3ecbb Mon Sep 17 00:00:00 2001 From: Adel Gadllah Date: Mon, 12 Mar 2012 17:09:17 +0100 Subject: [PATCH] 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 file changed, 30 insertions(+) diff --git a/src/core/window.c b/src/core/window.c index df80eadb0..c1cd528af 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -48,6 +48,7 @@ #include #include /* For display->resource_mask */ #include +#include #ifdef HAVE_SHAPE #include @@ -55,6 +56,10 @@ #include +/* 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;