From baaee2693736ee50ee11246fd202b5cf16e607fe Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Sat, 2 Jul 2022 20:23:14 +0200 Subject: [PATCH] src/view.c: Fall back to default geometry when changing state This makes sure that applications starting in maximized of fullscreen mode always have their natural_geometry set to sensible values. Partly fixes #403 --- src/view.c | 67 +++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/view.c b/src/view.c index b833c372..6288d671 100644 --- a/src/view.c +++ b/src/view.c @@ -8,6 +8,8 @@ #include "menu/menu.h" #include "workspaces.h" +#define LAB_FALLBACK_WIDTH 640 +#define LAB_FALLBACK_HEIGHT 480 #define MAX(a, b) (((a) > (b)) ? (a) : (b)) /** @@ -215,15 +217,6 @@ view_wlr_output(struct view *view) return wlr_output; } -static void -view_store_natural_geometry(struct view *view) -{ - view->natural_geometry.x = view->x; - view->natural_geometry.y = view->y; - view->natural_geometry.width = view->w; - view->natural_geometry.height = view->h; -} - static struct output * view_output(struct view *view) { @@ -268,6 +261,38 @@ view_compute_centered_position(struct view *view, int w, int h, int *x, int *y) return true; } +static void +set_fallback_geometry(struct view *view) +{ + view->natural_geometry.width = LAB_FALLBACK_WIDTH; + view->natural_geometry.height = LAB_FALLBACK_HEIGHT; + view_compute_centered_position(view, + view->natural_geometry.width, + view->natural_geometry.height, + &view->natural_geometry.x, + &view->natural_geometry.y); +} +#undef LAB_FALLBACK_WIDTH +#undef LAB_FALLBACK_HEIGHT + +static void +view_store_natural_geometry(struct view *view) +{ + /** + * If an application was started maximized or fullscreened, its + * natural_geometry width/height may still be zero in which case we set + * some fallback values. This is the case with foot and Qt applications. + */ + if (!view->w || !view->h) { + set_fallback_geometry(view); + } else { + view->natural_geometry.x = view->x; + view->natural_geometry.y = view->y; + view->natural_geometry.width = view->w; + view->natural_geometry.height = view->h; + } +} + void view_center(struct view *view) { @@ -347,33 +372,9 @@ view_apply_maximized_geometry(struct view *view) view_move_resize(view, box); } -#define LAB_FALLBACK_WIDTH (640) -#define LAB_FALLBACK_HEIGHT (480) - -static void -set_fallback_geometry(struct view *view) -{ - view->natural_geometry.width = LAB_FALLBACK_WIDTH; - view->natural_geometry.height = LAB_FALLBACK_HEIGHT; - view_compute_centered_position(view, - view->natural_geometry.width, - view->natural_geometry.height, - &view->natural_geometry.x, - &view->natural_geometry.y); -} - static void view_apply_unmaximized_geometry(struct view *view) { - /* - * If an application was started maximized, its unmaximized_geometry - * width/height may still be zero in which case we set some fallback - * values. This is the case with foot and Qt applications. - */ - if (wlr_box_empty(&view->natural_geometry)) { - set_fallback_geometry(view); - } - struct wlr_output_layout *layout = view->server->output_layout; if (wlr_output_layout_intersects(layout, NULL, &view->natural_geometry)) {