diff options
author | emersion <contact@emersion.fr> | 2017-10-08 12:17:25 +0200 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2017-10-08 12:17:25 +0200 |
commit | d09d01236ba5804320bc9ad7d592c5077205f878 (patch) | |
tree | cd9ad220efcd58eccdc173f32d1483b8e17f9169 /rootston/desktop.c | |
parent | 543601e86c24ad6ed630aba0cf615bfb585c19e7 (diff) |
Center xdg shell views
Diffstat (limited to 'rootston/desktop.c')
-rw-r--r-- | rootston/desktop.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/rootston/desktop.c b/rootston/desktop.c index 555d592f..ee813130 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -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; |