]> git.mdlowis.com Git - proto/labwc.git/commitdiff
view: Add optional output parameter to view_center()
authorJohn Lindgren <john@jlindgren.net>
Sat, 18 Feb 2023 05:23:19 +0000 (00:23 -0500)
committerJohn Lindgren <john@jlindgren.net>
Mon, 20 Feb 2023 16:50:12 +0000 (11:50 -0500)
Allows centering the view on a specific output without the workaround of
overwriting view->current.x/y.

include/labwc.h
include/view.h
src/output.c
src/view.c
src/xdg.c
src/xwayland.c

index 99aafb4cffd48952f35379d456055ff3fedd3548..85097924b9af2602b46267b40611dc23459cc311 100644 (file)
@@ -420,7 +420,7 @@ bool output_is_usable(struct output *output);
 void output_update_usable_area(struct output *output);
 void output_update_all_usable_areas(struct server *server, bool layout_changed);
 struct wlr_box output_usable_area_in_layout_coords(struct output *output);
-struct wlr_box output_usable_area_from_cursor_coords(struct server *server);
+struct output *output_from_cursor_coords(struct server *server);
 void handle_output_power_manager_set_mode(struct wl_listener *listener,
        void *data);
 
index b790baeabf36b5521bf5ec005cc96778723d8f5e..777056c813fcadfd46415e7441dc7cfd30fe095a 100644 (file)
@@ -130,11 +130,13 @@ void view_move(struct view *view, int x, int y);
 void view_moved(struct view *view);
 void view_minimize(struct view *view, bool minimized);
 void view_store_natural_geometry(struct view *view);
-void view_center(struct view *view);
+/* output is optional, defaults to current nearest output */
+void view_center(struct view *view, struct output *output);
 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,
        bool store_natural_geometry);
+/* output is optional, defaults to current nearest output */
 void view_set_fullscreen(struct view *view, bool fullscreen,
        struct output *output);
 void view_toggle_maximize(struct view *view);
index 53218508c79b43c10c13bd2123d4211d35efe590..efbd14ef1676e5189d7a37db0a0104f06c4ab014 100644 (file)
@@ -518,14 +518,13 @@ output_usable_area_in_layout_coords(struct output *output)
        return box;
 }
 
-struct wlr_box
-output_usable_area_from_cursor_coords(struct server *server)
+struct output *
+output_from_cursor_coords(struct server *server)
 {
        struct wlr_output *wlr_output;
        wlr_output = wlr_output_layout_output_at(server->output_layout,
                server->seat.cursor->x, server->seat.cursor->y);
-       struct output *output = output_from_wlr_output(server, wlr_output);
-       return output_usable_area_in_layout_coords(output);
+       return output_from_wlr_output(server, wlr_output);
 }
 
 void
index 6e2af1e1f93600d5c8619054ce675336bb23d73e..591595b546e09f25b1bbdf0763992f340b6d1d73 100644 (file)
@@ -238,19 +238,18 @@ view_output(struct view *view)
 }
 
 static bool
-view_compute_centered_position(struct view *view, int w, int h, int *x, int *y)
+view_compute_centered_position(struct view *view, struct output *output,
+               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) {
-               return false;
-       }
-       struct wlr_output *wlr_output = output->wlr_output;
-       if (!wlr_output) {
-               return false;
+       if (!output_is_usable(output)) {
+               output = view_output(view);
+               if (!output_is_usable(output)) {
+                       return false;
+               }
        }
 
        struct border margin = ssd_get_margin(view->ssd);
@@ -284,7 +283,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,
+       view_compute_centered_position(view, NULL,
                view->natural_geometry.width,
                view->natural_geometry.height,
                &view->natural_geometry.x,
@@ -316,11 +315,11 @@ view_store_natural_geometry(struct view *view)
 }
 
 void
-view_center(struct view *view)
+view_center(struct view *view, struct output *output)
 {
        assert(view);
        int x, y;
-       if (view_compute_centered_position(view, view->pending.width,
+       if (view_compute_centered_position(view, output, view->pending.width,
                        view->pending.height, &x, &y)) {
                view_move(view, x, y);
        }
@@ -337,8 +336,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, 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);
                }
        }
@@ -745,7 +744,7 @@ view_adjust_for_layout_change(struct view *view)
                /* reposition view if it's offscreen */
                if (!wlr_output_layout_intersects(view->server->output_layout,
                                NULL, &view->pending)) {
-                       view_center(view);
+                       view_center(view, NULL);
                }
        }
        if (view->toplevel.handle) {
index 1c185eeb77341a4144b01245c7048fb110053070..c9e1a3c34c37a0c64a5c1f79052c57653a6177e6 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -278,11 +278,7 @@ position_xdg_toplevel_view(struct view *view)
                xdg_toplevel_from_view(view)->parent;
 
        if (!parent_xdg_toplevel) {
-               struct wlr_box box =
-                       output_usable_area_from_cursor_coords(view->server);
-               view->current.x = box.x;
-               view->current.y = box.y;
-               view_center(view);
+               view_center(view, output_from_cursor_coords(view->server));
        } else {
                /*
                 * If child-toplevel-views, we center-align relative to their
index 0e3b616552d4ce25568c4c4844f96f0b8ed0f1a3..8f94b105607de5ed0ff395b050f7b9598fd7c8e9 100644 (file)
@@ -440,11 +440,7 @@ set_initial_position(struct view *view,
                /* Just make sure the view is on-screen */
                view_adjust_for_layout_change(view);
        } else {
-               struct wlr_box box =
-                       output_usable_area_from_cursor_coords(view->server);
-               view->current.x = box.x;
-               view->current.y = box.y;
-               view_center(view);
+               view_center(view, output_from_cursor_coords(view->server));
        }
 }