diff options
Diffstat (limited to 'rootston/wl_shell.c')
-rw-r--r-- | rootston/wl_shell.c | 88 |
1 files changed, 46 insertions, 42 deletions
diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 81c0c128..b60f6ac7 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -34,7 +34,7 @@ static void popup_handle_destroy(struct wl_listener *listener, void *data) { static void popup_handle_set_state(struct wl_listener *listener, void *data) { struct roots_wl_shell_popup *popup = wl_container_of(listener, popup, set_state); - popup_destroy((struct roots_view_child *)popup); + view_child_destroy(&popup->view_child); } static struct roots_wl_shell_popup *popup_create(struct roots_view *view, @@ -68,21 +68,21 @@ static struct roots_wl_shell_popup *popup_create(struct roots_view *view, static void resize(struct roots_view *view, uint32_t width, uint32_t height) { - assert(view->type == ROOTS_WL_SHELL_VIEW); - struct wlr_wl_shell_surface *surf = view->wl_shell_surface; + struct wlr_wl_shell_surface *surf = + roots_wl_shell_surface_from_view(view)->wl_shell_surface; wlr_wl_shell_surface_configure(surf, WL_SHELL_SURFACE_RESIZE_NONE, width, height); } static void close(struct roots_view *view) { - assert(view->type == ROOTS_WL_SHELL_VIEW); - struct wlr_wl_shell_surface *surf = view->wl_shell_surface; + struct wlr_wl_shell_surface *surf = + roots_wl_shell_surface_from_view(view)->wl_shell_surface; wl_client_destroy(surf->client); } static void destroy(struct roots_view *view) { - assert(view->type == ROOTS_WL_SHELL_VIEW); - struct roots_wl_shell_surface *roots_surface = view->roots_wl_shell_surface; + struct roots_wl_shell_surface *roots_surface = + roots_wl_shell_surface_from_view(view); wl_list_remove(&roots_surface->destroy.link); wl_list_remove(&roots_surface->request_move.link); wl_list_remove(&roots_surface->request_resize.link); @@ -104,7 +104,7 @@ static const struct roots_view_interface view_impl = { static void handle_request_move(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, request_move); - struct roots_view *view = roots_surface->view; + struct roots_view *view = &roots_surface->view; struct roots_input *input = view->desktop->server->input; struct wlr_wl_shell_surface_move_event *e = data; struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat); @@ -117,7 +117,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) { static void handle_request_resize(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, request_resize); - struct roots_view *view = roots_surface->view; + struct roots_view *view = &roots_surface->view; struct roots_input *input = view->desktop->server->input; struct wlr_wl_shell_surface_resize_event *e = data; struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat); @@ -131,7 +131,7 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, request_maximize); - struct roots_view *view = roots_surface->view; + struct roots_view *view = &roots_surface->view; //struct wlr_wl_shell_surface_maximize_event *e = data; view_maximize(view, true); } @@ -140,7 +140,7 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, request_fullscreen); - struct roots_view *view = roots_surface->view; + struct roots_view *view = &roots_surface->view; struct wlr_wl_shell_surface_set_fullscreen_event *e = data; view_set_fullscreen(view, true, e->output); } @@ -148,8 +148,8 @@ static void handle_request_fullscreen(struct wl_listener *listener, static void handle_set_state(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, set_state); - struct roots_view *view = roots_surface->view; - struct wlr_wl_shell_surface *surface = view->wl_shell_surface; + struct roots_view *view = &roots_surface->view; + struct wlr_wl_shell_surface *surface = roots_surface->wl_shell_surface; if (view->maximized && surface->state != WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED) { view_maximize(view, false); @@ -163,21 +163,21 @@ static void handle_set_state(struct wl_listener *listener, void *data) { static void handle_set_title(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, set_state); - view_set_title(roots_surface->view, - roots_surface->view->wl_shell_surface->title); + view_set_title(&roots_surface->view, + roots_surface->wl_shell_surface->title); } static void handle_set_class(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, set_state); - view_set_app_id(roots_surface->view, - roots_surface->view->wl_shell_surface->class); + view_set_app_id(&roots_surface->view, + roots_surface->wl_shell_surface->class); } static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, surface_commit); - struct roots_view *view = roots_surface->view; + struct roots_view *view = &roots_surface->view; struct wlr_surface *wlr_surface = view->wlr_surface; view_apply_damage(view); @@ -205,13 +205,13 @@ static void handle_new_popup(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, new_popup); struct wlr_wl_shell_surface *wlr_wl_shell_surface = data; - popup_create(roots_surface->view, wlr_wl_shell_surface); + popup_create(&roots_surface->view, wlr_wl_shell_surface); } static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, destroy); - view_destroy(roots_surface->view); + view_destroy(&roots_surface->view); } void handle_wl_shell_surface(struct wl_listener *listener, void *data) { @@ -233,6 +233,12 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { if (!roots_surface) { return; } + + view_init(&roots_surface->view, &view_impl, ROOTS_WL_SHELL_VIEW, desktop); + roots_surface->view.box.width = surface->surface->current.width; + roots_surface->view.box.height = surface->surface->current.height; + roots_surface->wl_shell_surface = surface; + roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); roots_surface->new_popup.notify = handle_new_popup; @@ -259,42 +265,40 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&surface->surface->events.commit, &roots_surface->surface_commit); - struct roots_view *view = view_create(desktop, &view_impl); - if (!view) { - free(roots_surface); - return; - } - view->type = ROOTS_WL_SHELL_VIEW; - view->box.width = surface->surface->current.width; - view->box.height = surface->surface->current.height; - - view->wl_shell_surface = surface; - view->roots_wl_shell_surface = roots_surface; - roots_surface->view = view; - - view_map(view, surface->surface); - view_setup(view); + view_map(&roots_surface->view, surface->surface); + view_setup(&roots_surface->view); - wlr_foreign_toplevel_handle_v1_set_title(view->toplevel_handle, - view->wl_shell_surface->title ?: "none"); - wlr_foreign_toplevel_handle_v1_set_app_id(view->toplevel_handle, - view->wl_shell_surface->class ?: "none"); + wlr_foreign_toplevel_handle_v1_set_title(roots_surface->view.toplevel_handle, + surface->title ?: "none"); + wlr_foreign_toplevel_handle_v1_set_app_id(roots_surface->view.toplevel_handle, + surface->class ?: "none"); if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) { // We need to map it relative to the parent bool found = false; struct roots_view *parent; wl_list_for_each(parent, &desktop->views, link) { - if (parent->type == ROOTS_WL_SHELL_VIEW && - parent->wl_shell_surface == surface->parent) { + if (parent->type != ROOTS_WL_SHELL_VIEW) { + continue; + } + + struct roots_wl_shell_surface *parent_surf = + roots_wl_shell_surface_from_view(parent); + if (parent_surf->wl_shell_surface == surface->parent) { found = true; break; } } if (found) { - view_move(view, + view_move(&roots_surface->view, parent->box.x + surface->transient_state->x, parent->box.y + surface->transient_state->y); } } } + +struct roots_wl_shell_surface *roots_wl_shell_surface_from_view( + struct roots_view *view) { + assert(view->impl == &view_impl); + return (struct roots_wl_shell_surface *)view; +} |