]> git.mdlowis.com Git - proto/labwc.git/commitdiff
src/view.c: Fall back to default geometry when changing state
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Sat, 2 Jul 2022 18:23:14 +0000 (20:23 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 3 Jul 2022 12:46:47 +0000 (13:46 +0100)
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

index b833c372adc04e00bd7b650e001f1d5886b7f6ae..6288d671274d5aa5380815a7bf161438732f1720 100644 (file)
@@ -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)) {