From c27fd1e1ee9826ea0668d2bb5aa8644daec29a7f Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 9 Mar 2018 10:29:22 +0100 Subject: rootston: add view_map and view_unmap --- include/rootston/desktop.h | 6 +++-- include/rootston/view.h | 1 - rootston/desktop.c | 58 ++++++++++++++++++++++++++++++++-------------- rootston/wl_shell.c | 10 +++----- rootston/xdg_shell.c | 11 +++------ rootston/xdg_shell_v6.c | 11 +++------ rootston/xwayland.c | 43 +++++----------------------------- 7 files changed, 59 insertions(+), 81 deletions(-) diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 467de8ab..61fe47b0 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -71,14 +71,16 @@ struct roots_output *desktop_output_from_wlr_output( struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy); -void view_init(struct roots_view *view, struct roots_desktop *desktop); -void view_finish(struct roots_view *view); +struct roots_view *view_create(struct roots_desktop *desktop); +void view_destroy(struct roots_view *view); void view_activate(struct roots_view *view, bool activate); void view_apply_damage(struct roots_view *view); void view_damage_whole(struct roots_view *view); void view_update_position(struct roots_view *view, double x, double y); void view_update_size(struct roots_view *view, uint32_t width, uint32_t height); void view_initial_focus(struct roots_view *view); +void view_map(struct roots_view *view, struct wlr_surface *surface); +void view_unmap(struct roots_view *view); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); void handle_xdg_shell_surface(struct wl_listener *listener, void *data); diff --git a/include/rootston/view.h b/include/rootston/view.h index ff5ef44a..66a0cb3d 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -181,7 +181,6 @@ struct roots_xdg_popup { struct wl_listener new_popup; }; -struct roots_view *view_create(); void view_get_box(const struct roots_view *view, struct wlr_box *box); void view_activate(struct roots_view *view, bool active); void view_move(struct roots_view *view, double x, double y); diff --git a/rootston/desktop.c b/rootston/desktop.c index 3628b051..66c7ac2b 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -23,13 +23,15 @@ #include "rootston/view.h" #include "rootston/xcursor.h" - -struct roots_view *view_create() { +struct roots_view *view_create(struct roots_desktop *desktop) { struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (!view) { return NULL; } + view->desktop = desktop; view->alpha = 1.0f; + wl_signal_init(&view->events.destroy); + wl_list_init(&view->children); return view; } @@ -402,20 +404,18 @@ struct roots_subsurface *subsurface_create(struct roots_view *view, return subsurface; } -void view_finish(struct roots_view *view) { - view_damage_whole(view); - wl_signal_emit(&view->events.destroy, view); - - wl_list_remove(&view->new_subsurface.link); - - struct roots_view_child *child, *tmp; - wl_list_for_each_safe(child, tmp, &view->children, link) { - child->destroy(child); +void view_destroy(struct roots_view *view) { + if (view == NULL) { + return; } - if (view->fullscreen_output) { - view->fullscreen_output->fullscreen_view = NULL; + if (view->wlr_surface != NULL) { + view_unmap(view); } + + wl_signal_emit(&view->events.destroy, view); + + free(view); } static void view_handle_new_subsurface(struct wl_listener *listener, @@ -425,12 +425,10 @@ static void view_handle_new_subsurface(struct wl_listener *listener, subsurface_create(view, wlr_subsurface); } -void view_init(struct roots_view *view, struct roots_desktop *desktop) { - assert(view->wlr_surface); +void view_map(struct roots_view *view, struct wlr_surface *surface) { + assert(view->wlr_surface == NULL); - view->desktop = desktop; - wl_signal_init(&view->events.destroy); - wl_list_init(&view->children); + view->wlr_surface = surface; struct wlr_subsurface *subsurface; wl_list_for_each(subsurface, &view->wlr_surface->subsurface_list, @@ -442,7 +440,31 @@ void view_init(struct roots_view *view, struct roots_desktop *desktop) { wl_signal_add(&view->wlr_surface->events.new_subsurface, &view->new_subsurface); + wl_list_insert(&view->desktop->views, &view->link); + view_damage_whole(view); +} + +void view_unmap(struct roots_view *view) { + assert(view->wlr_surface != NULL); + view_damage_whole(view); + wl_list_remove(&view->link); + + wl_list_remove(&view->new_subsurface.link); + + struct roots_view_child *child, *tmp; + wl_list_for_each_safe(child, tmp, &view->children, link) { + child->destroy(child); + } + + if (view->fullscreen_output != NULL) { + output_damage_whole(view->fullscreen_output); + view->fullscreen_output->fullscreen_view = NULL; + view->fullscreen_output = NULL; + } + + view->wlr_surface = NULL; + view->width = view->height = 0; } void view_initial_focus(struct roots_view *view) { diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 899df1c6..6326d9d7 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -181,9 +181,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_surface->request_fullscreen.link); wl_list_remove(&roots_surface->set_state.link); wl_list_remove(&roots_surface->surface_commit.link); - wl_list_remove(&roots_surface->view->link); - view_finish(roots_surface->view); - free(roots_surface->view); + view_destroy(roots_surface->view); free(roots_surface); } @@ -227,7 +225,7 @@ 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(); + struct roots_view *view = view_create(desktop); if (!view) { free(roots_surface); return; @@ -238,13 +236,11 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { view->wl_shell_surface = surface; view->roots_wl_shell_surface = roots_surface; - view->wlr_surface = surface->surface; view->resize = resize; view->close = close; roots_surface->view = view; - view_init(view, desktop); - wl_list_insert(&desktop->views, &view->link); + view_map(view, surface->surface); view_setup(view); if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) { diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c index 9368ce0b..1733eb4e 100644 --- a/rootston/xdg_shell.c +++ b/rootston/xdg_shell.c @@ -287,9 +287,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->request_maximize.link); wl_list_remove(&roots_xdg_surface->request_fullscreen.link); - wl_list_remove(&roots_xdg_surface->view->link); - view_finish(roots_xdg_surface->view); - free(roots_xdg_surface->view); + view_destroy(roots_xdg_surface->view); free(roots_xdg_surface); } @@ -333,7 +331,7 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { roots_surface->new_popup.notify = handle_new_popup; wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup); - struct roots_view *view = view_create(); + struct roots_view *view = view_create(desktop); if (!view) { free(roots_surface); return; @@ -342,7 +340,6 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { view->xdg_surface = surface; view->roots_xdg_surface = roots_surface; - view->wlr_surface = surface->surface; view->activate = activate; view->resize = resize; view->move_resize = move_resize; @@ -356,8 +353,6 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { view->width = box.width; view->height = box.height; - view_init(view, desktop); - wl_list_insert(&desktop->views, &view->link); - + view_map(view, surface->surface); view_setup(view); } diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index eda349cb..c49bd911 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -287,9 +287,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->request_maximize.link); wl_list_remove(&roots_xdg_surface->request_fullscreen.link); - wl_list_remove(&roots_xdg_surface->view->link); - view_finish(roots_xdg_surface->view); - free(roots_xdg_surface->view); + view_destroy(roots_xdg_surface->view); free(roots_xdg_surface); } @@ -333,7 +331,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { roots_surface->new_popup.notify = handle_new_popup; wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup); - struct roots_view *view = view_create(); + struct roots_view *view = view_create(desktop); if (!view) { free(roots_surface); return; @@ -342,7 +340,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->xdg_surface_v6 = surface; view->roots_xdg_surface_v6 = roots_surface; - view->wlr_surface = surface->surface; view->activate = activate; view->resize = resize; view->move_resize = move_resize; @@ -356,8 +353,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->width = box.width; view->height = box.height; - view_init(view, desktop); - wl_list_insert(&desktop->views, &view->link); - + view_map(view, surface->surface); view_setup(view); } diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 56f068ea..f95e5f81 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -109,8 +109,6 @@ static void set_fullscreen(struct roots_view *view, bool fullscreen) { static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, destroy); - struct wlr_xwayland_surface *xwayland_surface = - roots_surface->view->xwayland_surface; wl_list_remove(&roots_surface->destroy.link); wl_list_remove(&roots_surface->request_configure.link); wl_list_remove(&roots_surface->request_move.link); @@ -118,11 +116,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_surface->request_maximize.link); wl_list_remove(&roots_surface->map_notify.link); wl_list_remove(&roots_surface->unmap_notify.link); - if (xwayland_surface->mapped) { - wl_list_remove(&roots_surface->view->link); - } - view_finish(roots_surface->view); - free(roots_surface->view); + view_destroy(roots_surface->view); free(roots_surface); } @@ -231,22 +225,13 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { wl_container_of(listener, roots_surface, map_notify); struct wlr_xwayland_surface *xsurface = data; struct roots_view *view = roots_surface->view; - struct roots_desktop *desktop = view->desktop; - view->wlr_surface = xsurface->surface; view->x = xsurface->x; view->y = xsurface->y; view->width = xsurface->surface->current->width; view->height = xsurface->surface->current->height; - wl_list_insert(&desktop->views, &view->link); - struct wlr_subsurface *subsurface; - wl_list_for_each(subsurface, &view->wlr_surface->subsurface_list, - parent_link) { - subsurface_create(view, subsurface); - } - - view_damage_whole(view); + view_map(view, xsurface->surface); roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&xsurface->surface->events.commit, @@ -260,22 +245,7 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { wl_list_remove(&roots_surface->surface_commit.link); - view_damage_whole(view); - - struct roots_view_child *child, *tmp; - wl_list_for_each_safe(child, tmp, &view->children, link) { - child->destroy(child); - } - - if (view->fullscreen_output != NULL) { - output_damage_whole(view->fullscreen_output); - view->fullscreen_output->fullscreen_view = NULL; - view->fullscreen_output = NULL; - } - - view->wlr_surface = NULL; - view->width = view->height = 0; - wl_list_remove(&view->link); + view_unmap(view); } void handle_xwayland_surface(struct wl_listener *listener, void *data) { @@ -317,7 +287,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { wl_signal_add(&surface->surface->events.commit, &roots_surface->surface_commit); - struct roots_view *view = view_create(); + struct roots_view *view = view_create(desktop); if (view == NULL) { free(roots_surface); return; @@ -330,7 +300,6 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->xwayland_surface = surface; view->roots_xwayland_surface = roots_surface; - view->wlr_surface = surface->surface; view->activate = activate; view->resize = resize; view->move = move; @@ -339,8 +308,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->set_fullscreen = set_fullscreen; view->close = close; roots_surface->view = view; - view_init(view, desktop); - wl_list_insert(&desktop->views, &view->link); + + view_map(view, surface->surface); if (!surface->override_redirect) { if (surface->decorations == WLR_XWAYLAND_SURFACE_DECORATIONS_ALL) { -- cgit v1.2.3 From 3f072bedd98969974ec1d3e8ffd9bae4150e52d4 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 10 Mar 2018 11:18:50 +0100 Subject: xdg-shell-v6: add map signal --- include/rootston/view.h | 2 ++ include/wlr/types/wlr_xdg_shell_v6.h | 5 +++-- rootston/desktop.c | 16 ++++++++++++--- rootston/output.c | 7 ++++++- rootston/xdg_shell_v6.c | 38 ++++++++++++++++++++++++++++-------- types/wlr_xdg_shell_v6.c | 18 +++++++++++++++-- 6 files changed, 70 insertions(+), 16 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 66a0cb3d..0844a6da 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -27,6 +27,8 @@ struct roots_xdg_surface_v6 { struct wl_listener destroy; struct wl_listener new_popup; + struct wl_listener map; + struct wl_listener unmap; struct wl_listener request_move; struct wl_listener request_resize; struct wl_listener request_maximize; diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 7dc746ce..959d420f 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -107,8 +107,7 @@ struct wlr_xdg_surface_v6 { struct wl_list popups; // wlr_xdg_popup_v6::link - bool configured; - bool added; + bool added, configured, mapped; uint32_t configure_serial; struct wl_event_source *configure_idle; uint32_t configure_next_serial; @@ -127,6 +126,8 @@ struct wlr_xdg_surface_v6 { struct wl_signal destroy; struct wl_signal ping_timeout; struct wl_signal new_popup; + struct wl_signal map; + struct wl_signal unmap; struct wl_signal request_maximize; struct wl_signal request_fullscreen; diff --git a/rootston/desktop.c b/rootston/desktop.c index 66c7ac2b..278f4fea 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -54,7 +54,8 @@ void view_get_deco_box(const struct roots_view *view, struct wlr_box *box) { box->height += (view->border_width * 2 + view->titlebar_height); } -enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx, double sy) { +enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx, + double sy) { if (!view->decorated) { return ROOTS_DECO_PART_NONE; } @@ -94,9 +95,15 @@ enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx, doub static void view_update_output(const struct roots_view *view, const struct wlr_box *before) { struct roots_desktop *desktop = view->desktop; - struct roots_output *output; + + if (view->wlr_surface == NULL) { + return; + } + struct wlr_box box; view_get_box(view, &box); + + struct roots_output *output; wl_list_for_each(output, &desktop->outputs, link) { bool intersected = before != NULL && wlr_output_layout_intersects( desktop->layout, output->wlr_output, before); @@ -479,7 +486,10 @@ void view_initial_focus(struct roots_view *view) { void view_setup(struct roots_view *view) { view_initial_focus(view); - view_center(view); + if (view->fullscreen_output == NULL) { + view_center(view); + } + view_update_output(view, NULL); } diff --git a/rootston/output.c b/rootston/output.c index 4d0a9c05..adcbb961 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -501,7 +501,9 @@ static void render_output(struct roots_output *output) { goto renderer_end; } - view_for_each_surface(view, render_surface, &data); + if (view->wlr_surface != NULL) { + view_for_each_surface(view, render_surface, &data); + } // During normal rendering the xwayland window tree isn't traversed // because all windows are rendered. Here we only want to render @@ -570,6 +572,9 @@ void output_damage_whole(struct roots_output *output) { static bool view_accept_damage(struct roots_output *output, struct roots_view *view) { + if (view->wlr_surface == NULL) { + return false; + } if (output->fullscreen_view == NULL) { return true; } diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index c49bd911..4591f642 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -243,6 +243,10 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + if (!surface->mapped) { + return; + } + view_apply_damage(view); struct wlr_box size; @@ -277,6 +281,28 @@ static void handle_new_popup(struct wl_listener *listener, void *data) { popup_create(roots_xdg_surface->view, wlr_popup); } +static void handle_map(struct wl_listener *listener, void *data) { + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, map); + struct roots_view *view = roots_xdg_surface->view; + + struct wlr_box box; + get_size(view, &box); + view->width = box.width; + view->height = box.height; + + view_map(view, view->xdg_surface_v6->surface); + view_setup(view); +} + +static void handle_unmap(struct wl_listener *listener, void *data) { + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, unmap); + struct roots_view *view = roots_xdg_surface->view; + + view_unmap(view); +} + 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); @@ -317,6 +343,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { &roots_surface->surface_commit); roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); + roots_surface->map.notify = handle_map; + wl_signal_add(&surface->events.map, &roots_surface->map); + roots_surface->unmap.notify = handle_unmap; + wl_signal_add(&surface->events.unmap, &roots_surface->unmap); roots_surface->request_move.notify = handle_request_move; wl_signal_add(&surface->events.request_move, &roots_surface->request_move); roots_surface->request_resize.notify = handle_request_resize; @@ -347,12 +377,4 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->set_fullscreen = set_fullscreen; view->close = close; roots_surface->view = view; - - struct wlr_box box; - get_size(view, &box); - view->width = box.width; - view->height = box.height; - - view_map(view, surface->surface); - view_setup(view); } diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index e07d78a1..18f7393d 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -481,6 +481,7 @@ static void xdg_popup_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_popup_resource(resource); if (surface != NULL) { + // TODO: don't destroy the surface, unmap it xdg_surface_destroy(surface); } } @@ -792,6 +793,7 @@ static void xdg_toplevel_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); if (surface != NULL) { + // TODO: don't destroy the surface, unmap it xdg_surface_destroy(surface); } } @@ -1172,9 +1174,19 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, break; } - if (surface->configured && !surface->added) { + if (!surface->added) { surface->added = true; - wlr_signal_emit_safe(&surface->client->shell->events.new_surface, surface); + wlr_signal_emit_safe(&surface->client->shell->events.new_surface, + surface); + } + if (surface->configured && wlr_surface_has_buffer(surface->surface) && + !surface->mapped) { + surface->mapped = true; + wlr_signal_emit_safe(&surface->events.map, surface); + } + if (surface->configured && !wlr_surface_has_buffer(surface->surface) && + surface->mapped) { + // TODO: unmap the surface } } @@ -1249,6 +1261,8 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.ping_timeout); wl_signal_init(&surface->events.new_popup); + wl_signal_init(&surface->events.map); + wl_signal_init(&surface->events.unmap); wl_signal_add(&surface->surface->events.destroy, &surface->surface_destroy_listener); -- cgit v1.2.3 From 1f8854f2172b124572f53976b9067fc4ef33a8a1 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 12 Mar 2018 09:00:59 +0100 Subject: rootston: remove xdg-shell-v6 map/unmap listeners on destroy --- rootston/xdg_shell_v6.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 4591f642..12e22afb 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -309,6 +309,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_xdg_surface->surface_commit.link); wl_list_remove(&roots_xdg_surface->destroy.link); wl_list_remove(&roots_xdg_surface->new_popup.link); + wl_list_remove(&roots_xdg_surface->map.link); + wl_list_remove(&roots_xdg_surface->unmap.link); wl_list_remove(&roots_xdg_surface->request_move.link); wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->request_maximize.link); -- cgit v1.2.3 From 6ac3534df6ce1ac35932fb71584675d32507fed7 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 12 Mar 2018 09:17:06 +0100 Subject: rootston: add destroy to view interface --- include/rootston/view.h | 1 + rootston/desktop.c | 4 ++++ rootston/wl_shell.c | 22 ++++++++++++++-------- rootston/xdg_shell.c | 21 +++++++++++++-------- rootston/xdg_shell_v6.c | 30 +++++++++++++++++------------- rootston/xwayland.c | 14 ++++++++++---- 6 files changed, 59 insertions(+), 33 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 0844a6da..1e5c0933 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -142,6 +142,7 @@ struct roots_view { void (*maximize)(struct roots_view *view, bool maximized); void (*set_fullscreen)(struct roots_view *view, bool fullscreen); void (*close)(struct roots_view *view); + void (*destroy)(struct roots_view *view); }; struct roots_view_child { diff --git a/rootston/desktop.c b/rootston/desktop.c index 278f4fea..19b7768c 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -422,6 +422,10 @@ void view_destroy(struct roots_view *view) { wl_signal_emit(&view->events.destroy, view); + if (view->destroy) { + view->destroy(view); + } + free(view); } diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 6326d9d7..d58f030a 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -78,6 +78,19 @@ static void close(struct roots_view *view) { 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; + wl_list_remove(&roots_surface->destroy.link); + wl_list_remove(&roots_surface->request_move.link); + wl_list_remove(&roots_surface->request_resize.link); + wl_list_remove(&roots_surface->request_maximize.link); + wl_list_remove(&roots_surface->request_fullscreen.link); + wl_list_remove(&roots_surface->set_state.link); + wl_list_remove(&roots_surface->surface_commit.link); + free(roots_surface); +} + 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); @@ -174,15 +187,7 @@ static void handle_new_popup(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, destroy); - wl_list_remove(&roots_surface->destroy.link); - wl_list_remove(&roots_surface->request_move.link); - wl_list_remove(&roots_surface->request_resize.link); - wl_list_remove(&roots_surface->request_maximize.link); - wl_list_remove(&roots_surface->request_fullscreen.link); - wl_list_remove(&roots_surface->set_state.link); - wl_list_remove(&roots_surface->surface_commit.link); view_destroy(roots_surface->view); - free(roots_surface); } void handle_wl_shell_surface(struct wl_listener *listener, void *data) { @@ -238,6 +243,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { view->roots_wl_shell_surface = roots_surface; view->resize = resize; view->close = close; + view->destroy = destroy; roots_surface->view = view; view_map(view, surface->surface); diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c index 1733eb4e..24c57bd5 100644 --- a/rootston/xdg_shell.c +++ b/rootston/xdg_shell.c @@ -180,6 +180,18 @@ static void close(struct roots_view *view) { } } +static void destroy(struct roots_view *view) { + struct roots_xdg_surface *roots_xdg_surface = view->roots_xdg_surface; + wl_list_remove(&roots_xdg_surface->surface_commit.link); + wl_list_remove(&roots_xdg_surface->destroy.link); + wl_list_remove(&roots_xdg_surface->new_popup.link); + wl_list_remove(&roots_xdg_surface->request_move.link); + wl_list_remove(&roots_xdg_surface->request_resize.link); + wl_list_remove(&roots_xdg_surface->request_maximize.link); + wl_list_remove(&roots_xdg_surface->request_fullscreen.link); + free(roots_xdg_surface); +} + static void handle_request_move(struct wl_listener *listener, void *data) { struct roots_xdg_surface *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, request_move); @@ -280,15 +292,7 @@ static void handle_new_popup(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xdg_surface *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, destroy); - wl_list_remove(&roots_xdg_surface->surface_commit.link); - wl_list_remove(&roots_xdg_surface->destroy.link); - wl_list_remove(&roots_xdg_surface->new_popup.link); - wl_list_remove(&roots_xdg_surface->request_move.link); - wl_list_remove(&roots_xdg_surface->request_resize.link); - wl_list_remove(&roots_xdg_surface->request_maximize.link); - wl_list_remove(&roots_xdg_surface->request_fullscreen.link); view_destroy(roots_xdg_surface->view); - free(roots_xdg_surface); } void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { @@ -346,6 +350,7 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { view->maximize = maximize; view->set_fullscreen = set_fullscreen; view->close = close; + view->destroy = destroy; roots_surface->view = view; struct wlr_box box; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 12e22afb..1f6f25eb 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -180,6 +180,21 @@ static void close(struct roots_view *view) { } } +static void destroy(struct roots_view *view) { + assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); + struct roots_xdg_surface_v6 *roots_xdg_surface = view->roots_xdg_surface_v6; + wl_list_remove(&roots_xdg_surface->surface_commit.link); + wl_list_remove(&roots_xdg_surface->destroy.link); + wl_list_remove(&roots_xdg_surface->new_popup.link); + wl_list_remove(&roots_xdg_surface->map.link); + wl_list_remove(&roots_xdg_surface->unmap.link); + wl_list_remove(&roots_xdg_surface->request_move.link); + wl_list_remove(&roots_xdg_surface->request_resize.link); + wl_list_remove(&roots_xdg_surface->request_maximize.link); + wl_list_remove(&roots_xdg_surface->request_fullscreen.link); + free(roots_xdg_surface); +} + static void handle_request_move(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, request_move); @@ -298,25 +313,13 @@ static void handle_map(struct wl_listener *listener, void *data) { static void handle_unmap(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, unmap); - struct roots_view *view = roots_xdg_surface->view; - - view_unmap(view); + view_unmap(roots_xdg_surface->view); } 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); - wl_list_remove(&roots_xdg_surface->surface_commit.link); - wl_list_remove(&roots_xdg_surface->destroy.link); - wl_list_remove(&roots_xdg_surface->new_popup.link); - wl_list_remove(&roots_xdg_surface->map.link); - wl_list_remove(&roots_xdg_surface->unmap.link); - wl_list_remove(&roots_xdg_surface->request_move.link); - wl_list_remove(&roots_xdg_surface->request_resize.link); - wl_list_remove(&roots_xdg_surface->request_maximize.link); - wl_list_remove(&roots_xdg_surface->request_fullscreen.link); view_destroy(roots_xdg_surface->view); - free(roots_xdg_surface); } void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { @@ -378,5 +381,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->maximize = maximize; view->set_fullscreen = set_fullscreen; view->close = close; + view->destroy = destroy; roots_surface->view = view; } diff --git a/rootston/xwayland.c b/rootston/xwayland.c index f95e5f81..53331b1f 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -106,9 +106,9 @@ static void set_fullscreen(struct roots_view *view, bool fullscreen) { wlr_xwayland_surface_set_fullscreen(view->xwayland_surface, fullscreen); } -static void handle_destroy(struct wl_listener *listener, void *data) { - struct roots_xwayland_surface *roots_surface = - wl_container_of(listener, roots_surface, destroy); +static void destroy(struct roots_view *view) { + assert(view->type == ROOTS_XWAYLAND_VIEW); + struct roots_xwayland_surface *roots_surface = view->roots_xwayland_surface; wl_list_remove(&roots_surface->destroy.link); wl_list_remove(&roots_surface->request_configure.link); wl_list_remove(&roots_surface->request_move.link); @@ -116,10 +116,15 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_surface->request_maximize.link); wl_list_remove(&roots_surface->map_notify.link); wl_list_remove(&roots_surface->unmap_notify.link); - view_destroy(roots_surface->view); free(roots_surface); } +static void handle_destroy(struct wl_listener *listener, void *data) { + struct roots_xwayland_surface *roots_surface = + wl_container_of(listener, roots_surface, destroy); + view_destroy(roots_surface->view); +} + static void handle_request_configure(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, request_configure); @@ -307,6 +312,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->maximize = maximize; view->set_fullscreen = set_fullscreen; view->close = close; + view->destroy = destroy; roots_surface->view = view; view_map(view, surface->surface); -- cgit v1.2.3 From adec3f5c0fec7cc3aae5c68128d23dfe24950fb3 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 12 Mar 2018 10:41:57 +0100 Subject: xdg-shell-v6: add unmap support, add more protocol errors --- types/wlr_xdg_shell_v6.c | 237 +++++++++++++++++++++++++++++------------------ 1 file changed, 148 insertions(+), 89 deletions(-) diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 18f7393d..5da25f62 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -34,7 +34,7 @@ struct wlr_xdg_positioner_v6 { }; -static void resource_destroy(struct wl_client *client, +static void resource_handle_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); } @@ -159,22 +159,16 @@ static struct wlr_xdg_popup_grab_v6 *xdg_shell_popup_grab_from_seat( } -static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { - // TODO: probably need to ungrab before this event - wlr_signal_emit_safe(&surface->events.destroy, surface); +static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { + assert(surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE); - if (surface->configure_idle) { - wl_event_source_remove(surface->configure_idle); - } - - struct wlr_xdg_surface_v6_configure *configure, *tmp; - wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { - free(configure); - } + // TODO: probably need to ungrab before this event + wlr_signal_emit_safe(&surface->events.unmap, surface); if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { wl_resource_set_user_data(surface->toplevel_state->resource, NULL); free(surface->toplevel_state); + surface->toplevel_state = NULL; } if (surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) { @@ -185,16 +179,6 @@ static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { xdg_shell_popup_grab_from_seat(surface->client->shell, surface->popup_state->seat); - struct wlr_xdg_surface_v6 *topmost = - xdg_popup_grab_get_topmost(grab); - - if (topmost != surface) { - wl_resource_post_error(surface->client->resource, - ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP, - "xdg_popup was destroyed while it was not the topmost " - "popup."); - } - wl_list_remove(&surface->popup_state->grab_link); if (wl_list_empty(&grab->popups)) { @@ -209,16 +193,47 @@ static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { wl_list_remove(&surface->popup_state->link); free(surface->popup_state); + surface->popup_state = NULL; + } + + surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE; + free(surface->title); + surface->title = NULL; + free(surface->app_id); + surface->app_id = NULL; + + surface->added = surface->configured = surface->mapped = false; + surface->configure_serial = 0; + if (surface->configure_idle) { + wl_event_source_remove(surface->configure_idle); + surface->configure_idle = NULL; + } + surface->configure_next_serial = 0; + + struct wlr_xdg_surface_v6_configure *configure, *tmp; + wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { + wl_list_remove(&configure->link); + free(configure); } + surface->has_next_geometry = false; + memset(surface->geometry, 0, sizeof(struct wlr_box)); + memset(surface->next_geometry, 0, sizeof(struct wlr_box)); +} + +static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { + if (surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE) { + xdg_surface_unmap(surface); + } + + wlr_signal_emit_safe(&surface->events.destroy, surface); + wl_resource_set_user_data(surface->resource, NULL); wl_list_remove(&surface->link); wl_list_remove(&surface->surface_destroy_listener.link); wlr_surface_set_role_committed(surface->surface, NULL, NULL); free(surface->geometry); free(surface->next_geometry); - free(surface->title); - free(surface->app_id); free(surface); } @@ -237,10 +252,9 @@ static void xdg_positioner_destroy(struct wl_resource *resource) { struct wlr_xdg_positioner_v6 *positioner = xdg_positioner_from_resource(resource); free(positioner); - } -static void xdg_positioner_protocol_set_size(struct wl_client *client, +static void xdg_positioner_handle_set_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_positioner_v6 *positioner = xdg_positioner_from_resource(resource); @@ -256,7 +270,7 @@ static void xdg_positioner_protocol_set_size(struct wl_client *client, positioner->size.height = height; } -static void xdg_positioner_protocol_set_anchor_rect(struct wl_client *client, +static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) { struct wlr_xdg_positioner_v6 *positioner = @@ -275,7 +289,7 @@ static void xdg_positioner_protocol_set_anchor_rect(struct wl_client *client, positioner->anchor_rect.height = height; } -static void xdg_positioner_protocol_set_anchor(struct wl_client *client, +static void xdg_positioner_handle_set_anchor(struct wl_client *client, struct wl_resource *resource, uint32_t anchor) { struct wlr_xdg_positioner_v6 *positioner = xdg_positioner_from_resource(resource); @@ -293,7 +307,7 @@ static void xdg_positioner_protocol_set_anchor(struct wl_client *client, positioner->anchor = anchor; } -static void xdg_positioner_protocol_set_gravity(struct wl_client *client, +static void xdg_positioner_handle_set_gravity(struct wl_client *client, struct wl_resource *resource, uint32_t gravity) { struct wlr_xdg_positioner_v6 *positioner = xdg_positioner_from_resource(resource); @@ -311,7 +325,7 @@ static void xdg_positioner_protocol_set_gravity(struct wl_client *client, positioner->gravity = gravity; } -static void xdg_positioner_protocol_set_constraint_adjustment( +static void xdg_positioner_handle_set_constraint_adjustment( struct wl_client *client, struct wl_resource *resource, uint32_t constraint_adjustment) { struct wlr_xdg_positioner_v6 *positioner = @@ -320,7 +334,7 @@ static void xdg_positioner_protocol_set_constraint_adjustment( positioner->constraint_adjustment = constraint_adjustment; } -static void xdg_positioner_protocol_set_offset(struct wl_client *client, +static void xdg_positioner_handle_set_offset(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y) { struct wlr_xdg_positioner_v6 *positioner = xdg_positioner_from_resource(resource); @@ -331,17 +345,17 @@ static void xdg_positioner_protocol_set_offset(struct wl_client *client, static const struct zxdg_positioner_v6_interface zxdg_positioner_v6_implementation = { - .destroy = resource_destroy, - .set_size = xdg_positioner_protocol_set_size, - .set_anchor_rect = xdg_positioner_protocol_set_anchor_rect, - .set_anchor = xdg_positioner_protocol_set_anchor, - .set_gravity = xdg_positioner_protocol_set_gravity, + .destroy = resource_handle_destroy, + .set_size = xdg_positioner_handle_set_size, + .set_anchor_rect = xdg_positioner_handle_set_anchor_rect, + .set_anchor = xdg_positioner_handle_set_anchor, + .set_gravity = xdg_positioner_handle_set_gravity, .set_constraint_adjustment = - xdg_positioner_protocol_set_constraint_adjustment, - .set_offset = xdg_positioner_protocol_set_offset, + xdg_positioner_handle_set_constraint_adjustment, + .set_offset = xdg_positioner_handle_set_offset, }; -static void xdg_shell_create_positioner(struct wl_client *wl_client, +static void xdg_shell_handle_create_positioner(struct wl_client *wl_client, struct wl_resource *resource, uint32_t id) { struct wlr_xdg_positioner_v6 *positioner = calloc(1, sizeof(struct wlr_xdg_positioner_v6)); @@ -430,7 +444,7 @@ static struct wlr_xdg_surface_v6 *xdg_surface_from_xdg_popup_resource( return wl_resource_get_user_data(resource); } -static void xdg_popup_protocol_grab(struct wl_client *client, +static void xdg_popup_handle_grab(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { struct wlr_xdg_surface_v6 *surface = @@ -472,17 +486,37 @@ static void xdg_popup_protocol_grab(struct wl_client *client, &popup_grab->keyboard_grab); } +static void xdg_popup_handle_destroy(struct wl_client *client, + struct wl_resource *resource) { + struct wlr_xdg_surface_v6 *surface = + xdg_surface_from_xdg_popup_resource(resource); + struct wlr_xdg_popup_grab_v6 *grab = + xdg_shell_popup_grab_from_seat(surface->client->shell, + surface->popup_state->seat); + struct wlr_xdg_surface_v6 *topmost = + xdg_popup_grab_get_topmost(grab); + + if (topmost != surface) { + wl_resource_post_error(surface->client->resource, + ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP, + "xdg_popup was destroyed while it was not the topmost " + "popup"); + return; + } + + wl_resource_destroy(resource); +} + static const struct zxdg_popup_v6_interface zxdg_popup_v6_implementation = { - .destroy = resource_destroy, - .grab = xdg_popup_protocol_grab, + .destroy = xdg_popup_handle_destroy, + .grab = xdg_popup_handle_grab, }; static void xdg_popup_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_popup_resource(resource); if (surface != NULL) { - // TODO: don't destroy the surface, unmap it - xdg_surface_destroy(surface); + xdg_surface_unmap(surface); } } @@ -495,7 +529,7 @@ static struct wlr_xdg_surface_v6 *xdg_surface_from_resource( return wl_resource_get_user_data(resource); } -static void xdg_surface_get_popup(struct wl_client *client, +static void xdg_surface_handle_get_popup(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *parent_resource, struct wl_resource *positioner_resource) { @@ -557,7 +591,7 @@ static struct wlr_xdg_surface_v6 *xdg_surface_from_xdg_toplevel_resource( return wl_resource_get_user_data(resource); } -static void xdg_toplevel_protocol_set_parent(struct wl_client *client, +static void xdg_toplevel_handle_set_parent(struct wl_client *client, struct wl_resource *resource, struct wl_resource *parent_resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -570,7 +604,7 @@ static void xdg_toplevel_protocol_set_parent(struct wl_client *client, surface->toplevel_state->parent = parent; } -static void xdg_toplevel_protocol_set_title(struct wl_client *client, +static void xdg_toplevel_handle_set_title(struct wl_client *client, struct wl_resource *resource, const char *title) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -584,7 +618,7 @@ static void xdg_toplevel_protocol_set_title(struct wl_client *client, surface->title = tmp; } -static void xdg_toplevel_protocol_set_app_id(struct wl_client *client, +static void xdg_toplevel_handle_set_app_id(struct wl_client *client, struct wl_resource *resource, const char *app_id) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -598,7 +632,7 @@ static void xdg_toplevel_protocol_set_app_id(struct wl_client *client, surface->app_id = tmp; } -static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client, +static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, int32_t x, int32_t y) { struct wlr_xdg_surface_v6 *surface = @@ -629,7 +663,7 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_show_window_menu, &event); } -static void xdg_toplevel_protocol_move(struct wl_client *client, +static void xdg_toplevel_handle_move(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { struct wlr_xdg_surface_v6 *surface = @@ -658,7 +692,7 @@ static void xdg_toplevel_protocol_move(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_move, &event); } -static void xdg_toplevel_protocol_resize(struct wl_client *client, +static void xdg_toplevel_handle_resize(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, uint32_t edges) { struct wlr_xdg_surface_v6 *surface = @@ -688,7 +722,7 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_resize, &event); } -static void xdg_toplevel_protocol_set_max_size(struct wl_client *client, +static void xdg_toplevel_handle_set_max_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -696,7 +730,7 @@ static void xdg_toplevel_protocol_set_max_size(struct wl_client *client, surface->toplevel_state->next.max_height = height; } -static void xdg_toplevel_protocol_set_min_size(struct wl_client *client, +static void xdg_toplevel_handle_set_min_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -704,7 +738,7 @@ static void xdg_toplevel_protocol_set_min_size(struct wl_client *client, surface->toplevel_state->next.min_height = height; } -static void xdg_toplevel_protocol_set_maximized(struct wl_client *client, +static void xdg_toplevel_handle_set_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -712,7 +746,7 @@ static void xdg_toplevel_protocol_set_maximized(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_maximize, surface); } -static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client, +static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -720,7 +754,7 @@ static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_maximize, surface); } -static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, +static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, struct wl_resource *resource, struct wl_resource *output_resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -741,7 +775,7 @@ static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); } -static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client, +static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -757,7 +791,7 @@ static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); } -static void xdg_toplevel_protocol_set_minimized(struct wl_client *client, +static void xdg_toplevel_handle_set_minimized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -766,20 +800,20 @@ static void xdg_toplevel_protocol_set_minimized(struct wl_client *client, static const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation = { - .destroy = resource_destroy, - .set_parent = xdg_toplevel_protocol_set_parent, - .set_title = xdg_toplevel_protocol_set_title, - .set_app_id = xdg_toplevel_protocol_set_app_id, - .show_window_menu = xdg_toplevel_protocol_show_window_menu, - .move = xdg_toplevel_protocol_move, - .resize = xdg_toplevel_protocol_resize, - .set_max_size = xdg_toplevel_protocol_set_max_size, - .set_min_size = xdg_toplevel_protocol_set_min_size, - .set_maximized = xdg_toplevel_protocol_set_maximized, - .unset_maximized = xdg_toplevel_protocol_unset_maximized, - .set_fullscreen = xdg_toplevel_protocol_set_fullscreen, - .unset_fullscreen = xdg_toplevel_protocol_unset_fullscreen, - .set_minimized = xdg_toplevel_protocol_set_minimized + .destroy = resource_handle_destroy, + .set_parent = xdg_toplevel_handle_set_parent, + .set_title = xdg_toplevel_handle_set_title, + .set_app_id = xdg_toplevel_handle_set_app_id, + .show_window_menu = xdg_toplevel_handle_show_window_menu, + .move = xdg_toplevel_handle_move, + .resize = xdg_toplevel_handle_resize, + .set_max_size = xdg_toplevel_handle_set_max_size, + .set_min_size = xdg_toplevel_handle_set_min_size, + .set_maximized = xdg_toplevel_handle_set_maximized, + .unset_maximized = xdg_toplevel_handle_unset_maximized, + .set_fullscreen = xdg_toplevel_handle_set_fullscreen, + .unset_fullscreen = xdg_toplevel_handle_unset_fullscreen, + .set_minimized = xdg_toplevel_handle_set_minimized }; static void xdg_surface_resource_destroy(struct wl_resource *resource) { @@ -793,12 +827,11 @@ static void xdg_toplevel_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); if (surface != NULL) { - // TODO: don't destroy the surface, unmap it - xdg_surface_destroy(surface); + xdg_surface_unmap(surface); } } -static void xdg_surface_get_toplevel(struct wl_client *client, +static void xdg_surface_handle_get_toplevel(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource); @@ -840,7 +873,7 @@ static void wlr_xdg_toplevel_v6_ack_configure( surface->toplevel_state->pending.height = 0; } -static void xdg_surface_ack_configure(struct wl_client *client, +static void xdg_surface_handle_ack_configure(struct wl_client *client, struct wl_resource *resource, uint32_t serial) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource); @@ -889,7 +922,7 @@ static void xdg_surface_ack_configure(struct wl_client *client, free(configure); } -static void xdg_surface_set_window_geometry(struct wl_client *client, +static void xdg_surface_handle_set_window_geometry(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource); @@ -906,15 +939,27 @@ static void xdg_surface_set_window_geometry(struct wl_client *client, surface->next_geometry->width = width; surface->next_geometry->x = x; surface->next_geometry->y = y; +} +static void xdg_surface_handle_destroy(struct wl_client *client, + struct wl_resource *resource) { + struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource); + + if (surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE) { + wlr_log(L_ERROR, "Tried to destroy an xdg_surface before its role " + "object"); + return; + } + + wl_resource_destroy(resource); } static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation = { - .destroy = resource_destroy, - .get_toplevel = xdg_surface_get_toplevel, - .get_popup = xdg_surface_get_popup, - .ack_configure = xdg_surface_ack_configure, - .set_window_geometry = xdg_surface_set_window_geometry, + .destroy = xdg_surface_handle_destroy, + .get_toplevel = xdg_surface_handle_get_toplevel, + .get_popup = xdg_surface_handle_get_popup, + .ack_configure = xdg_surface_handle_ack_configure, + .set_window_geometry = xdg_surface_handle_set_window_geometry, }; static bool wlr_xdg_surface_v6_toplevel_state_compare( @@ -1186,7 +1231,7 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, } if (surface->configured && !wlr_surface_has_buffer(surface->surface) && surface->mapped) { - // TODO: unmap the surface + xdg_surface_unmap(surface); } } @@ -1199,7 +1244,7 @@ static struct wlr_xdg_client_v6 *xdg_client_from_resource( return wl_resource_get_user_data(resource); } -static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, +static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client, struct wl_resource *client_resource, uint32_t id, struct wl_resource *surface_resource) { struct wlr_xdg_client_v6 *client = @@ -1277,7 +1322,7 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, wl_list_insert(&client->surfaces, &surface->link); } -static void xdg_shell_pong(struct wl_client *wl_client, +static void xdg_shell_handle_pong(struct wl_client *wl_client, struct wl_resource *resource, uint32_t serial) { struct wlr_xdg_client_v6 *client = xdg_client_from_resource(resource); @@ -1289,11 +1334,25 @@ static void xdg_shell_pong(struct wl_client *wl_client, client->ping_serial = 0; } +static void xdg_shell_handle_destroy(struct wl_client *wl_client, + struct wl_resource *resource) { + struct wlr_xdg_client_v6 *client = xdg_client_from_resource(resource); + + if (!wl_list_empty(&client->surfaces)) { + wl_resource_post_error(client->resource, + ZXDG_SHELL_V6_ERROR_DEFUNCT_SURFACES, + "xdg_wm_base was destroyed before children"); + return; + } + + wl_resource_destroy(resource); +} + static const struct zxdg_shell_v6_interface xdg_shell_impl = { - .destroy = resource_destroy, - .create_positioner = xdg_shell_create_positioner, - .get_xdg_surface = xdg_shell_get_xdg_surface, - .pong = xdg_shell_pong, + .destroy = xdg_shell_handle_destroy, + .create_positioner = xdg_shell_handle_create_positioner, + .get_xdg_surface = xdg_shell_handle_get_xdg_surface, + .pong = xdg_shell_handle_pong, }; static void wlr_xdg_client_v6_destroy(struct wl_resource *resource) { -- cgit v1.2.3 From 42637a52cf2779ec05f0fdb97df416e21438a77b Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 12 Mar 2018 10:42:41 +0100 Subject: rootston: don't segfault when getting size of an unmapped xdg-shell view --- rootston/xdg_shell_v6.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 1f6f25eb..c81cd16a 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -63,9 +63,11 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) { if (surface->geometry->width > 0 && surface->geometry->height > 0) { box->width = surface->geometry->width; box->height = surface->geometry->height; - } else { + } else if (view->wlr_surface != NULL) { box->width = view->wlr_surface->current->width; box->height = view->wlr_surface->current->height; + } else { + box->width = box->height = 0; } } -- cgit v1.2.3 From c1c88bfe5d88b7f6330f5ce5be04ef6951123c3d Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 13 Mar 2018 12:31:45 +0100 Subject: rootston: destroy seat view on unmap --- include/rootston/seat.h | 1 + include/rootston/view.h | 1 + rootston/desktop.c | 1 + rootston/seat.c | 9 +++++++++ 4 files changed, 12 insertions(+) diff --git a/include/rootston/seat.h b/include/rootston/seat.h index cc0293b5..0b1dbe2d 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -39,6 +39,7 @@ struct roots_seat_view { struct wl_list link; // roots_seat::views + struct wl_listener view_unmap; struct wl_listener view_destroy; }; diff --git a/include/rootston/view.h b/include/rootston/view.h index 1e5c0933..92d1feb5 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -130,6 +130,7 @@ struct roots_view { struct wl_listener new_subsurface; struct { + struct wl_signal unmap; struct wl_signal destroy; } events; diff --git a/rootston/desktop.c b/rootston/desktop.c index 19b7768c..afe2c221 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -30,6 +30,7 @@ struct roots_view *view_create(struct roots_desktop *desktop) { } view->desktop = desktop; view->alpha = 1.0f; + wl_signal_init(&view->events.unmap); wl_signal_init(&view->events.destroy); wl_list_init(&view->children); return view; diff --git a/rootston/seat.c b/rootston/seat.c index 9acbb737..c4535c7c 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -645,6 +645,7 @@ static void seat_view_destroy(struct roots_seat_view *seat_view) { seat->cursor->pointer_view = NULL; } + wl_list_remove(&seat_view->view_unmap.link); wl_list_remove(&seat_view->view_destroy.link); wl_list_remove(&seat_view->link); free(seat_view); @@ -657,6 +658,12 @@ static void seat_view_destroy(struct roots_seat_view *seat_view) { } } +static void seat_view_handle_unmap(struct wl_listener *listener, void *data) { + struct roots_seat_view *seat_view = + wl_container_of(listener, seat_view, view_unmap); + seat_view_destroy(seat_view); +} + static void seat_view_handle_destroy(struct wl_listener *listener, void *data) { struct roots_seat_view *seat_view = wl_container_of(listener, seat_view, view_destroy); @@ -675,6 +682,8 @@ static struct roots_seat_view *seat_add_view(struct roots_seat *seat, wl_list_insert(seat->views.prev, &seat_view->link); + seat_view->view_unmap.notify = seat_view_handle_unmap; + wl_signal_add(&view->events.unmap, &seat_view->view_unmap); seat_view->view_destroy.notify = seat_view_handle_destroy; wl_signal_add(&view->events.destroy, &seat_view->view_destroy); -- cgit v1.2.3 From 125138f1a0448927c26c0f8a2761fed2df09b6ad Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 13 Mar 2018 12:34:29 +0100 Subject: rootston: unmap view after emitting destroy signal in view_destroy --- rootston/desktop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index afe2c221..b1e6f874 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -417,12 +417,12 @@ void view_destroy(struct roots_view *view) { return; } + wl_signal_emit(&view->events.destroy, view); + if (view->wlr_surface != NULL) { view_unmap(view); } - wl_signal_emit(&view->events.destroy, view); - if (view->destroy) { view->destroy(view); } -- cgit v1.2.3 From e74ddaaf10f1c8078cf078f55428b9e86776ca93 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 13 Mar 2018 19:57:21 +0100 Subject: xdg-shell-v6: redesign the configure/ack_configure workflow --- include/wlr/types/wlr_xdg_shell_v6.h | 23 ++++++++-------------- rootston/output.c | 3 ++- rootston/xdg_shell_v6.c | 7 +++++++ types/wlr_xdg_shell_v6.c | 38 +++++++++++++++++++++++------------- 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 959d420f..86a42181 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -62,19 +62,10 @@ enum wlr_xdg_surface_v6_role { }; struct wlr_xdg_toplevel_v6_state { - bool maximized; - bool fullscreen; - bool resizing; - bool activated; - - uint32_t width; - uint32_t height; - - uint32_t max_width; - uint32_t max_height; - - uint32_t min_width; - uint32_t min_height; + bool maximized, fullscreen, resizing, activated; + uint32_t width, height; + uint32_t max_width, max_height; + uint32_t min_width, min_height; }; struct wlr_xdg_toplevel_v6 { @@ -90,7 +81,8 @@ struct wlr_xdg_toplevel_v6 { struct wlr_xdg_surface_v6_configure { struct wl_list link; // wlr_xdg_surface_v6::configure_list uint32_t serial; - struct wlr_xdg_toplevel_v6_state state; + + struct wlr_xdg_toplevel_v6_state toplevel_state; // TODO: should be null-able }; struct wlr_xdg_surface_v6 { @@ -100,6 +92,7 @@ struct wlr_xdg_surface_v6 { struct wl_list link; // wlr_xdg_client_v6::surfaces enum wlr_xdg_surface_v6_role role; + // TODO: the _state prefix should be dropped union { struct wlr_xdg_toplevel_v6 *toplevel_state; struct wlr_xdg_popup_v6 *popup_state; @@ -118,7 +111,7 @@ struct wlr_xdg_surface_v6 { bool has_next_geometry; struct wlr_box *next_geometry; - struct wlr_box *geometry; + struct wlr_box *geometry; // TODO: should not be a pointer struct wl_listener surface_destroy_listener; diff --git a/rootston/output.c b/rootston/output.c index adcbb961..f772ea24 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -433,7 +433,8 @@ static void render_output(struct roots_output *output) { float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f}; // Check if we can delegate the fullscreen surface to the output - if (output->fullscreen_view != NULL) { + if (output->fullscreen_view != NULL && + output->fullscreen_view->wlr_surface != NULL) { struct roots_view *view = output->fullscreen_view; // Make sure the view is centered on screen diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index c81cd16a..84c76d16 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -385,4 +385,11 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->close = close; view->destroy = destroy; roots_surface->view = view; + + if (surface->toplevel_state->next.maximized) { + view_maximize(view, true); + } + if (surface->toplevel_state->next.fullscreen) { + view_set_fullscreen(view, true, NULL); + } } diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 5da25f62..8c2e9d58 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -868,9 +868,15 @@ static void wlr_xdg_toplevel_v6_ack_configure( struct wlr_xdg_surface_v6 *surface, struct wlr_xdg_surface_v6_configure *configure) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->next = configure->state; - surface->toplevel_state->pending.width = 0; - surface->toplevel_state->pending.height = 0; + + surface->toplevel_state->current.maximized = + configure->toplevel_state.maximized; + surface->toplevel_state->current.fullscreen = + configure->toplevel_state.fullscreen; + surface->toplevel_state->current.resizing = + configure->toplevel_state.resizing; + surface->toplevel_state->current.activated = + configure->toplevel_state.activated; } static void xdg_surface_handle_ack_configure(struct wl_client *client, @@ -982,9 +988,9 @@ static bool wlr_xdg_surface_v6_toplevel_state_compare( } else { struct wlr_xdg_surface_v6_configure *configure = wl_container_of(state->base->configure_list.prev, configure, link); - configured.state = configure->state; - configured.width = configure->state.width; - configured.height = configure->state.height; + configured.state = configure->toplevel_state; + configured.width = configure->toplevel_state.width; + configured.height = configure->toplevel_state.height; } if (state->pending.activated != configured.state.activated) { @@ -1019,7 +1025,7 @@ static void wlr_xdg_toplevel_v6_send_configure( uint32_t *s; struct wl_array states; - configure->state = surface->toplevel_state->pending; + configure->toplevel_state = surface->toplevel_state->pending; wl_array_init(&states); if (surface->toplevel_state->pending.maximized) { @@ -1160,8 +1166,7 @@ static void wlr_xdg_surface_v6_toplevel_committed( struct wlr_xdg_surface_v6 *surface) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - if (!wlr_surface_has_buffer(surface->surface) - && !surface->toplevel_state->added) { + if (!surface->toplevel_state->added) { // on the first commit, send a configure request to tell the client it // is added wlr_xdg_surface_v6_schedule_configure(surface); @@ -1169,11 +1174,15 @@ static void wlr_xdg_surface_v6_toplevel_committed( return; } - if (!wlr_surface_has_buffer(surface->surface)) { - return; - } - - surface->toplevel_state->current = surface->toplevel_state->next; + // update state that doesn't need compositor approval + surface->toplevel_state->current.max_width = + surface->toplevel_state->next.max_width; + surface->toplevel_state->current.min_width = + surface->toplevel_state->next.min_width; + surface->toplevel_state->current.max_height = + surface->toplevel_state->next.max_height; + surface->toplevel_state->current.min_height = + surface->toplevel_state->next.min_height; } static void wlr_xdg_surface_v6_popup_committed( @@ -1482,6 +1491,7 @@ uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); surface->toplevel_state->pending.width = width; surface->toplevel_state->pending.height = height; + wlr_log(L_DEBUG, "wlr_xdg_toplevel_v6_set_size %d", width); return wlr_xdg_surface_v6_schedule_configure(surface); } -- cgit v1.2.3 From 657e5c8c0d162958f96c45069767acfa56075843 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 13 Mar 2018 22:05:35 +0100 Subject: xdg-shell-v6: changed wlr_xdg_surface_v6_configure.toplevel_state to be NULL if surface isn't a toplevel --- include/wlr/types/wlr_xdg_shell_v6.h | 2 +- types/wlr_xdg_shell_v6.c | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 86a42181..9140fa64 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -82,7 +82,7 @@ struct wlr_xdg_surface_v6_configure { struct wl_list link; // wlr_xdg_surface_v6::configure_list uint32_t serial; - struct wlr_xdg_toplevel_v6_state toplevel_state; // TODO: should be null-able + struct wlr_xdg_toplevel_v6_state *toplevel_state; }; struct wlr_xdg_surface_v6 { diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 8c2e9d58..5ea1fb8b 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -868,15 +868,19 @@ static void wlr_xdg_toplevel_v6_ack_configure( struct wlr_xdg_surface_v6 *surface, struct wlr_xdg_surface_v6_configure *configure) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); + assert(configure->toplevel_state != NULL); surface->toplevel_state->current.maximized = - configure->toplevel_state.maximized; + configure->toplevel_state->maximized; surface->toplevel_state->current.fullscreen = - configure->toplevel_state.fullscreen; + configure->toplevel_state->fullscreen; surface->toplevel_state->current.resizing = - configure->toplevel_state.resizing; + configure->toplevel_state->resizing; surface->toplevel_state->current.activated = - configure->toplevel_state.activated; + configure->toplevel_state->activated; + + free(configure->toplevel_state); + configure->toplevel_state = NULL; } static void xdg_surface_handle_ack_configure(struct wl_client *client, @@ -988,9 +992,9 @@ static bool wlr_xdg_surface_v6_toplevel_state_compare( } else { struct wlr_xdg_surface_v6_configure *configure = wl_container_of(state->base->configure_list.prev, configure, link); - configured.state = configure->toplevel_state; - configured.width = configure->toplevel_state.width; - configured.height = configure->toplevel_state.height; + configured.state = *configure->toplevel_state; + configured.width = configure->toplevel_state->width; + configured.height = configure->toplevel_state->height; } if (state->pending.activated != configured.state.activated) { @@ -1025,7 +1029,12 @@ static void wlr_xdg_toplevel_v6_send_configure( uint32_t *s; struct wl_array states; - configure->toplevel_state = surface->toplevel_state->pending; + configure->toplevel_state = malloc(sizeof(*configure->toplevel_state)); + if (configure->toplevel_state == NULL) { + wlr_log(L_ERROR, "Allocation failed"); + return; + } + *configure->toplevel_state = surface->toplevel_state->pending; wl_array_init(&states); if (surface->toplevel_state->pending.maximized) { -- cgit v1.2.3 From 149209b72ed069f3c6026e6bf7ffb4ffff0de190 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 13 Mar 2018 22:09:44 +0100 Subject: xdg-shell-v6: rename toplevel and popup fields in wlr_xdg_surface_v6 for consistency --- include/wlr/types/wlr_xdg_shell_v6.h | 5 +- rootston/xdg_shell_v6.c | 8 +- types/wlr_xdg_shell_v6.c | 172 +++++++++++++++++------------------ 3 files changed, 92 insertions(+), 93 deletions(-) diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 9140fa64..2358feec 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -92,10 +92,9 @@ struct wlr_xdg_surface_v6 { struct wl_list link; // wlr_xdg_client_v6::surfaces enum wlr_xdg_surface_v6_role role; - // TODO: the _state prefix should be dropped union { - struct wlr_xdg_toplevel_v6 *toplevel_state; - struct wlr_xdg_popup_v6 *popup_state; + struct wlr_xdg_toplevel_v6 *toplevel; + struct wlr_xdg_popup_v6 *popup; }; struct wl_list popups; // wlr_xdg_popup_v6::link diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 84c76d16..59637105 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -85,7 +85,7 @@ static void apply_size_constraints(struct wlr_xdg_surface_v6 *surface, *dest_width = width; *dest_height = height; - struct wlr_xdg_toplevel_v6_state *state = &surface->toplevel_state->current; + struct wlr_xdg_toplevel_v6_state *state = &surface->toplevel->current; if (width < state->min_width) { *dest_width = state->min_width; } else if (state->max_width > 0 && @@ -236,7 +236,7 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) { return; } - view_maximize(view, surface->toplevel_state->next.maximized); + view_maximize(view, surface->toplevel->next.maximized); } static void handle_request_fullscreen(struct wl_listener *listener, @@ -386,10 +386,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->destroy = destroy; roots_surface->view = view; - if (surface->toplevel_state->next.maximized) { + if (surface->toplevel->next.maximized) { view_maximize(view, true); } - if (surface->toplevel_state->next.fullscreen) { + if (surface->toplevel->next.fullscreen) { view_set_fullscreen(view, true, NULL); } } diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 5ea1fb8b..214f818c 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -166,20 +166,20 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { wlr_signal_emit_safe(&surface->events.unmap, surface); if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { - wl_resource_set_user_data(surface->toplevel_state->resource, NULL); - free(surface->toplevel_state); - surface->toplevel_state = NULL; + wl_resource_set_user_data(surface->toplevel->resource, NULL); + free(surface->toplevel); + surface->toplevel = NULL; } if (surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) { - wl_resource_set_user_data(surface->popup_state->resource, NULL); + wl_resource_set_user_data(surface->popup->resource, NULL); - if (surface->popup_state->seat) { + if (surface->popup->seat) { struct wlr_xdg_popup_grab_v6 *grab = xdg_shell_popup_grab_from_seat(surface->client->shell, - surface->popup_state->seat); + surface->popup->seat); - wl_list_remove(&surface->popup_state->grab_link); + wl_list_remove(&surface->popup->grab_link); if (wl_list_empty(&grab->popups)) { if (grab->seat->pointer_state.grab == &grab->pointer_grab) { @@ -191,9 +191,9 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { } } - wl_list_remove(&surface->popup_state->link); - free(surface->popup_state); - surface->popup_state = NULL; + wl_list_remove(&surface->popup->link); + free(surface->popup); + surface->popup = NULL; } surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE; @@ -452,8 +452,8 @@ static void xdg_popup_handle_grab(struct wl_client *client, struct wlr_seat_client *seat_client = wlr_seat_client_from_resource(seat_resource); - if (surface->popup_state->committed) { - wl_resource_post_error(surface->popup_state->resource, + if (surface->popup->committed) { + wl_resource_post_error(surface->popup->resource, ZXDG_POPUP_V6_ERROR_INVALID_GRAB, "xdg_popup is already mapped"); return; @@ -465,10 +465,10 @@ static void xdg_popup_handle_grab(struct wl_client *client, struct wlr_xdg_surface_v6 *topmost = xdg_popup_grab_get_topmost(popup_grab); bool parent_is_toplevel = - surface->popup_state->parent->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL; + surface->popup->parent->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL; if ((topmost == NULL && !parent_is_toplevel) || - (topmost != NULL && topmost != surface->popup_state->parent)) { + (topmost != NULL && topmost != surface->popup->parent)) { wl_resource_post_error(surface->client->resource, ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP, "xdg_popup was not created on the topmost popup"); @@ -476,9 +476,9 @@ static void xdg_popup_handle_grab(struct wl_client *client, } popup_grab->client = surface->client->client; - surface->popup_state->seat = seat_client->seat; + surface->popup->seat = seat_client->seat; - wl_list_insert(&popup_grab->popups, &surface->popup_state->grab_link); + wl_list_insert(&popup_grab->popups, &surface->popup->grab_link); wlr_seat_pointer_start_grab(seat_client->seat, &popup_grab->pointer_grab); @@ -492,7 +492,7 @@ static void xdg_popup_handle_destroy(struct wl_client *client, xdg_surface_from_xdg_popup_resource(resource); struct wlr_xdg_popup_grab_v6 *grab = xdg_shell_popup_grab_from_seat(surface->client->shell, - surface->popup_state->seat); + surface->popup->seat); struct wlr_xdg_surface_v6 *topmost = xdg_popup_grab_get_topmost(grab); @@ -552,33 +552,33 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, return; } - surface->popup_state = calloc(1, sizeof(struct wlr_xdg_popup_v6)); - if (!surface->popup_state) { + surface->popup = calloc(1, sizeof(struct wlr_xdg_popup_v6)); + if (!surface->popup) { wl_resource_post_no_memory(resource); return; } - surface->popup_state->resource = + surface->popup->resource = wl_resource_create(client, &zxdg_popup_v6_interface, wl_resource_get_version(resource), id); - if (surface->popup_state->resource == NULL) { - free(surface->popup_state); + if (surface->popup->resource == NULL) { + free(surface->popup); wl_resource_post_no_memory(resource); return; } surface->role = WLR_XDG_SURFACE_V6_ROLE_POPUP; - surface->popup_state->base = surface; - surface->popup_state->parent = parent; - surface->popup_state->geometry = + surface->popup->base = surface; + surface->popup->parent = parent; + surface->popup->geometry = xdg_positioner_get_geometry(positioner, surface, parent); - wl_list_insert(&parent->popups, &surface->popup_state->link); + wl_list_insert(&parent->popups, &surface->popup->link); - wl_resource_set_implementation(surface->popup_state->resource, + wl_resource_set_implementation(surface->popup->resource, &zxdg_popup_v6_implementation, surface, xdg_popup_resource_destroy); - wlr_signal_emit_safe(&parent->events.new_popup, surface->popup_state); + wlr_signal_emit_safe(&parent->events.new_popup, surface->popup); } @@ -601,7 +601,7 @@ static void xdg_toplevel_handle_set_parent(struct wl_client *client, parent = xdg_surface_from_xdg_toplevel_resource(parent_resource); } - surface->toplevel_state->parent = parent; + surface->toplevel->parent = parent; } static void xdg_toplevel_handle_set_title(struct wl_client *client, @@ -641,7 +641,7 @@ static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, wlr_seat_client_from_resource(seat_resource); if (!surface->configured) { - wl_resource_post_error(surface->toplevel_state->resource, + wl_resource_post_error(surface->toplevel->resource, ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -672,7 +672,7 @@ static void xdg_toplevel_handle_move(struct wl_client *client, wlr_seat_client_from_resource(seat_resource); if (!surface->configured) { - wl_resource_post_error(surface->toplevel_state->resource, + wl_resource_post_error(surface->toplevel->resource, ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -701,7 +701,7 @@ static void xdg_toplevel_handle_resize(struct wl_client *client, wlr_seat_client_from_resource(seat_resource); if (!surface->configured) { - wl_resource_post_error(surface->toplevel_state->resource, + wl_resource_post_error(surface->toplevel->resource, ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -726,23 +726,23 @@ static void xdg_toplevel_handle_set_max_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.max_width = width; - surface->toplevel_state->next.max_height = height; + surface->toplevel->next.max_width = width; + surface->toplevel->next.max_height = height; } static void xdg_toplevel_handle_set_min_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.min_width = width; - surface->toplevel_state->next.min_height = height; + surface->toplevel->next.min_width = width; + surface->toplevel->next.min_height = height; } static void xdg_toplevel_handle_set_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.maximized = true; + surface->toplevel->next.maximized = true; wlr_signal_emit_safe(&surface->events.request_maximize, surface); } @@ -750,7 +750,7 @@ static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.maximized = false; + surface->toplevel->next.maximized = false; wlr_signal_emit_safe(&surface->events.request_maximize, surface); } @@ -764,7 +764,7 @@ static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, output = wlr_output_from_resource(output_resource); } - surface->toplevel_state->next.fullscreen = true; + surface->toplevel->next.fullscreen = true; struct wlr_xdg_toplevel_v6_set_fullscreen_event event = { .surface = surface, @@ -780,7 +780,7 @@ static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.fullscreen = false; + surface->toplevel->next.fullscreen = false; struct wlr_xdg_toplevel_v6_set_fullscreen_event event = { .surface = surface, @@ -840,24 +840,24 @@ static void xdg_surface_handle_get_toplevel(struct wl_client *client, return; } - surface->toplevel_state = calloc(1, sizeof(struct wlr_xdg_toplevel_v6)); - if (surface->toplevel_state == NULL) { + surface->toplevel = calloc(1, sizeof(struct wlr_xdg_toplevel_v6)); + if (surface->toplevel == NULL) { wl_resource_post_no_memory(resource); return; } surface->role = WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL; - surface->toplevel_state->base = surface; + surface->toplevel->base = surface; struct wl_resource *toplevel_resource = wl_resource_create(client, &zxdg_toplevel_v6_interface, wl_resource_get_version(resource), id); if (toplevel_resource == NULL) { - free(surface->toplevel_state); + free(surface->toplevel); wl_resource_post_no_memory(resource); return; } - surface->toplevel_state->resource = toplevel_resource; + surface->toplevel->resource = toplevel_resource; wl_resource_set_implementation(toplevel_resource, &zxdg_toplevel_v6_implementation, surface, @@ -870,13 +870,13 @@ static void wlr_xdg_toplevel_v6_ack_configure( assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); assert(configure->toplevel_state != NULL); - surface->toplevel_state->current.maximized = + surface->toplevel->current.maximized = configure->toplevel_state->maximized; - surface->toplevel_state->current.fullscreen = + surface->toplevel->current.fullscreen = configure->toplevel_state->fullscreen; - surface->toplevel_state->current.resizing = + surface->toplevel->current.resizing = configure->toplevel_state->resizing; - surface->toplevel_state->current.activated = + surface->toplevel->current.activated = configure->toplevel_state->activated; free(configure->toplevel_state); @@ -1034,10 +1034,10 @@ static void wlr_xdg_toplevel_v6_send_configure( wlr_log(L_ERROR, "Allocation failed"); return; } - *configure->toplevel_state = surface->toplevel_state->pending; + *configure->toplevel_state = surface->toplevel->pending; wl_array_init(&states); - if (surface->toplevel_state->pending.maximized) { + if (surface->toplevel->pending.maximized) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel"); @@ -1045,7 +1045,7 @@ static void wlr_xdg_toplevel_v6_send_configure( } *s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED; } - if (surface->toplevel_state->pending.fullscreen) { + if (surface->toplevel->pending.fullscreen) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel"); @@ -1053,7 +1053,7 @@ static void wlr_xdg_toplevel_v6_send_configure( } *s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN; } - if (surface->toplevel_state->pending.resizing) { + if (surface->toplevel->pending.resizing) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel"); @@ -1061,7 +1061,7 @@ static void wlr_xdg_toplevel_v6_send_configure( } *s = ZXDG_TOPLEVEL_V6_STATE_RESIZING; } - if (surface->toplevel_state->pending.activated) { + if (surface->toplevel->pending.activated) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel"); @@ -1070,15 +1070,15 @@ static void wlr_xdg_toplevel_v6_send_configure( *s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED; } - uint32_t width = surface->toplevel_state->pending.width; - uint32_t height = surface->toplevel_state->pending.height; + uint32_t width = surface->toplevel->pending.width; + uint32_t height = surface->toplevel->pending.height; if (width == 0 || height == 0) { width = surface->geometry->width; height = surface->geometry->height; } - zxdg_toplevel_v6_send_configure(surface->toplevel_state->resource, width, + zxdg_toplevel_v6_send_configure(surface->toplevel->resource, width, height, &states); wl_array_release(&states); @@ -1086,7 +1086,7 @@ static void wlr_xdg_toplevel_v6_send_configure( error_out: wl_array_release(&states); - wl_resource_post_no_memory(surface->toplevel_state->resource); + wl_resource_post_no_memory(surface->toplevel->resource); } static void wlr_xdg_surface_send_configure(void *user_data) { @@ -1112,11 +1112,11 @@ static void wlr_xdg_surface_send_configure(void *user_data) { wlr_xdg_toplevel_v6_send_configure(surface, configure); break; case WLR_XDG_SURFACE_V6_ROLE_POPUP: - zxdg_popup_v6_send_configure(surface->popup_state->resource, - surface->popup_state->geometry.x, - surface->popup_state->geometry.y, - surface->popup_state->geometry.width, - surface->popup_state->geometry.height); + zxdg_popup_v6_send_configure(surface->popup->resource, + surface->popup->geometry.x, + surface->popup->geometry.y, + surface->popup->geometry.width, + surface->popup->geometry.height); break; } @@ -1135,7 +1135,7 @@ static uint32_t wlr_xdg_surface_v6_schedule_configure( break; case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL: pending_same = - wlr_xdg_surface_v6_toplevel_state_compare(surface->toplevel_state); + wlr_xdg_surface_v6_toplevel_state_compare(surface->toplevel); break; case WLR_XDG_SURFACE_V6_ROLE_POPUP: break; @@ -1175,32 +1175,32 @@ static void wlr_xdg_surface_v6_toplevel_committed( struct wlr_xdg_surface_v6 *surface) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - if (!surface->toplevel_state->added) { + if (!surface->toplevel->added) { // on the first commit, send a configure request to tell the client it // is added wlr_xdg_surface_v6_schedule_configure(surface); - surface->toplevel_state->added = true; + surface->toplevel->added = true; return; } // update state that doesn't need compositor approval - surface->toplevel_state->current.max_width = - surface->toplevel_state->next.max_width; - surface->toplevel_state->current.min_width = - surface->toplevel_state->next.min_width; - surface->toplevel_state->current.max_height = - surface->toplevel_state->next.max_height; - surface->toplevel_state->current.min_height = - surface->toplevel_state->next.min_height; + surface->toplevel->current.max_width = + surface->toplevel->next.max_width; + surface->toplevel->current.min_width = + surface->toplevel->next.min_width; + surface->toplevel->current.max_height = + surface->toplevel->next.max_height; + surface->toplevel->current.min_height = + surface->toplevel->next.min_height; } static void wlr_xdg_surface_v6_popup_committed( struct wlr_xdg_surface_v6 *surface) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP); - if (!surface->popup_state->committed) { + if (!surface->popup->committed) { wlr_xdg_surface_v6_schedule_configure(surface); - surface->popup_state->committed = true; + surface->popup->committed = true; } } @@ -1498,8 +1498,8 @@ void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface) { uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, uint32_t width, uint32_t height) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->pending.width = width; - surface->toplevel_state->pending.height = height; + surface->toplevel->pending.width = width; + surface->toplevel->pending.height = height; wlr_log(L_DEBUG, "wlr_xdg_toplevel_v6_set_size %d", width); return wlr_xdg_surface_v6_schedule_configure(surface); @@ -1508,7 +1508,7 @@ uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, bool activated) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->pending.activated = activated; + surface->toplevel->pending.activated = activated; return wlr_xdg_surface_v6_schedule_configure(surface); } @@ -1516,7 +1516,7 @@ uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, bool maximized) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->pending.maximized = maximized; + surface->toplevel->pending.maximized = maximized; return wlr_xdg_surface_v6_schedule_configure(surface); } @@ -1524,7 +1524,7 @@ uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, bool fullscreen) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->pending.fullscreen = fullscreen; + surface->toplevel->pending.fullscreen = fullscreen; return wlr_xdg_surface_v6_schedule_configure(surface); } @@ -1532,23 +1532,23 @@ uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, bool resizing) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->pending.resizing = resizing; + surface->toplevel->pending.resizing = resizing; return wlr_xdg_surface_v6_schedule_configure(surface); } void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - zxdg_toplevel_v6_send_close(surface->toplevel_state->resource); + zxdg_toplevel_v6_send_close(surface->toplevel->resource); } void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface, double *popup_sx, double *popup_sy) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP); - struct wlr_xdg_surface_v6 *parent = surface->popup_state->parent; - *popup_sx = parent->geometry->x + surface->popup_state->geometry.x - + struct wlr_xdg_surface_v6 *parent = surface->popup->parent; + *popup_sx = parent->geometry->x + surface->popup->geometry.x - surface->geometry->x; - *popup_sy = parent->geometry->y + surface->popup_state->geometry.y - + *popup_sy = parent->geometry->y + surface->popup->geometry.y - surface->geometry->y; } -- cgit v1.2.3 From ace738dbca9cadb9b9bc5e15aeac19131bab3998 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 13 Mar 2018 22:17:25 +0100 Subject: xdg-shell-v6: next_geometry and geometry fields are not longer pointers in wlr_xdg_surface_v6 --- include/wlr/types/wlr_xdg_shell_v6.h | 4 +- rootston/xdg_shell_v6.c | 6 +-- types/wlr_xdg_shell_v6.c | 78 +++++++++++++----------------------- 3 files changed, 32 insertions(+), 56 deletions(-) diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 2358feec..d8503d28 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -109,8 +109,8 @@ struct wlr_xdg_surface_v6 { char *app_id; bool has_next_geometry; - struct wlr_box *next_geometry; - struct wlr_box *geometry; // TODO: should not be a pointer + struct wlr_box next_geometry; + struct wlr_box geometry; struct wl_listener surface_destroy_listener; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 59637105..13d25331 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -60,9 +60,9 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; - if (surface->geometry->width > 0 && surface->geometry->height > 0) { - box->width = surface->geometry->width; - box->height = surface->geometry->height; + if (surface->geometry.width > 0 && surface->geometry.height > 0) { + box->width = surface->geometry.width; + box->height = surface->geometry.height; } else if (view->wlr_surface != NULL) { box->width = view->wlr_surface->current->width; box->height = view->wlr_surface->current->height; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 214f818c..aabd9f2b 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -217,8 +217,8 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { } surface->has_next_geometry = false; - memset(surface->geometry, 0, sizeof(struct wlr_box)); - memset(surface->next_geometry, 0, sizeof(struct wlr_box)); + memset(&surface->geometry, 0, sizeof(struct wlr_box)); + memset(&surface->next_geometry, 0, sizeof(struct wlr_box)); } static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { @@ -232,8 +232,6 @@ static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { wl_list_remove(&surface->link); wl_list_remove(&surface->surface_destroy_listener.link); wlr_surface_set_role_committed(surface->surface, NULL, NULL); - free(surface->geometry); - free(surface->next_geometry); free(surface); } @@ -945,10 +943,10 @@ static void xdg_surface_handle_set_window_geometry(struct wl_client *client, } surface->has_next_geometry = true; - surface->next_geometry->height = height; - surface->next_geometry->width = width; - surface->next_geometry->x = x; - surface->next_geometry->y = y; + surface->next_geometry.height = height; + surface->next_geometry.width = width; + surface->next_geometry.x = x; + surface->next_geometry.y = y; } static void xdg_surface_handle_destroy(struct wl_client *client, @@ -1073,11 +1071,6 @@ static void wlr_xdg_toplevel_v6_send_configure( uint32_t width = surface->toplevel->pending.width; uint32_t height = surface->toplevel->pending.height; - if (width == 0 || height == 0) { - width = surface->geometry->width; - height = surface->geometry->height; - } - zxdg_toplevel_v6_send_configure(surface->toplevel->resource, width, height, &states); @@ -1217,10 +1210,10 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, if (surface->has_next_geometry) { surface->has_next_geometry = false; - surface->geometry->x = surface->next_geometry->x; - surface->geometry->y = surface->next_geometry->y; - surface->geometry->width = surface->next_geometry->width; - surface->geometry->height = surface->next_geometry->height; + surface->geometry.x = surface->next_geometry.x; + surface->geometry.y = surface->next_geometry.y; + surface->geometry.width = surface->next_geometry.width; + surface->geometry.height = surface->next_geometry.height; } switch (surface->role) { @@ -1268,21 +1261,9 @@ static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client, struct wlr_xdg_client_v6 *client = xdg_client_from_resource(client_resource); - struct wlr_xdg_surface_v6 *surface; - if (!(surface = calloc(1, sizeof(struct wlr_xdg_surface_v6)))) { - wl_client_post_no_memory(wl_client); - return; - } - - if (!(surface->geometry = calloc(1, sizeof(struct wlr_box)))) { - free(surface); - wl_client_post_no_memory(wl_client); - return; - } - - if (!(surface->next_geometry = calloc(1, sizeof(struct wlr_box)))) { - free(surface->geometry); - free(surface); + struct wlr_xdg_surface_v6 *surface = + calloc(1, sizeof(struct wlr_xdg_surface_v6)); + if (surface == NULL) { wl_client_post_no_memory(wl_client); return; } @@ -1294,8 +1275,6 @@ static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client, &zxdg_surface_v6_interface, wl_resource_get_version(client_resource), id); if (surface->resource == NULL) { - free(surface->next_geometry); - free(surface->geometry); free(surface); wl_client_post_no_memory(wl_client); return; @@ -1303,8 +1282,6 @@ static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client, if (wlr_surface_has_buffer(surface->surface)) { wl_resource_destroy(surface->resource); - free(surface->next_geometry); - free(surface->geometry); free(surface); wl_resource_post_error(surface_resource, ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, @@ -1500,7 +1477,6 @@ uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); surface->toplevel->pending.width = width; surface->toplevel->pending.height = height; - wlr_log(L_DEBUG, "wlr_xdg_toplevel_v6_set_size %d", width); return wlr_xdg_surface_v6_schedule_configure(surface); } @@ -1546,10 +1522,10 @@ void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface, double *popup_sx, double *popup_sy) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP); struct wlr_xdg_surface_v6 *parent = surface->popup->parent; - *popup_sx = parent->geometry->x + surface->popup->geometry.x - - surface->geometry->x; - *popup_sy = parent->geometry->y + surface->popup->geometry.y - - surface->geometry->y; + *popup_sx = parent->geometry.x + surface->popup->geometry.x - + surface->geometry.x; + *popup_sy = parent->geometry.y + surface->popup->geometry.y - + surface->geometry.y; } struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( @@ -1563,30 +1539,30 @@ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( struct wlr_xdg_surface_v6 *popup = popup_state->base; double _popup_sx = - surface->geometry->x + popup_state->geometry.x; + surface->geometry.x + popup_state->geometry.x; double _popup_sy = - surface->geometry->y + popup_state->geometry.y; + surface->geometry.y + popup_state->geometry.y; int popup_width = popup_state->geometry.width; int popup_height = popup_state->geometry.height; struct wlr_xdg_surface_v6 *_popup = wlr_xdg_surface_v6_popup_at(popup, - sx - _popup_sx + popup->geometry->x, - sy - _popup_sy + popup->geometry->y, + sx - _popup_sx + popup->geometry.x, + sy - _popup_sy + popup->geometry.y, popup_sx, popup_sy); if (_popup) { - *popup_sx = *popup_sx + _popup_sx - popup->geometry->x; - *popup_sy = *popup_sy + _popup_sy - popup->geometry->y; + *popup_sx = *popup_sx + _popup_sx - popup->geometry.x; + *popup_sy = *popup_sy + _popup_sy - popup->geometry.y; return _popup; } if ((sx > _popup_sx && sx < _popup_sx + popup_width) && (sy > _popup_sy && sy < _popup_sy + popup_height)) { if (pixman_region32_contains_point(&popup->surface->current->input, - sx - _popup_sx + popup->geometry->x, - sy - _popup_sy + popup->geometry->y, NULL)) { - *popup_sx = _popup_sx - popup->geometry->x; - *popup_sy = _popup_sy - popup->geometry->y; + sx - _popup_sx + popup->geometry.x, + sy - _popup_sy + popup->geometry.y, NULL)) { + *popup_sx = _popup_sx - popup->geometry.x; + *popup_sy = _popup_sy - popup->geometry.y; return popup; } } -- cgit v1.2.3 From dd8a7a29e19f4e304e2620aa1665dd6761a1370e Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 14 Mar 2018 00:01:28 +0100 Subject: rootston: don't center view if maximized --- rootston/desktop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index b1e6f874..e9a9425c 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -491,7 +491,7 @@ void view_initial_focus(struct roots_view *view) { void view_setup(struct roots_view *view) { view_initial_focus(view); - if (view->fullscreen_output == NULL) { + if (view->fullscreen_output == NULL && !view->maximized) { view_center(view); } -- cgit v1.2.3 From 361d7c857eec82d345ed5d55971ae16da88d710e Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 09:04:06 +0100 Subject: xdg-shell-v6: don't leak wlr_xdg_surface_v6_configure.toplevel_state --- types/wlr_xdg_shell_v6.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index aabd9f2b..31dd306a 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -159,6 +159,16 @@ static struct wlr_xdg_popup_grab_v6 *xdg_shell_popup_grab_from_seat( } +static void xdg_surface_configure_destroy( + struct wlr_xdg_surface_v6_configure *configure) { + if (configure == NULL) { + return; + } + wl_list_remove(&configure->link); + free(configure->toplevel_state); + free(configure); +} + static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { assert(surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE); @@ -196,6 +206,11 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { surface->popup = NULL; } + struct wlr_xdg_surface_v6_configure *configure, *tmp; + wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { + xdg_surface_configure_destroy(configure); + } + surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE; free(surface->title); surface->title = NULL; @@ -210,12 +225,6 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { } surface->configure_next_serial = 0; - struct wlr_xdg_surface_v6_configure *configure, *tmp; - wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { - wl_list_remove(&configure->link); - free(configure); - } - surface->has_next_geometry = false; memset(&surface->geometry, 0, sizeof(struct wlr_box)); memset(&surface->next_geometry, 0, sizeof(struct wlr_box)); @@ -876,9 +885,6 @@ static void wlr_xdg_toplevel_v6_ack_configure( configure->toplevel_state->resizing; surface->toplevel->current.activated = configure->toplevel_state->activated; - - free(configure->toplevel_state); - configure->toplevel_state = NULL; } static void xdg_surface_handle_ack_configure(struct wl_client *client, @@ -897,9 +903,10 @@ static void xdg_surface_handle_ack_configure(struct wl_client *client, wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { if (configure->serial < serial) { wl_list_remove(&configure->link); - free(configure); + xdg_surface_configure_destroy(configure); } else if (configure->serial == serial) { wl_list_remove(&configure->link); + wl_list_init(&configure->link); found = true; break; } else { @@ -927,7 +934,7 @@ static void xdg_surface_handle_ack_configure(struct wl_client *client, surface->configured = true; surface->configure_serial = serial; - free(configure); + xdg_surface_configure_destroy(configure); } static void xdg_surface_handle_set_window_geometry(struct wl_client *client, @@ -1024,16 +1031,17 @@ static void wlr_xdg_toplevel_v6_send_configure( struct wlr_xdg_surface_v6 *surface, struct wlr_xdg_surface_v6_configure *configure) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - uint32_t *s; - struct wl_array states; configure->toplevel_state = malloc(sizeof(*configure->toplevel_state)); if (configure->toplevel_state == NULL) { wlr_log(L_ERROR, "Allocation failed"); + wl_resource_post_no_memory(surface->toplevel->resource); return; } *configure->toplevel_state = surface->toplevel->pending; + uint32_t *s; + struct wl_array states; wl_array_init(&states); if (surface->toplevel->pending.maximized) { s = wl_array_add(&states, sizeof(uint32_t)); @@ -1070,7 +1078,6 @@ static void wlr_xdg_toplevel_v6_send_configure( uint32_t width = surface->toplevel->pending.width; uint32_t height = surface->toplevel->pending.height; - zxdg_toplevel_v6_send_configure(surface->toplevel->resource, width, height, &states); -- cgit v1.2.3 From 42cc575266b3fb2bb406145d0553e375d17b038a Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 20:14:47 +0100 Subject: xdg-shell-v6: fix wl_list_remove called twice --- types/wlr_xdg_shell_v6.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 31dd306a..ef6045c2 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -506,8 +506,7 @@ static void xdg_popup_handle_destroy(struct wl_client *client, if (topmost != surface) { wl_resource_post_error(surface->client->resource, ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP, - "xdg_popup was destroyed while it was not the topmost " - "popup"); + "xdg_popup was destroyed while it was not the topmost popup"); return; } @@ -805,8 +804,8 @@ static void xdg_toplevel_handle_set_minimized(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_minimize, surface); } -static const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation = -{ +static const struct zxdg_toplevel_v6_interface + zxdg_toplevel_v6_implementation = { .destroy = resource_handle_destroy, .set_parent = xdg_toplevel_handle_set_parent, .set_title = xdg_toplevel_handle_set_title, @@ -820,7 +819,7 @@ static const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation = .unset_maximized = xdg_toplevel_handle_unset_maximized, .set_fullscreen = xdg_toplevel_handle_set_fullscreen, .unset_fullscreen = xdg_toplevel_handle_unset_fullscreen, - .set_minimized = xdg_toplevel_handle_set_minimized + .set_minimized = xdg_toplevel_handle_set_minimized, }; static void xdg_surface_resource_destroy(struct wl_resource *resource) { @@ -902,11 +901,8 @@ static void xdg_surface_handle_ack_configure(struct wl_client *client, struct wlr_xdg_surface_v6_configure *configure, *tmp; wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { if (configure->serial < serial) { - wl_list_remove(&configure->link); xdg_surface_configure_destroy(configure); } else if (configure->serial == serial) { - wl_list_remove(&configure->link); - wl_list_init(&configure->link); found = true; break; } else { -- cgit v1.2.3 From e607d0f7ee00c59354c996fc98e738c26adbca58 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 20:15:09 +0100 Subject: xdg-shell: add map/unmap support --- include/rootston/view.h | 2 + include/wlr/types/wlr_xdg_shell.h | 33 +-- rootston/xdg_shell.c | 58 ++++- types/wlr_xdg_shell.c | 518 ++++++++++++++++++++++---------------- 4 files changed, 355 insertions(+), 256 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 92d1feb5..775f3d11 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -44,6 +44,8 @@ struct roots_xdg_surface { struct wl_listener destroy; struct wl_listener new_popup; + struct wl_listener map; + struct wl_listener unmap; struct wl_listener request_move; struct wl_listener request_resize; struct wl_listener request_maximize; diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index 8422863c..ad0a626f 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -62,19 +62,10 @@ enum wlr_xdg_surface_role { }; struct wlr_xdg_toplevel_state { - bool maximized; - bool fullscreen; - bool resizing; - bool activated; - - uint32_t width; - uint32_t height; - - uint32_t max_width; - uint32_t max_height; - - uint32_t min_width; - uint32_t min_height; + bool maximized, fullscreen, resizing, activated; + uint32_t width, height; + uint32_t max_width, max_height; + uint32_t min_width, min_height; }; struct wlr_xdg_toplevel { @@ -90,7 +81,8 @@ struct wlr_xdg_toplevel { struct wlr_xdg_surface_configure { struct wl_list link; // wlr_xdg_surface::configure_list uint32_t serial; - struct wlr_xdg_toplevel_state state; + + struct wlr_xdg_toplevel_state *toplevel_state; }; struct wlr_xdg_surface { @@ -101,14 +93,13 @@ struct wlr_xdg_surface { enum wlr_xdg_surface_role role; union { - struct wlr_xdg_toplevel *toplevel_state; - struct wlr_xdg_popup *popup_state; + struct wlr_xdg_toplevel *toplevel; + struct wlr_xdg_popup *popup; }; struct wl_list popups; // wlr_xdg_popup::link - bool configured; - bool added; + bool added, configured, mapped; uint32_t configure_serial; struct wl_event_source *configure_idle; uint32_t configure_next_serial; @@ -118,8 +109,8 @@ struct wlr_xdg_surface { char *app_id; bool has_next_geometry; - struct wlr_box *next_geometry; - struct wlr_box *geometry; + struct wlr_box next_geometry; + struct wlr_box geometry; struct wl_listener surface_destroy_listener; @@ -127,6 +118,8 @@ struct wlr_xdg_surface { struct wl_signal destroy; struct wl_signal ping_timeout; struct wl_signal new_popup; + struct wl_signal map; + struct wl_signal unmap; struct wl_signal request_maximize; struct wl_signal request_fullscreen; diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c index 24c57bd5..851c0045 100644 --- a/rootston/xdg_shell.c +++ b/rootston/xdg_shell.c @@ -60,12 +60,14 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) { assert(view->type == ROOTS_XDG_SHELL_VIEW); struct wlr_xdg_surface *surface = view->xdg_surface; - if (surface->geometry->width > 0 && surface->geometry->height > 0) { - box->width = surface->geometry->width; - box->height = surface->geometry->height; - } else { + if (surface->geometry.width > 0 && surface->geometry.height > 0) { + box->width = surface->geometry.width; + box->height = surface->geometry.height; + } else if (view->wlr_surface != NULL) { box->width = view->wlr_surface->current->width; box->height = view->wlr_surface->current->height; + } else { + box->width = box->height = 0; } } @@ -83,7 +85,7 @@ static void apply_size_constraints(struct wlr_xdg_surface *surface, *dest_width = width; *dest_height = height; - struct wlr_xdg_toplevel_state *state = &surface->toplevel_state->current; + struct wlr_xdg_toplevel_state *state = &surface->toplevel->current; if (width < state->min_width) { *dest_width = state->min_width; } else if (state->max_width > 0 && @@ -181,10 +183,13 @@ static void close(struct roots_view *view) { } static void destroy(struct roots_view *view) { + assert(view->type == ROOTS_XDG_SHELL_VIEW); struct roots_xdg_surface *roots_xdg_surface = view->roots_xdg_surface; wl_list_remove(&roots_xdg_surface->surface_commit.link); wl_list_remove(&roots_xdg_surface->destroy.link); wl_list_remove(&roots_xdg_surface->new_popup.link); + wl_list_remove(&roots_xdg_surface->map.link); + wl_list_remove(&roots_xdg_surface->unmap.link); wl_list_remove(&roots_xdg_surface->request_move.link); wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->request_maximize.link); @@ -231,7 +236,7 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) { return; } - view_maximize(view, surface->toplevel_state->next.maximized); + view_maximize(view, surface->toplevel->next.maximized); } static void handle_request_fullscreen(struct wl_listener *listener, @@ -255,6 +260,10 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_xdg_surface *surface = view->xdg_surface; + if (!surface->mapped) { + return; + } + view_apply_damage(view); struct wlr_box size; @@ -289,6 +298,26 @@ static void handle_new_popup(struct wl_listener *listener, void *data) { popup_create(roots_xdg_surface->view, wlr_popup); } +static void handle_map(struct wl_listener *listener, void *data) { + struct roots_xdg_surface *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, map); + struct roots_view *view = roots_xdg_surface->view; + + struct wlr_box box; + get_size(view, &box); + view->width = box.width; + view->height = box.height; + + view_map(view, view->xdg_surface->surface); + view_setup(view); +} + +static void handle_unmap(struct wl_listener *listener, void *data) { + struct roots_xdg_surface *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, unmap); + view_unmap(roots_xdg_surface->view); +} + static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xdg_surface *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, destroy); @@ -321,6 +350,10 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { &roots_surface->surface_commit); roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); + roots_surface->map.notify = handle_map; + wl_signal_add(&surface->events.map, &roots_surface->map); + roots_surface->unmap.notify = handle_unmap; + wl_signal_add(&surface->events.unmap, &roots_surface->unmap); roots_surface->request_move.notify = handle_request_move; wl_signal_add(&surface->events.request_move, &roots_surface->request_move); roots_surface->request_resize.notify = handle_request_resize; @@ -353,11 +386,10 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { view->destroy = destroy; roots_surface->view = view; - struct wlr_box box; - get_size(view, &box); - view->width = box.width; - view->height = box.height; - - view_map(view, surface->surface); - view_setup(view); + if (surface->toplevel->next.maximized) { + view_maximize(view, true); + } + if (surface->toplevel->next.fullscreen) { + view_set_fullscreen(view, true, NULL); + } } diff --git a/types/wlr_xdg_shell.c b/types/wlr_xdg_shell.c index 990926cf..5b02088d 100644 --- a/types/wlr_xdg_shell.c +++ b/types/wlr_xdg_shell.c @@ -34,7 +34,7 @@ struct wlr_xdg_positioner { }; -static void resource_destroy(struct wl_client *client, +static void resource_handle_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); } @@ -159,43 +159,37 @@ static struct wlr_xdg_popup_grab *xdg_shell_popup_grab_from_seat( } -static void xdg_surface_destroy(struct wlr_xdg_surface *surface) { - // TODO: probably need to ungrab before this event - wlr_signal_emit_safe(&surface->events.destroy, surface); - - if (surface->configure_idle) { - wl_event_source_remove(surface->configure_idle); +static void xdg_surface_configure_destroy( + struct wlr_xdg_surface_configure *configure) { + if (configure == NULL) { + return; } + wl_list_remove(&configure->link); + free(configure->toplevel_state); + free(configure); +} - struct wlr_xdg_surface_configure *configure, *tmp; - wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { - free(configure); - } +static void xdg_surface_unmap(struct wlr_xdg_surface *surface) { + assert(surface->role != WLR_XDG_SURFACE_ROLE_NONE); + + // TODO: probably need to ungrab before this event + wlr_signal_emit_safe(&surface->events.unmap, surface); if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) { - wl_resource_set_user_data(surface->toplevel_state->resource, NULL); - free(surface->toplevel_state); + wl_resource_set_user_data(surface->toplevel->resource, NULL); + free(surface->toplevel); + surface->toplevel = NULL; } if (surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { - wl_resource_set_user_data(surface->popup_state->resource, NULL); + wl_resource_set_user_data(surface->popup->resource, NULL); - if (surface->popup_state->seat) { + if (surface->popup->seat) { struct wlr_xdg_popup_grab *grab = xdg_shell_popup_grab_from_seat(surface->client->shell, - surface->popup_state->seat); + surface->popup->seat); - struct wlr_xdg_surface *topmost = - xdg_popup_grab_get_topmost(grab); - - if (topmost != surface) { - wl_resource_post_error(surface->client->resource, - XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP, - "xdg_popup was destroyed while it was not the topmost " - "popup."); - } - - wl_list_remove(&surface->popup_state->grab_link); + wl_list_remove(&surface->popup->grab_link); if (wl_list_empty(&grab->popups)) { if (grab->seat->pointer_state.grab == &grab->pointer_grab) { @@ -207,18 +201,46 @@ static void xdg_surface_destroy(struct wlr_xdg_surface *surface) { } } - wl_list_remove(&surface->popup_state->link); - free(surface->popup_state); + wl_list_remove(&surface->popup->link); + free(surface->popup); + surface->popup = NULL; } + struct wlr_xdg_surface_configure *configure, *tmp; + wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { + xdg_surface_configure_destroy(configure); + } + + surface->role = WLR_XDG_SURFACE_ROLE_NONE; + free(surface->title); + surface->title = NULL; + free(surface->app_id); + surface->app_id = NULL; + + surface->added = surface->configured = surface->mapped = false; + surface->configure_serial = 0; + if (surface->configure_idle) { + wl_event_source_remove(surface->configure_idle); + surface->configure_idle = NULL; + } + surface->configure_next_serial = 0; + + surface->has_next_geometry = false; + memset(&surface->geometry, 0, sizeof(struct wlr_box)); + memset(&surface->next_geometry, 0, sizeof(struct wlr_box)); +} + +static void xdg_surface_destroy(struct wlr_xdg_surface *surface) { + if (surface->role != WLR_XDG_SURFACE_ROLE_NONE) { + xdg_surface_unmap(surface); + } + + wlr_signal_emit_safe(&surface->events.destroy, surface); + wl_resource_set_user_data(surface->resource, NULL); wl_list_remove(&surface->link); wl_list_remove(&surface->surface_destroy_listener.link); wlr_surface_set_role_committed(surface->surface, NULL, NULL); - free(surface->geometry); - free(surface->next_geometry); - free(surface->title); - free(surface->app_id); free(surface); } @@ -238,7 +260,7 @@ static void xdg_positioner_destroy(struct wl_resource *resource) { free(positioner); } -static void xdg_positioner_protocol_set_size(struct wl_client *client, +static void xdg_positioner_handle_set_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_positioner *positioner = xdg_positioner_from_resource(resource); @@ -254,7 +276,7 @@ static void xdg_positioner_protocol_set_size(struct wl_client *client, positioner->size.height = height; } -static void xdg_positioner_protocol_set_anchor_rect(struct wl_client *client, +static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) { struct wlr_xdg_positioner *positioner = @@ -273,7 +295,7 @@ static void xdg_positioner_protocol_set_anchor_rect(struct wl_client *client, positioner->anchor_rect.height = height; } -static void xdg_positioner_protocol_set_anchor(struct wl_client *client, +static void xdg_positioner_handle_set_anchor(struct wl_client *client, struct wl_resource *resource, uint32_t anchor) { struct wlr_xdg_positioner *positioner = xdg_positioner_from_resource(resource); @@ -288,7 +310,7 @@ static void xdg_positioner_protocol_set_anchor(struct wl_client *client, positioner->anchor = anchor; } -static void xdg_positioner_protocol_set_gravity(struct wl_client *client, +static void xdg_positioner_handle_set_gravity(struct wl_client *client, struct wl_resource *resource, uint32_t gravity) { struct wlr_xdg_positioner *positioner = xdg_positioner_from_resource(resource); @@ -303,7 +325,7 @@ static void xdg_positioner_protocol_set_gravity(struct wl_client *client, positioner->gravity = gravity; } -static void xdg_positioner_protocol_set_constraint_adjustment( +static void xdg_positioner_handle_set_constraint_adjustment( struct wl_client *client, struct wl_resource *resource, uint32_t constraint_adjustment) { struct wlr_xdg_positioner *positioner = @@ -312,7 +334,7 @@ static void xdg_positioner_protocol_set_constraint_adjustment( positioner->constraint_adjustment = constraint_adjustment; } -static void xdg_positioner_protocol_set_offset(struct wl_client *client, +static void xdg_positioner_handle_set_offset(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y) { struct wlr_xdg_positioner *positioner = xdg_positioner_from_resource(resource); @@ -323,17 +345,17 @@ static void xdg_positioner_protocol_set_offset(struct wl_client *client, static const struct xdg_positioner_interface xdg_positioner_implementation = { - .destroy = resource_destroy, - .set_size = xdg_positioner_protocol_set_size, - .set_anchor_rect = xdg_positioner_protocol_set_anchor_rect, - .set_anchor = xdg_positioner_protocol_set_anchor, - .set_gravity = xdg_positioner_protocol_set_gravity, + .destroy = resource_handle_destroy, + .set_size = xdg_positioner_handle_set_size, + .set_anchor_rect = xdg_positioner_handle_set_anchor_rect, + .set_anchor = xdg_positioner_handle_set_anchor, + .set_gravity = xdg_positioner_handle_set_gravity, .set_constraint_adjustment = - xdg_positioner_protocol_set_constraint_adjustment, - .set_offset = xdg_positioner_protocol_set_offset, + xdg_positioner_handle_set_constraint_adjustment, + .set_offset = xdg_positioner_handle_set_offset, }; -static void xdg_shell_create_positioner(struct wl_client *wl_client, +static void xdg_shell_handle_create_positioner(struct wl_client *wl_client, struct wl_resource *resource, uint32_t id) { struct wlr_xdg_positioner *positioner = calloc(1, sizeof(struct wlr_xdg_positioner)); @@ -458,7 +480,7 @@ static struct wlr_xdg_surface *xdg_surface_from_xdg_popup_resource( return wl_resource_get_user_data(resource); } -static void xdg_popup_protocol_grab(struct wl_client *client, +static void xdg_popup_handle_grab(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { struct wlr_xdg_surface *surface = @@ -466,8 +488,8 @@ static void xdg_popup_protocol_grab(struct wl_client *client, struct wlr_seat_client *seat_client = wlr_seat_client_from_resource(seat_resource); - if (surface->popup_state->committed) { - wl_resource_post_error(surface->popup_state->resource, + if (surface->popup->committed) { + wl_resource_post_error(surface->popup->resource, XDG_POPUP_ERROR_INVALID_GRAB, "xdg_popup is already mapped"); return; @@ -479,10 +501,10 @@ static void xdg_popup_protocol_grab(struct wl_client *client, struct wlr_xdg_surface *topmost = xdg_popup_grab_get_topmost(popup_grab); bool parent_is_toplevel = - surface->popup_state->parent->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL; + surface->popup->parent->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL; if ((topmost == NULL && !parent_is_toplevel) || - (topmost != NULL && topmost != surface->popup_state->parent)) { + (topmost != NULL && topmost != surface->popup->parent)) { wl_resource_post_error(surface->client->resource, XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP, "xdg_popup was not created on the topmost popup"); @@ -490,9 +512,9 @@ static void xdg_popup_protocol_grab(struct wl_client *client, } popup_grab->client = surface->client->client; - surface->popup_state->seat = seat_client->seat; + surface->popup->seat = seat_client->seat; - wl_list_insert(&popup_grab->popups, &surface->popup_state->grab_link); + wl_list_insert(&popup_grab->popups, &surface->popup->grab_link); wlr_seat_pointer_start_grab(seat_client->seat, &popup_grab->pointer_grab); @@ -500,16 +522,36 @@ static void xdg_popup_protocol_grab(struct wl_client *client, &popup_grab->keyboard_grab); } +static void xdg_popup_handle_destroy(struct wl_client *client, + struct wl_resource *resource) { + struct wlr_xdg_surface *surface = + xdg_surface_from_xdg_popup_resource(resource); + struct wlr_xdg_popup_grab *grab = + xdg_shell_popup_grab_from_seat(surface->client->shell, + surface->popup->seat); + struct wlr_xdg_surface *topmost = + xdg_popup_grab_get_topmost(grab); + + if (topmost != surface) { + wl_resource_post_error(surface->client->resource, + XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP, + "xdg_popup was destroyed while it was not the topmost popup"); + return; + } + + wl_resource_destroy(resource); +} + static const struct xdg_popup_interface xdg_popup_implementation = { - .destroy = resource_destroy, - .grab = xdg_popup_protocol_grab, + .destroy = xdg_popup_handle_destroy, + .grab = xdg_popup_handle_grab, }; static void xdg_popup_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_popup_resource(resource); if (surface != NULL) { - xdg_surface_destroy(surface); + xdg_surface_unmap(surface); } } @@ -522,7 +564,7 @@ static struct wlr_xdg_surface *xdg_surface_from_resource( return wl_resource_get_user_data(resource); } -static void xdg_surface_get_popup(struct wl_client *client, +static void xdg_surface_handle_get_popup(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *parent_resource, struct wl_resource *positioner_resource) { @@ -545,33 +587,33 @@ static void xdg_surface_get_popup(struct wl_client *client, return; } - surface->popup_state = calloc(1, sizeof(struct wlr_xdg_popup)); - if (!surface->popup_state) { + surface->popup = calloc(1, sizeof(struct wlr_xdg_popup)); + if (!surface->popup) { wl_resource_post_no_memory(resource); return; } - surface->popup_state->resource = + surface->popup->resource = wl_resource_create(client, &xdg_popup_interface, wl_resource_get_version(resource), id); - if (surface->popup_state->resource == NULL) { - free(surface->popup_state); + if (surface->popup->resource == NULL) { + free(surface->popup); wl_resource_post_no_memory(resource); return; } surface->role = WLR_XDG_SURFACE_ROLE_POPUP; - surface->popup_state->base = surface; - surface->popup_state->parent = parent; - surface->popup_state->geometry = + surface->popup->base = surface; + surface->popup->parent = parent; + surface->popup->geometry = xdg_positioner_get_geometry(positioner, surface, parent); - wl_list_insert(&parent->popups, &surface->popup_state->link); + wl_list_insert(&parent->popups, &surface->popup->link); - wl_resource_set_implementation(surface->popup_state->resource, + wl_resource_set_implementation(surface->popup->resource, &xdg_popup_implementation, surface, xdg_popup_resource_destroy); - wlr_signal_emit_safe(&parent->events.new_popup, surface->popup_state); + wlr_signal_emit_safe(&parent->events.new_popup, surface->popup); } @@ -584,7 +626,7 @@ static struct wlr_xdg_surface *xdg_surface_from_xdg_toplevel_resource( return wl_resource_get_user_data(resource); } -static void xdg_toplevel_protocol_set_parent(struct wl_client *client, +static void xdg_toplevel_handle_set_parent(struct wl_client *client, struct wl_resource *resource, struct wl_resource *parent_resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -594,10 +636,10 @@ static void xdg_toplevel_protocol_set_parent(struct wl_client *client, parent = xdg_surface_from_xdg_toplevel_resource(parent_resource); } - surface->toplevel_state->parent = parent; + surface->toplevel->parent = parent; } -static void xdg_toplevel_protocol_set_title(struct wl_client *client, +static void xdg_toplevel_handle_set_title(struct wl_client *client, struct wl_resource *resource, const char *title) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -612,7 +654,7 @@ static void xdg_toplevel_protocol_set_title(struct wl_client *client, surface->title = tmp; } -static void xdg_toplevel_protocol_set_app_id(struct wl_client *client, +static void xdg_toplevel_handle_set_app_id(struct wl_client *client, struct wl_resource *resource, const char *app_id) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -627,7 +669,7 @@ static void xdg_toplevel_protocol_set_app_id(struct wl_client *client, surface->app_id = tmp; } -static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client, +static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, int32_t x, int32_t y) { struct wlr_xdg_surface *surface = @@ -636,7 +678,7 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client, wlr_seat_client_from_resource(seat_resource); if (!surface->configured) { - wl_resource_post_error(surface->toplevel_state->resource, + wl_resource_post_error(surface->toplevel->resource, XDG_SURFACE_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -658,7 +700,7 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_show_window_menu, &event); } -static void xdg_toplevel_protocol_move(struct wl_client *client, +static void xdg_toplevel_handle_move(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { struct wlr_xdg_surface *surface = @@ -667,7 +709,7 @@ static void xdg_toplevel_protocol_move(struct wl_client *client, wlr_seat_client_from_resource(seat_resource); if (!surface->configured) { - wl_resource_post_error(surface->toplevel_state->resource, + wl_resource_post_error(surface->toplevel->resource, XDG_SURFACE_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -687,7 +729,7 @@ static void xdg_toplevel_protocol_move(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_move, &event); } -static void xdg_toplevel_protocol_resize(struct wl_client *client, +static void xdg_toplevel_handle_resize(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, uint32_t edges) { struct wlr_xdg_surface *surface = @@ -696,7 +738,7 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client, wlr_seat_client_from_resource(seat_resource); if (!surface->configured) { - wl_resource_post_error(surface->toplevel_state->resource, + wl_resource_post_error(surface->toplevel->resource, XDG_SURFACE_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -717,39 +759,39 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_resize, &event); } -static void xdg_toplevel_protocol_set_max_size(struct wl_client *client, +static void xdg_toplevel_handle_set_max_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.max_width = width; - surface->toplevel_state->next.max_height = height; + surface->toplevel->next.max_width = width; + surface->toplevel->next.max_height = height; } -static void xdg_toplevel_protocol_set_min_size(struct wl_client *client, +static void xdg_toplevel_handle_set_min_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.min_width = width; - surface->toplevel_state->next.min_height = height; + surface->toplevel->next.min_width = width; + surface->toplevel->next.min_height = height; } -static void xdg_toplevel_protocol_set_maximized(struct wl_client *client, +static void xdg_toplevel_handle_set_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.maximized = true; + surface->toplevel->next.maximized = true; wlr_signal_emit_safe(&surface->events.request_maximize, surface); } -static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client, +static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.maximized = false; + surface->toplevel->next.maximized = false; wlr_signal_emit_safe(&surface->events.request_maximize, surface); } -static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, +static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, struct wl_resource *resource, struct wl_resource *output_resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -759,7 +801,7 @@ static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, output = wlr_output_from_resource(output_resource); } - surface->toplevel_state->next.fullscreen = true; + surface->toplevel->next.fullscreen = true; struct wlr_xdg_toplevel_set_fullscreen_event event = { .surface = surface, @@ -770,12 +812,12 @@ static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); } -static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client, +static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel_state->next.fullscreen = false; + surface->toplevel->next.fullscreen = false; struct wlr_xdg_toplevel_set_fullscreen_event event = { .surface = surface, @@ -786,7 +828,7 @@ static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client, wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); } -static void xdg_toplevel_protocol_set_minimized(struct wl_client *client, +static void xdg_toplevel_handle_set_minimized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); @@ -794,20 +836,20 @@ static void xdg_toplevel_protocol_set_minimized(struct wl_client *client, } static const struct xdg_toplevel_interface xdg_toplevel_implementation = { - .destroy = resource_destroy, - .set_parent = xdg_toplevel_protocol_set_parent, - .set_title = xdg_toplevel_protocol_set_title, - .set_app_id = xdg_toplevel_protocol_set_app_id, - .show_window_menu = xdg_toplevel_protocol_show_window_menu, - .move = xdg_toplevel_protocol_move, - .resize = xdg_toplevel_protocol_resize, - .set_max_size = xdg_toplevel_protocol_set_max_size, - .set_min_size = xdg_toplevel_protocol_set_min_size, - .set_maximized = xdg_toplevel_protocol_set_maximized, - .unset_maximized = xdg_toplevel_protocol_unset_maximized, - .set_fullscreen = xdg_toplevel_protocol_set_fullscreen, - .unset_fullscreen = xdg_toplevel_protocol_unset_fullscreen, - .set_minimized = xdg_toplevel_protocol_set_minimized + .destroy = resource_handle_destroy, + .set_parent = xdg_toplevel_handle_set_parent, + .set_title = xdg_toplevel_handle_set_title, + .set_app_id = xdg_toplevel_handle_set_app_id, + .show_window_menu = xdg_toplevel_handle_show_window_menu, + .move = xdg_toplevel_handle_move, + .resize = xdg_toplevel_handle_resize, + .set_max_size = xdg_toplevel_handle_set_max_size, + .set_min_size = xdg_toplevel_handle_set_min_size, + .set_maximized = xdg_toplevel_handle_set_maximized, + .unset_maximized = xdg_toplevel_handle_unset_maximized, + .set_fullscreen = xdg_toplevel_handle_set_fullscreen, + .unset_fullscreen = xdg_toplevel_handle_unset_fullscreen, + .set_minimized = xdg_toplevel_handle_set_minimized, }; static void xdg_surface_resource_destroy(struct wl_resource *resource) { @@ -822,11 +864,11 @@ static void xdg_toplevel_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); if (surface != NULL) { - xdg_surface_destroy(surface); + xdg_surface_unmap(surface); } } -static void xdg_surface_get_toplevel(struct wl_client *client, +static void xdg_surface_handle_get_toplevel(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct wlr_xdg_surface *surface = xdg_surface_from_resource(resource); @@ -835,24 +877,24 @@ static void xdg_surface_get_toplevel(struct wl_client *client, return; } - surface->toplevel_state = calloc(1, sizeof(struct wlr_xdg_toplevel)); - if (surface->toplevel_state == NULL) { + surface->toplevel = calloc(1, sizeof(struct wlr_xdg_toplevel)); + if (surface->toplevel == NULL) { wl_resource_post_no_memory(resource); return; } surface->role = WLR_XDG_SURFACE_ROLE_TOPLEVEL; - surface->toplevel_state->base = surface; + surface->toplevel->base = surface; struct wl_resource *toplevel_resource = wl_resource_create(client, &xdg_toplevel_interface, wl_resource_get_version(resource), id); if (toplevel_resource == NULL) { - free(surface->toplevel_state); + free(surface->toplevel); wl_resource_post_no_memory(resource); return; } - surface->toplevel_state->resource = toplevel_resource; + surface->toplevel->resource = toplevel_resource; wl_resource_set_implementation(toplevel_resource, &xdg_toplevel_implementation, surface, @@ -863,12 +905,19 @@ static void wlr_xdg_toplevel_ack_configure( struct wlr_xdg_surface *surface, struct wlr_xdg_surface_configure *configure) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel_state->next = configure->state; - surface->toplevel_state->pending.width = 0; - surface->toplevel_state->pending.height = 0; + assert(configure->toplevel_state != NULL); + + surface->toplevel->current.maximized = + configure->toplevel_state->maximized; + surface->toplevel->current.fullscreen = + configure->toplevel_state->fullscreen; + surface->toplevel->current.resizing = + configure->toplevel_state->resizing; + surface->toplevel->current.activated = + configure->toplevel_state->activated; } -static void xdg_surface_ack_configure(struct wl_client *client, +static void xdg_surface_handle_ack_configure(struct wl_client *client, struct wl_resource *resource, uint32_t serial) { struct wlr_xdg_surface *surface = xdg_surface_from_resource(resource); @@ -883,10 +932,8 @@ static void xdg_surface_ack_configure(struct wl_client *client, struct wlr_xdg_surface_configure *configure, *tmp; wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { if (configure->serial < serial) { - wl_list_remove(&configure->link); - free(configure); + xdg_surface_configure_destroy(configure); } else if (configure->serial == serial) { - wl_list_remove(&configure->link); found = true; break; } else { @@ -914,10 +961,10 @@ static void xdg_surface_ack_configure(struct wl_client *client, surface->configured = true; surface->configure_serial = serial; - free(configure); + xdg_surface_configure_destroy(configure); } -static void xdg_surface_set_window_geometry(struct wl_client *client, +static void xdg_surface_handle_set_window_geometry(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) { struct wlr_xdg_surface *surface = xdg_surface_from_resource(resource); @@ -930,19 +977,31 @@ static void xdg_surface_set_window_geometry(struct wl_client *client, } surface->has_next_geometry = true; - surface->next_geometry->height = height; - surface->next_geometry->width = width; - surface->next_geometry->x = x; - surface->next_geometry->y = y; + surface->next_geometry.height = height; + surface->next_geometry.width = width; + surface->next_geometry.x = x; + surface->next_geometry.y = y; +} + +static void xdg_surface_handle_destroy(struct wl_client *client, + struct wl_resource *resource) { + struct wlr_xdg_surface *surface = xdg_surface_from_resource(resource); + if (surface->role != WLR_XDG_SURFACE_ROLE_NONE) { + wlr_log(L_ERROR, "Tried to destroy an xdg_surface before its role " + "object"); + return; + } + + wl_resource_destroy(resource); } static const struct xdg_surface_interface xdg_surface_implementation = { - .destroy = resource_destroy, - .get_toplevel = xdg_surface_get_toplevel, - .get_popup = xdg_surface_get_popup, - .ack_configure = xdg_surface_ack_configure, - .set_window_geometry = xdg_surface_set_window_geometry, + .destroy = xdg_surface_handle_destroy, + .get_toplevel = xdg_surface_handle_get_toplevel, + .get_popup = xdg_surface_handle_get_popup, + .ack_configure = xdg_surface_handle_ack_configure, + .set_window_geometry = xdg_surface_handle_set_window_geometry, }; static bool wlr_xdg_surface_toplevel_state_compare( @@ -965,9 +1024,9 @@ static bool wlr_xdg_surface_toplevel_state_compare( } else { struct wlr_xdg_surface_configure *configure = wl_container_of(state->base->configure_list.prev, configure, link); - configured.state = configure->state; - configured.width = configure->state.width; - configured.height = configure->state.height; + configured.state = *configure->toplevel_state; + configured.width = configure->toplevel_state->width; + configured.height = configure->toplevel_state->height; } if (state->pending.activated != configured.state.activated) { @@ -999,13 +1058,19 @@ static void wlr_xdg_toplevel_send_configure( struct wlr_xdg_surface *surface, struct wlr_xdg_surface_configure *configure) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - uint32_t *s; - struct wl_array states; - configure->state = surface->toplevel_state->pending; + configure->toplevel_state = malloc(sizeof(*configure->toplevel_state)); + if (configure->toplevel_state == NULL) { + wlr_log(L_ERROR, "Allocation failed"); + wl_resource_post_no_memory(surface->toplevel->resource); + return; + } + *configure->toplevel_state = surface->toplevel->pending; + uint32_t *s; + struct wl_array states; wl_array_init(&states); - if (surface->toplevel_state->pending.maximized) { + if (surface->toplevel->pending.maximized) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel"); @@ -1013,7 +1078,7 @@ static void wlr_xdg_toplevel_send_configure( } *s = XDG_TOPLEVEL_STATE_MAXIMIZED; } - if (surface->toplevel_state->pending.fullscreen) { + if (surface->toplevel->pending.fullscreen) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel"); @@ -1021,7 +1086,7 @@ static void wlr_xdg_toplevel_send_configure( } *s = XDG_TOPLEVEL_STATE_FULLSCREEN; } - if (surface->toplevel_state->pending.resizing) { + if (surface->toplevel->pending.resizing) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel"); @@ -1029,7 +1094,7 @@ static void wlr_xdg_toplevel_send_configure( } *s = XDG_TOPLEVEL_STATE_RESIZING; } - if (surface->toplevel_state->pending.activated) { + if (surface->toplevel->pending.activated) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel"); @@ -1038,23 +1103,17 @@ static void wlr_xdg_toplevel_send_configure( *s = XDG_TOPLEVEL_STATE_ACTIVATED; } - uint32_t width = surface->toplevel_state->pending.width; - uint32_t height = surface->toplevel_state->pending.height; - - if (width == 0 || height == 0) { - width = surface->geometry->width; - height = surface->geometry->height; - } - - xdg_toplevel_send_configure(surface->toplevel_state->resource, width, - height, &states); + uint32_t width = surface->toplevel->pending.width; + uint32_t height = surface->toplevel->pending.height; + xdg_toplevel_send_configure(surface->toplevel->resource, width, height, + &states); wl_array_release(&states); return; error_out: wl_array_release(&states); - wl_resource_post_no_memory(surface->toplevel_state->resource); + wl_resource_post_no_memory(surface->toplevel->resource); } static void wlr_xdg_surface_send_configure(void *user_data) { @@ -1080,11 +1139,11 @@ static void wlr_xdg_surface_send_configure(void *user_data) { wlr_xdg_toplevel_send_configure(surface, configure); break; case WLR_XDG_SURFACE_ROLE_POPUP: - xdg_popup_send_configure(surface->popup_state->resource, - surface->popup_state->geometry.x, - surface->popup_state->geometry.y, - surface->popup_state->geometry.width, - surface->popup_state->geometry.height); + xdg_popup_send_configure(surface->popup->resource, + surface->popup->geometry.x, + surface->popup->geometry.y, + surface->popup->geometry.width, + surface->popup->geometry.height); break; } @@ -1103,7 +1162,7 @@ static uint32_t wlr_xdg_surface_schedule_configure( break; case WLR_XDG_SURFACE_ROLE_TOPLEVEL: pending_same = - wlr_xdg_surface_toplevel_state_compare(surface->toplevel_state); + wlr_xdg_surface_toplevel_state_compare(surface->toplevel); break; case WLR_XDG_SURFACE_ROLE_POPUP: break; @@ -1143,29 +1202,32 @@ static void wlr_xdg_surface_toplevel_committed( struct wlr_xdg_surface *surface) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - if (!wlr_surface_has_buffer(surface->surface) - && !surface->toplevel_state->added) { + if (!surface->toplevel->added) { // on the first commit, send a configure request to tell the client it // is added wlr_xdg_surface_schedule_configure(surface); - surface->toplevel_state->added = true; - return; - } - - if (!wlr_surface_has_buffer(surface->surface)) { + surface->toplevel->added = true; return; } - surface->toplevel_state->current = surface->toplevel_state->next; + // update state that doesn't need compositor approval + surface->toplevel->current.max_width = + surface->toplevel->next.max_width; + surface->toplevel->current.min_width = + surface->toplevel->next.min_width; + surface->toplevel->current.max_height = + surface->toplevel->next.max_height; + surface->toplevel->current.min_height = + surface->toplevel->next.min_height; } static void wlr_xdg_surface_popup_committed( struct wlr_xdg_surface *surface) { assert(surface->role == WLR_XDG_SURFACE_ROLE_POPUP); - if (!surface->popup_state->committed) { + if (!surface->popup->committed) { wlr_xdg_surface_schedule_configure(surface); - surface->popup_state->committed = true; + surface->popup->committed = true; } } @@ -1182,10 +1244,10 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, if (surface->has_next_geometry) { surface->has_next_geometry = false; - surface->geometry->x = surface->next_geometry->x; - surface->geometry->y = surface->next_geometry->y; - surface->geometry->width = surface->next_geometry->width; - surface->geometry->height = surface->next_geometry->height; + surface->geometry.x = surface->next_geometry.x; + surface->geometry.y = surface->next_geometry.y; + surface->geometry.width = surface->next_geometry.width; + surface->geometry.height = surface->next_geometry.height; } switch (surface->role) { @@ -1202,9 +1264,19 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, break; } - if (surface->configured && !surface->added) { + if (!surface->added) { surface->added = true; - wlr_signal_emit_safe(&surface->client->shell->events.new_surface, surface); + wlr_signal_emit_safe(&surface->client->shell->events.new_surface, + surface); + } + if (surface->configured && wlr_surface_has_buffer(surface->surface) && + !surface->mapped) { + surface->mapped = true; + wlr_signal_emit_safe(&surface->events.map, surface); + } + if (surface->configured && !wlr_surface_has_buffer(surface->surface) && + surface->mapped) { + xdg_surface_unmap(surface); } } @@ -1217,27 +1289,15 @@ static struct wlr_xdg_client *xdg_client_from_resource( return wl_resource_get_user_data(resource); } -static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, +static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client, struct wl_resource *client_resource, uint32_t id, struct wl_resource *surface_resource) { struct wlr_xdg_client *client = xdg_client_from_resource(client_resource); - struct wlr_xdg_surface *surface; - if (!(surface = calloc(1, sizeof(struct wlr_xdg_surface)))) { - wl_client_post_no_memory(wl_client); - return; - } - - if (!(surface->geometry = calloc(1, sizeof(struct wlr_box)))) { - free(surface); - wl_client_post_no_memory(wl_client); - return; - } - - if (!(surface->next_geometry = calloc(1, sizeof(struct wlr_box)))) { - free(surface->geometry); - free(surface); + struct wlr_xdg_surface *surface = + calloc(1, sizeof(struct wlr_xdg_surface)); + if (surface == NULL) { wl_client_post_no_memory(wl_client); return; } @@ -1249,8 +1309,6 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, &xdg_surface_interface, wl_resource_get_version(client_resource), id); if (surface->resource == NULL) { - free(surface->next_geometry); - free(surface->geometry); free(surface); wl_client_post_no_memory(wl_client); return; @@ -1258,8 +1316,6 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, if (wlr_surface_has_buffer(surface->surface)) { wl_resource_destroy(surface->resource); - free(surface->next_geometry); - free(surface->geometry); free(surface); wl_resource_post_error(surface_resource, XDG_SURFACE_ERROR_UNCONFIGURED_BUFFER, @@ -1279,6 +1335,8 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.ping_timeout); wl_signal_init(&surface->events.new_popup); + wl_signal_init(&surface->events.map); + wl_signal_init(&surface->events.unmap); wl_signal_add(&surface->surface->events.destroy, &surface->surface_destroy_listener); @@ -1293,7 +1351,7 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, wl_list_insert(&client->surfaces, &surface->link); } -static void xdg_shell_pong(struct wl_client *wl_client, +static void xdg_shell_handle_pong(struct wl_client *wl_client, struct wl_resource *resource, uint32_t serial) { struct wlr_xdg_client *client = xdg_client_from_resource(resource); @@ -1305,11 +1363,25 @@ static void xdg_shell_pong(struct wl_client *wl_client, client->ping_serial = 0; } +static void xdg_shell_handle_destroy(struct wl_client *wl_client, + struct wl_resource *resource) { + struct wlr_xdg_client *client = xdg_client_from_resource(resource); + + if (!wl_list_empty(&client->surfaces)) { + wl_resource_post_error(client->resource, + XDG_WM_BASE_ERROR_DEFUNCT_SURFACES, + "xdg_wm_base was destroyed before children"); + return; + } + + wl_resource_destroy(resource); +} + static const struct xdg_wm_base_interface xdg_shell_impl = { - .destroy = resource_destroy, - .create_positioner = xdg_shell_create_positioner, - .get_xdg_surface = xdg_shell_get_xdg_surface, - .pong = xdg_shell_pong, + .destroy = xdg_shell_handle_destroy, + .create_positioner = xdg_shell_handle_create_positioner, + .get_xdg_surface = xdg_shell_handle_get_xdg_surface, + .pong = xdg_shell_handle_pong, }; static void wlr_xdg_client_destroy(struct wl_resource *resource) { @@ -1437,8 +1509,8 @@ void wlr_xdg_surface_ping(struct wlr_xdg_surface *surface) { uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_surface *surface, uint32_t width, uint32_t height) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel_state->pending.width = width; - surface->toplevel_state->pending.height = height; + surface->toplevel->pending.width = width; + surface->toplevel->pending.height = height; return wlr_xdg_surface_schedule_configure(surface); } @@ -1446,7 +1518,7 @@ uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_surface *surface, uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_surface *surface, bool activated) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel_state->pending.activated = activated; + surface->toplevel->pending.activated = activated; return wlr_xdg_surface_schedule_configure(surface); } @@ -1454,7 +1526,7 @@ uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_surface *surface, uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_surface *surface, bool maximized) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel_state->pending.maximized = maximized; + surface->toplevel->pending.maximized = maximized; return wlr_xdg_surface_schedule_configure(surface); } @@ -1462,7 +1534,7 @@ uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_surface *surface, uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_surface *surface, bool fullscreen) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel_state->pending.fullscreen = fullscreen; + surface->toplevel->pending.fullscreen = fullscreen; return wlr_xdg_surface_schedule_configure(surface); } @@ -1470,24 +1542,24 @@ uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_surface *surface, uint32_t wlr_xdg_toplevel_set_resizing(struct wlr_xdg_surface *surface, bool resizing) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel_state->pending.resizing = resizing; + surface->toplevel->pending.resizing = resizing; return wlr_xdg_surface_schedule_configure(surface); } void wlr_xdg_toplevel_send_close(struct wlr_xdg_surface *surface) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - xdg_toplevel_send_close(surface->toplevel_state->resource); + xdg_toplevel_send_close(surface->toplevel->resource); } void wlr_xdg_surface_popup_get_position(struct wlr_xdg_surface *surface, double *popup_sx, double *popup_sy) { assert(surface->role == WLR_XDG_SURFACE_ROLE_POPUP); - struct wlr_xdg_surface *parent = surface->popup_state->parent; - *popup_sx = parent->geometry->x + surface->popup_state->geometry.x - - surface->geometry->x; - *popup_sy = parent->geometry->y + surface->popup_state->geometry.y - - surface->geometry->y; + struct wlr_xdg_surface *parent = surface->popup->parent; + *popup_sx = parent->geometry.x + surface->popup->geometry.x - + surface->geometry.x; + *popup_sy = parent->geometry.y + surface->popup->geometry.y - + surface->geometry.y; } struct wlr_xdg_surface *wlr_xdg_surface_popup_at( @@ -1501,30 +1573,30 @@ struct wlr_xdg_surface *wlr_xdg_surface_popup_at( struct wlr_xdg_surface *popup = popup_state->base; double _popup_sx = - surface->geometry->x + popup_state->geometry.x; + surface->geometry.x + popup_state->geometry.x; double _popup_sy = - surface->geometry->y + popup_state->geometry.y; + surface->geometry.y + popup_state->geometry.y; int popup_width = popup_state->geometry.width; int popup_height = popup_state->geometry.height; struct wlr_xdg_surface *_popup = wlr_xdg_surface_popup_at(popup, - sx - _popup_sx + popup->geometry->x, - sy - _popup_sy + popup->geometry->y, + sx - _popup_sx + popup->geometry.x, + sy - _popup_sy + popup->geometry.y, popup_sx, popup_sy); if (_popup) { - *popup_sx = *popup_sx + _popup_sx - popup->geometry->x; - *popup_sy = *popup_sy + _popup_sy - popup->geometry->y; + *popup_sx = *popup_sx + _popup_sx - popup->geometry.x; + *popup_sy = *popup_sy + _popup_sy - popup->geometry.y; return _popup; } if ((sx > _popup_sx && sx < _popup_sx + popup_width) && (sy > _popup_sy && sy < _popup_sy + popup_height)) { if (pixman_region32_contains_point(&popup->surface->current->input, - sx - _popup_sx + popup->geometry->x, - sy - _popup_sy + popup->geometry->y, NULL)) { - *popup_sx = _popup_sx - popup->geometry->x; - *popup_sy = _popup_sy - popup->geometry->y; + sx - _popup_sx + popup->geometry.x, + sy - _popup_sy + popup->geometry.y, NULL)) { + *popup_sx = _popup_sx - popup->geometry.x; + *popup_sy = _popup_sy - popup->geometry.y; return popup; } } -- cgit v1.2.3 From 303883ce49b81438c8653991f40e72b0481e27cf Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 21:47:20 +0100 Subject: rootston: properly emit view unmap event --- rootston/desktop.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rootston/desktop.c b/rootston/desktop.c index e9a9425c..78076e75 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -459,6 +459,8 @@ void view_map(struct roots_view *view, struct wlr_surface *surface) { void view_unmap(struct roots_view *view) { assert(view->wlr_surface != NULL); + wl_signal_emit(&view->events.unmap, view); + view_damage_whole(view); wl_list_remove(&view->link); -- cgit v1.2.3