]> git.mdlowis.com Git - proto/labwc.git/commitdiff
output: Add output_nearest_to()
authorJohn Lindgren <john@jlindgren.net>
Fri, 3 Feb 2023 20:22:54 +0000 (15:22 -0500)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 21 Feb 2023 07:46:22 +0000 (08:46 +0100)
Reimplement output_from_cursor_coords() as output_nearest_to_cursor().

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

index 85097924b9af2602b46267b40611dc23459cc311..cc7806a2677464872822ca22e9180d873c725194 100644 (file)
@@ -416,11 +416,12 @@ void output_init(struct server *server);
 void output_manager_init(struct server *server);
 struct output *output_from_wlr_output(struct server *server,
        struct wlr_output *wlr_output);
+struct output *output_nearest_to(struct server *server, int lx, int ly);
+struct output *output_nearest_to_cursor(struct server *server);
 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 output *output_from_cursor_coords(struct server *server);
 void handle_output_power_manager_set_mode(struct wl_listener *listener,
        void *data);
 
index efbd14ef1676e5189d7a37db0a0104f06c4ab014..3684ec0a30b86793a722f4f2e4ecabe393059137 100644 (file)
@@ -458,6 +458,25 @@ output_from_wlr_output(struct server *server, struct wlr_output *wlr_output)
        return NULL;
 }
 
+struct output *
+output_nearest_to(struct server *server, int lx, int ly)
+{
+       double closest_x, closest_y;
+       wlr_output_layout_closest_point(server->output_layout, NULL, lx, ly,
+               &closest_x, &closest_y);
+
+       return output_from_wlr_output(server,
+               wlr_output_layout_output_at(server->output_layout,
+                       closest_x, closest_y));
+}
+
+struct output *
+output_nearest_to_cursor(struct server *server)
+{
+       return output_nearest_to(server, server->seat.cursor->x,
+               server->seat.cursor->y);
+}
+
 bool
 output_is_usable(struct output *output)
 {
@@ -518,15 +537,6 @@ output_usable_area_in_layout_coords(struct output *output)
        return box;
 }
 
-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);
-       return output_from_wlr_output(server, wlr_output);
-}
-
 void
 handle_output_power_manager_set_mode(struct wl_listener *listener, void *data)
 {
index 98c19654326b4ed3d1910a372a83c6fdfa3e9079..861fcbd7e6ece6b372bdda8263e83dad748f48df 100644 (file)
@@ -226,15 +226,9 @@ struct output *
 view_output(struct view *view)
 {
        assert(view);
-       double closest_x, closest_y;
-       struct wlr_output *wlr_output = NULL;
-       wlr_output_layout_closest_point(view->server->output_layout, wlr_output,
+       return output_nearest_to(view->server,
                view->current.x + view->current.width / 2,
-               view->current.y + view->current.height / 2,
-               &closest_x, &closest_y);
-       wlr_output = wlr_output_layout_output_at(view->server->output_layout,
-               closest_x, closest_y);
-       return output_from_wlr_output(view->server, wlr_output);
+               view->current.y + view->current.height / 2);
 }
 
 static bool
index dca9f44c68b1fcca1203049bc5e2667d5305f723..dea39e0287775417fe1d0da6e1ff2ce30404c65c 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -276,8 +276,7 @@ position_xdg_toplevel_view(struct view *view)
                xdg_toplevel_from_view(view)->parent;
 
        if (!parent_xdg_toplevel) {
-               view_center(view, output_from_cursor_coords(view->server),
-                       NULL);
+               view_center(view, output_nearest_to_cursor(view->server), NULL);
        } else {
                /*
                 * If child-toplevel-views, we center-align relative to their
index 14d4951d42566c711c3f0b5886f68b6ec3eda28b..9ef487df38fcaf4699a54d0620cd26e6f5a335cd 100644 (file)
@@ -440,8 +440,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_from_cursor_coords(view->server),
-                       NULL);
+               view_center(view, output_nearest_to_cursor(view->server), NULL);
        }
 }