From: Johan Malm Date: Wed, 21 Jul 2021 21:04:54 +0000 (+0100) Subject: xdg: use "usable_area" when positioning view X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=22f5073ebd19b217b115600b2b3d8190f578e78b;p=proto%2Flabwc.git xdg: use "usable_area" when positioning view --- diff --git a/include/labwc.h b/include/labwc.h index 5c9a024f..8fc2b4f1 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -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); diff --git a/src/output.c b/src/output.c index beb13bfe..43036aa4 100644 --- a/src/output.c +++ b/src/output.c @@ -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); } diff --git a/src/view.c b/src/view.c index 583bd9a2..f46a9ea3 100644 --- a/src/view.c +++ b/src/view.c @@ -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")) { diff --git a/src/xdg.c b/src/xdg.c index 18ff8b2e..1f9d0105 100644 --- 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; } diff --git a/src/xwayland.c b/src/xwayland.c index 36b7e935..515947fe 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -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; }