]> git.mdlowis.com Git - proto/labwc.git/commitdiff
view: Set view->output prior to calling view_center()
authorJohn Lindgren <john@jlindgren.net>
Mon, 20 Feb 2023 21:23:53 +0000 (16:23 -0500)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 5 Mar 2023 08:44:03 +0000 (08:44 +0000)
include/view.h
src/view.c
src/xdg.c
src/xwayland.c

index 3bcad7b6e2d6383d599b9d39f9187630487a919a..71d0efb46d4058d1e3664d3ff63acf2fbf8d426b 100644 (file)
@@ -131,9 +131,7 @@ void view_moved(struct view *view);
 void view_minimize(struct view *view, bool minimized);
 struct output *view_output(struct view *view);
 void view_store_natural_geometry(struct view *view);
-/* output is optional, defaults to current nearest output */
-void view_center(struct view *view, struct output *output,
-       const struct wlr_box *ref);
+void view_center(struct view *view, const struct wlr_box *ref);
 void view_restore_to(struct view *view, struct wlr_box geometry);
 void view_set_untiled(struct view *view);
 void view_maximize(struct view *view, bool maximize,
index f10e014376b142aa8d06558d1df0ef45d80e518c..182402fcc8d1d37d058dd61b5ee71b5b019a3b73 100644 (file)
@@ -254,18 +254,16 @@ view_minimize(struct view *view, bool minimized)
 }
 
 static bool
-view_compute_centered_position(struct view *view, struct output *output,
-               const struct wlr_box *ref, int w, int h, int *x, int *y)
+view_compute_centered_position(struct view *view, const struct wlr_box *ref,
+               int w, int h, int *x, int *y)
 {
        if (w <= 0 || h <= 0) {
                wlr_log(WLR_ERROR, "view has empty geometry, not centering");
                return false;
        }
+       struct output *output = view_output(view);
        if (!output_is_usable(output)) {
-               output = view_output(view);
-               if (!output_is_usable(output)) {
-                       return false;
-               }
+               return false;
        }
 
        struct border margin = ssd_get_margin(view->ssd);
@@ -299,7 +297,7 @@ 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, NULL, NULL,
+       view_compute_centered_position(view, NULL,
                view->natural_geometry.width,
                view->natural_geometry.height,
                &view->natural_geometry.x,
@@ -331,12 +329,12 @@ view_store_natural_geometry(struct view *view)
 }
 
 void
-view_center(struct view *view, struct output *output, const struct wlr_box *ref)
+view_center(struct view *view, const struct wlr_box *ref)
 {
        assert(view);
        int x, y;
-       if (view_compute_centered_position(view, output, ref,
-                       view->pending.width, view->pending.height, &x, &y)) {
+       if (view_compute_centered_position(view, ref, view->pending.width,
+                       view->pending.height, &x, &y)) {
                view_move(view, x, y);
        }
 }
@@ -352,8 +350,8 @@ view_apply_natural_geometry(struct view *view)
        } else {
                /* reposition if original geometry is offscreen */
                struct wlr_box box = view->natural_geometry;
-               if (view_compute_centered_position(view, NULL, NULL,
-                               box.width, box.height, &box.x, &box.y)) {
+               if (view_compute_centered_position(view, NULL, box.width,
+                               box.height, &box.x, &box.y)) {
                        view_move_resize(view, box);
                }
        }
@@ -777,7 +775,7 @@ view_adjust_for_layout_change(struct view *view)
                        if (!wlr_output_layout_intersects(
                                        view->server->output_layout,
                                        NULL, &view->pending)) {
-                               view_center(view, NULL, NULL);
+                               view_center(view, NULL);
                        }
                }
        }
index 7123ce58ee88f43aa9db03590cda50d174c437e2..f2d1aaca4b2ad54c699d7ff0d7b5f4c620f6a2f8 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -306,7 +306,7 @@ position_xdg_toplevel_view(struct view *view)
                xdg_toplevel_from_view(view)->parent;
 
        if (!parent_xdg_toplevel) {
-               view_center(view, output_nearest_to_cursor(view->server), NULL);
+               view_center(view, NULL);
        } else {
                /*
                 * If child-toplevel-views, we center-align relative to their
@@ -315,7 +315,8 @@ position_xdg_toplevel_view(struct view *view)
                struct view *parent = lookup_view_by_xdg_toplevel(
                        view->server, parent_xdg_toplevel);
                assert(parent);
-               view_center(view, view_output(parent), &parent->pending);
+               view->output = view_output(parent);
+               view_center(view, &parent->pending);
        }
 }
 
index 5235cd5750bc0ba16e8341dad2bef63fbae05889..765f0f169e4f928b73dc9247df39fdb17da7eba8 100644 (file)
@@ -400,7 +400,7 @@ set_initial_position(struct view *view,
                /* Just make sure the view is on-screen */
                view_adjust_for_layout_change(view);
        } else {
-               view_center(view, output_nearest_to_cursor(view->server), NULL);
+               view_center(view, NULL);
        }
 }