view: increase accuracy of center-alignment

When center-aligning, take into account usable area and server-side
decoration (if used).
This commit is contained in:
Johan Malm 2022-04-19 23:01:23 +01:00
parent 6b4d9b9383
commit a234e71b29

View file

@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <strings.h> #include <strings.h>
#include "labwc.h" #include "labwc.h"
@ -138,20 +139,18 @@ view_output(struct view *view)
static bool static bool
view_compute_centered_position(struct view *view, int w, int h, int *x, int *y) view_compute_centered_position(struct view *view, int w, int h, int *x, int *y)
{ {
struct wlr_output *wlr_output = view_wlr_output(view); struct output *output = view_output(view);
assert(output);
struct wlr_output *wlr_output = output->wlr_output;
if (!wlr_output) { if (!wlr_output) {
return false; return false;
} }
struct wlr_output_layout *layout = view->server->output_layout; struct wlr_box usable = output_usable_area_in_layout_coords(output);
struct wlr_output_layout_output *ol_output = int width = w + view->margin.left + view->margin.right;
wlr_output_layout_get(layout, wlr_output); int height = h + view->margin.top + view->margin.bottom;
if (!ol_output) { *x = usable.x + usable.width / wlr_output->scale / 2 - width / 2;
return false; *y = usable.y + usable.height / wlr_output->scale / 2 - height / 2;
}
*x = ol_output->x + wlr_output->width / wlr_output->scale / 2 - w / 2;
*y = ol_output->y + wlr_output->height / wlr_output->scale / 2 - h / 2;
return true; return true;
} }