From a3ac2f27678c555307f18275293b12afbb553833 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Mon, 12 Jul 2021 21:39:09 +0100 Subject: [PATCH] layers: take into account usable area when maximizing views --- include/labwc.h | 2 ++ src/layers.c | 7 +++++-- src/output.c | 2 ++ src/view.c | 32 +++++++++++++++----------------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/include/labwc.h b/include/labwc.h index c00dc366..c1cd528b 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -133,6 +133,8 @@ struct output { struct wlr_output *wlr_output; struct wlr_output_damage *damage; struct wl_list layers[4]; + struct wlr_box usable_area; + struct wl_listener destroy; struct wl_listener damage_frame; struct wl_listener damage_destroy; diff --git a/src/layers.c b/src/layers.c index e340dce7..ed70685f 100644 --- a/src/layers.c +++ b/src/layers.c @@ -167,9 +167,9 @@ arrange_layer(struct wlr_output *output, struct wl_list *list, void arrange_layers(struct output *output) { + assert(output); + struct wlr_box usable_area = { 0 }; - if (!output) - return; wlr_output_effective_resolution(output->wlr_output, &usable_area.width, &usable_area.height); @@ -186,6 +186,9 @@ arrange_layers(struct output *output) arrange_layer(output->wlr_output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &usable_area, true); + memcpy(&output->usable_area, &usable_area, sizeof(struct wlr_box)); + + /* TODO: re-arrange all views taking into account updated usable_area */ /* Non-exclusive surfaces */ arrange_layer(output->wlr_output, diff --git a/src/output.c b/src/output.c index ab002f7e..f56873dc 100644 --- a/src/output.c +++ b/src/output.c @@ -809,6 +809,8 @@ new_output_notify(struct wl_listener *listener, void *data) output->wlr_output = wlr_output; output->server = server; output->damage = wlr_output_damage_create(wlr_output); + wlr_output_effective_resolution(wlr_output, + &output->usable_area.width, &output->usable_area.height); wl_list_insert(&server->outputs, &output->link); output->destroy.notify = output_destroy_notify; diff --git a/src/view.c b/src/view.c index 0f59e979..895dff74 100644 --- a/src/view.c +++ b/src/view.c @@ -73,26 +73,24 @@ view_maximize(struct view *view, bool maximize) } view->impl->maximize(view, maximize); if (maximize) { - struct wlr_output *output = view_output(view); - if (!output) { - return; - } - - struct wlr_output_layout *layout = view->server->output_layout; - struct wlr_output_layout_output* ol_output = - wlr_output_layout_get(layout, output); - view->unmaximized_geometry.x = view->x; view->unmaximized_geometry.y = view->y; view->unmaximized_geometry.width = view->w; view->unmaximized_geometry.height = view->h; - struct wlr_box box = { - .x = ol_output->x, - .y = ol_output->y, - .width = output->width, - .height = output->height, - }; + struct wlr_output *wlr_output = view_output(view); + struct output *output = + output_from_wlr_output(view->server, wlr_output); + + struct wlr_box box; + memcpy(&box, &output->usable_area, sizeof(struct wlr_box)); + + double ox = 0, oy = 0; + wlr_output_layout_output_coords(view->server->output_layout, + wlr_output, &ox, &oy); + box.x -= ox; + box.y -= oy; + if (view->ssd.enabled) { struct border border = ssd_thickness(view); box.x += border.left; @@ -100,8 +98,8 @@ view_maximize(struct view *view, bool maximize) box.width -= border.right + border.left; box.height -= border.top + border.bottom; } - box.width /= output->scale; - box.height /= output->scale; + box.width /= wlr_output->scale; + box.height /= wlr_output->scale; view_move_resize(view, box); view_move(view, box.x, box.y); view->maximized = true; -- 2.52.0