mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-02 11:55:59 +01:00
Center xdg shell views
This commit is contained in:
parent
543601e86c
commit
d09d01236b
3 changed files with 41 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
#ifndef _ROOTSTON_VIEW_H
|
||||
#define _ROOTSTON_VIEW_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
|
@ -18,7 +19,9 @@ struct roots_wl_shell_surface {
|
|||
|
||||
struct roots_xdg_surface_v6 {
|
||||
struct roots_view *view;
|
||||
|
||||
// TODO: Maybe destroy listener should go in roots_view
|
||||
struct wl_listener commit;
|
||||
struct wl_listener destroy;
|
||||
struct wl_listener ping_timeout;
|
||||
struct wl_listener request_minimize;
|
||||
|
@ -73,5 +76,6 @@ void view_get_input_bounds(struct roots_view *view, struct wlr_box *box);
|
|||
void view_activate(struct roots_view *view, bool active);
|
||||
void view_resize(struct roots_view *view, uint32_t width, uint32_t height);
|
||||
void view_close(struct roots_view *view);
|
||||
bool view_center(struct roots_view *view);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -67,6 +67,17 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
|
|||
view_begin_resize(input, event->cursor, view, e->edges);
|
||||
}
|
||||
|
||||
static void handle_commit(struct wl_listener *listener, void *data) {
|
||||
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
||||
wl_container_of(listener, roots_xdg_surface, commit);
|
||||
struct roots_view *view = roots_xdg_surface->view;
|
||||
|
||||
bool centered = view_center(view);
|
||||
if (centered) {
|
||||
wl_list_remove(&listener->link);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_destroy(struct wl_listener *listener, void *data) {
|
||||
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
||||
wl_container_of(listener, roots_xdg_surface, destroy);
|
||||
|
@ -98,7 +109,12 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
|
|||
|
||||
struct roots_xdg_surface_v6 *roots_surface =
|
||||
calloc(1, sizeof(struct roots_xdg_surface_v6));
|
||||
// TODO: all of the trimmings
|
||||
if (!roots_surface) {
|
||||
return;
|
||||
}
|
||||
wl_list_init(&roots_surface->commit.link);
|
||||
roots_surface->commit.notify = handle_commit;
|
||||
wl_signal_add(&surface->events.commit, &roots_surface->commit);
|
||||
wl_list_init(&roots_surface->destroy.link);
|
||||
roots_surface->destroy.notify = handle_destroy;
|
||||
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
|
||||
|
@ -115,7 +131,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
|
|||
|
||||
struct roots_view *view = calloc(1, sizeof(struct roots_view));
|
||||
view->type = ROOTS_XDG_SHELL_V6_VIEW;
|
||||
view->x = view->y = 200;
|
||||
view->xdg_surface_v6 = surface;
|
||||
view->roots_xdg_surface_v6 = roots_surface;
|
||||
view->wlr_surface = surface->surface;
|
||||
|
|
Loading…
Reference in a new issue