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;