Center xdg shell views

This commit is contained in:
emersion 2017-10-08 12:17:25 +02:00
parent 543601e86c
commit d09d01236b
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
3 changed files with 41 additions and 2 deletions

View file

@ -83,6 +83,26 @@ void view_close(struct roots_view *view) {
}
}
bool view_center(struct roots_view *view) {
struct wlr_box size;
view_get_size(view, &size);
if (size.width == 0 && size.height == 0) {
return false;
}
struct roots_desktop *desktop = view->desktop;
struct wlr_cursor *cursor = desktop->server->input->cursor;
struct wlr_output *output = wlr_output_layout_output_at(desktop->layout,
cursor->x, cursor->y);
if (!output) {
return false;
}
view->x = (double)(output->width - size.width) / 2;
view->y = (double)(output->height - size.height) / 2;
return true;
}
static struct wlr_subsurface *subsurface_at(struct wlr_surface *surface,
double sx, double sy, double *sub_x, double *sub_y) {
struct wlr_subsurface *subsurface;