]> git.mdlowis.com Git - proto/labwc.git/commitdiff
xdg: use "usable_area" when positioning view
authorJohan Malm <jgm323@gmail.com>
Wed, 21 Jul 2021 21:04:54 +0000 (22:04 +0100)
committerJohan Malm <jgm323@gmail.com>
Wed, 21 Jul 2021 21:04:54 +0000 (22:04 +0100)
include/labwc.h
src/output.c
src/view.c
src/xdg.c
src/xwayland.c

index 5c9a024f41668e34f49cea544d5b1524b69d7f9e..8fc2b4f10cd3a1a82706fe6cc336207e4e837570 100644 (file)
@@ -337,7 +337,8 @@ void output_damage_surface(struct output *output, struct wlr_surface *surface,
 void scale_box(struct wlr_box *box, float scale);
 void output_manager_init(struct server *server);
 struct output *output_from_wlr_output(struct server *server, struct wlr_output *wlr_output);
-struct wlr_box *output_box_from_cursor_coords(struct server *server);
+struct wlr_box output_usable_area_in_layout_coords(struct output *output);
+struct wlr_box output_usable_area_from_cursor_coords(struct server *server);
 
 void damage_all_outputs(struct server *server);
 void damage_view_whole(struct view *view);
index beb13bfeceb62282e8a302a0cfd86d7eee77f592..43036aa449fb9349f537a6795465680bb069ff94 100644 (file)
@@ -1002,11 +1002,24 @@ output_from_wlr_output(struct server *server, struct wlr_output *wlr_output)
        return NULL;
 }
 
-struct wlr_box *
-output_box_from_cursor_coords(struct server *server)
+struct wlr_box
+output_usable_area_in_layout_coords(struct output *output)
+{
+       struct wlr_box box = output->usable_area;
+       double ox = 0, oy = 0;
+       wlr_output_layout_output_coords(output->server->output_layout,
+               output->wlr_output, &ox, &oy);
+       box.x -= ox;
+       box.y -= oy;
+       return box;
+}
+
+struct wlr_box
+output_usable_area_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 wlr_output_layout_get_box(server->output_layout, wlr_output);
+       struct output *output = output_from_wlr_output(server, wlr_output);
+       return output_usable_area_in_layout_coords(output);
 }
index 583bd9a2d2c37d54b91af7464f285ac4574612be..f46a9ea3c75582183882dc71f24b94e0c7b6eaf7 100644 (file)
@@ -35,19 +35,12 @@ view_unminimize(struct view *view)
        view->impl->map(view);
 }
 
-/*
- * view_wlr_output - return the output that a view is mostly on
- */
+/* view_wlr_output - return the output that a view is mostly on */
 static struct wlr_output *
 view_wlr_output(struct view *view)
 {
-       struct wlr_output_layout *layout = view->server->output_layout;
-       struct wlr_output *output;
-
-       /* TODO: make this a bit more sophisticated */
-       output = wlr_output_layout_output_at(layout, view->x + view->w / 2,
-                                            view->y + view->h / 2);
-       return output;
+       return wlr_output_layout_output_at(view->server->output_layout,
+               view->x + view->w / 2, view->y + view->h / 2);
 }
 
 static struct output *
@@ -73,18 +66,6 @@ view_center(struct view *view)
        view_move(view, center_x - view->w / 2, center_y - view->h / 2);
 }
 
-static struct wlr_box
-usable_area_in_layout_coords(struct output *output)
-{
-       struct wlr_box box = output->usable_area;
-       double ox = 0, oy = 0;
-       wlr_output_layout_output_coords(output->server->output_layout,
-               output->wlr_output, &ox, &oy);
-       box.x -= ox;
-       box.y -= oy;
-       return box;
-}
-
 void
 view_maximize(struct view *view, bool maximize)
 {
@@ -99,7 +80,7 @@ view_maximize(struct view *view, bool maximize)
                view->unmaximized_geometry.height = view->h;
 
                struct output *output = view_output(view);
-               struct wlr_box box = usable_area_in_layout_coords(output);
+               struct wlr_box box = output_usable_area_in_layout_coords(output);
 
                if (view->ssd.enabled) {
                        struct border border = ssd_thickness(view);
@@ -158,7 +139,7 @@ view_move_to_edge(struct view *view, const char *direction)
        }
        struct output *output = view_output(view);
        struct border border = view_border(view);
-       struct wlr_box usable = usable_area_in_layout_coords(output);
+       struct wlr_box usable = output_usable_area_in_layout_coords(output);
 
        int x, y;
        if (!strcasecmp(direction, "left")) {
index 18ff8b2ec65d29ee6f739a21923d2e9c5683b21b..1f9d0105749fe409624df47b140790faca0026b6 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -224,12 +224,14 @@ static void
 position_xdg_toplevel_view(struct view *view)
 {
        if (istopmost(view)) {
-               struct wlr_box *box = output_box_from_cursor_coords(view->server);
-               view->x = box->x;
-               view->y = box->y;
+               struct wlr_box box = output_usable_area_from_cursor_coords(view->server);
+               view->x = box.x;
+               view->y = box.y;
                view->w = view->xdg_surface->geometry.width;
                view->h = view->xdg_surface->geometry.height;
-               view_center(view);
+               if (view->w && view->h) {
+                       view_center(view);
+               }
        } else {
                /*
                 * If child-toplevel-views, we center-align relative to their
@@ -263,6 +265,7 @@ xdg_toplevel_view_map(struct view *view)
                        view->margin = ssd_thickness(view);
                        ssd_create(view);
                }
+
                update_padding(view);
                position_xdg_toplevel_view(view);
 
@@ -275,6 +278,7 @@ xdg_toplevel_view_map(struct view *view)
                                 parent_link) {
                        subsurface_create(view, subsurface);
                }
+
                view->been_mapped = true;
        }
 
index 36b7e93559fe60b4f7dcb6686cd23cb0e7edae58..515947fe405f28862417cd372d8265883a2c688e 100644 (file)
@@ -159,9 +159,9 @@ map(struct view *view)
 
        if (!view->been_mapped) {
                view_maximize(view, false);
-               struct wlr_box *box = output_box_from_cursor_coords(view->server);
-               view->x = box->x;
-               view->y = box->y;
+               struct wlr_box box = output_usable_area_from_cursor_coords(view->server);
+               view->x = box.x;
+               view->y = box.y;
                view_center(view);
                view->been_mapped = true;
        }