From c35d14ecfaf785cbf557c6106372ea68e0b8011e Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Sat, 8 Jan 2022 22:52:55 +0300 Subject: [PATCH] xdg-shell: extract role-specific unmap logic --- include/types/wlr_xdg_shell.h | 3 ++- types/xdg_shell/wlr_xdg_popup.c | 21 +++++++++++++++++ types/xdg_shell/wlr_xdg_surface.c | 38 +++--------------------------- types/xdg_shell/wlr_xdg_toplevel.c | 25 ++++++++++++++++---- 4 files changed, 46 insertions(+), 41 deletions(-) diff --git a/include/types/wlr_xdg_shell.h b/include/types/wlr_xdg_shell.h index 7613a15d..0c2b5cd5 100644 --- a/include/types/wlr_xdg_shell.h +++ b/include/types/wlr_xdg_shell.h @@ -30,17 +30,18 @@ struct wlr_xdg_positioner_resource *get_xdg_positioner_from_resource( void create_xdg_popup(struct wlr_xdg_surface *surface, struct wlr_xdg_surface *parent, struct wlr_xdg_positioner_resource *positioner, uint32_t id); +void unmap_xdg_popup(struct wlr_xdg_popup *popup); void handle_xdg_popup_committed(struct wlr_xdg_popup *popup); struct wlr_xdg_popup_grab *get_xdg_shell_popup_grab_from_seat( struct wlr_xdg_shell *shell, struct wlr_seat *seat); void create_xdg_toplevel(struct wlr_xdg_surface *surface, uint32_t id); +void unmap_xdg_toplevel(struct wlr_xdg_toplevel *toplevel); void handle_xdg_toplevel_committed(struct wlr_xdg_toplevel *toplevel); struct wlr_xdg_toplevel_configure *send_xdg_toplevel_configure( struct wlr_xdg_toplevel *toplevel); void handle_xdg_toplevel_ack_configure(struct wlr_xdg_toplevel *toplevel, struct wlr_xdg_toplevel_configure *configure); -void destroy_xdg_toplevel(struct wlr_xdg_toplevel *toplevel); #endif diff --git a/types/xdg_shell/wlr_xdg_popup.c b/types/xdg_shell/wlr_xdg_popup.c index 7066893a..17b71cd4 100644 --- a/types/xdg_shell/wlr_xdg_popup.c +++ b/types/xdg_shell/wlr_xdg_popup.c @@ -355,6 +355,27 @@ void create_xdg_popup(struct wlr_xdg_surface *surface, } } +void unmap_xdg_popup(struct wlr_xdg_popup *popup) { + if (popup->seat != NULL) { + struct wlr_xdg_popup_grab *grab = + get_xdg_shell_popup_grab_from_seat( + popup->base->client->shell, popup->seat); + + wl_list_remove(&popup->grab_link); + + if (wl_list_empty(&grab->popups)) { + if (grab->seat->pointer_state.grab == &grab->pointer_grab) { + wlr_seat_pointer_end_grab(grab->seat); + } + if (grab->seat->keyboard_state.grab == &grab->keyboard_grab) { + wlr_seat_keyboard_end_grab(grab->seat); + } + } + + popup->seat = NULL; + } +} + void wlr_xdg_popup_destroy(struct wlr_xdg_popup *popup) { if (popup == NULL) { return; diff --git a/types/xdg_shell/wlr_xdg_surface.c b/types/xdg_shell/wlr_xdg_surface.c index 7db308c0..ff8d0d97 100644 --- a/types/xdg_shell/wlr_xdg_surface.c +++ b/types/xdg_shell/wlr_xdg_surface.c @@ -42,34 +42,10 @@ void unmap_xdg_surface(struct wlr_xdg_surface *surface) { switch (surface->role) { case WLR_XDG_SURFACE_ROLE_TOPLEVEL: - if (surface->toplevel->parent) { - wl_list_remove(&surface->toplevel->parent_unmap.link); - surface->toplevel->parent = NULL; - } - free(surface->toplevel->title); - surface->toplevel->title = NULL; - free(surface->toplevel->app_id); - surface->toplevel->app_id = NULL; + unmap_xdg_toplevel(surface->toplevel); break; case WLR_XDG_SURFACE_ROLE_POPUP: - if (surface->popup->seat != NULL) { - struct wlr_xdg_popup_grab *grab = - get_xdg_shell_popup_grab_from_seat(surface->client->shell, - surface->popup->seat); - - wl_list_remove(&surface->popup->grab_link); - - if (wl_list_empty(&grab->popups)) { - if (grab->seat->pointer_state.grab == &grab->pointer_grab) { - wlr_seat_pointer_end_grab(grab->seat); - } - if (grab->seat->keyboard_state.grab == &grab->keyboard_grab) { - wlr_seat_keyboard_end_grab(grab->seat); - } - } - - surface->popup->seat = NULL; - } + unmap_xdg_popup(surface->popup); break; case WLR_XDG_SURFACE_ROLE_NONE: assert(false && "not reached"); @@ -436,21 +412,13 @@ void reset_xdg_surface(struct wlr_xdg_surface *surface) { switch (surface->role) { case WLR_XDG_SURFACE_ROLE_TOPLEVEL: wl_resource_set_user_data(surface->toplevel->resource, NULL); - surface->toplevel->resource = NULL; - struct wlr_xdg_toplevel_requested *req = - &surface->toplevel->requested; - if (req->fullscreen_output) { - wl_list_remove(&req->fullscreen_output_destroy.link); - } free(surface->toplevel); surface->toplevel = NULL; break; case WLR_XDG_SURFACE_ROLE_POPUP: - wl_resource_set_user_data(surface->popup->resource, NULL); - surface->popup->resource = NULL; - wl_list_remove(&surface->popup->link); + wl_resource_set_user_data(surface->popup->resource, NULL); free(surface->popup); surface->popup = NULL; break; diff --git a/types/xdg_shell/wlr_xdg_toplevel.c b/types/xdg_shell/wlr_xdg_toplevel.c index e1f9a91d..8bbec935 100644 --- a/types/xdg_shell/wlr_xdg_toplevel.c +++ b/types/xdg_shell/wlr_xdg_toplevel.c @@ -426,7 +426,10 @@ static const struct xdg_toplevel_interface xdg_toplevel_implementation = { static void xdg_toplevel_handle_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_toplevel *toplevel = wlr_xdg_toplevel_from_resource(resource); - destroy_xdg_toplevel(toplevel); + if (toplevel == NULL) { + return; + } + reset_xdg_surface(toplevel->base); } const struct wlr_surface_role xdg_toplevel_surface_role = { @@ -482,11 +485,23 @@ void create_xdg_toplevel(struct wlr_xdg_surface *surface, surface->role = WLR_XDG_SURFACE_ROLE_TOPLEVEL; } -void destroy_xdg_toplevel(struct wlr_xdg_toplevel *toplevel) { - if (toplevel == NULL) { - return; +void unmap_xdg_toplevel(struct wlr_xdg_toplevel *toplevel) { + if (toplevel->parent) { + wl_list_remove(&toplevel->parent_unmap.link); + toplevel->parent = NULL; } - reset_xdg_surface(toplevel->base); + free(toplevel->title); + toplevel->title = NULL; + free(toplevel->app_id); + toplevel->app_id = NULL; + + if (toplevel->requested.fullscreen_output) { + wl_list_remove(&toplevel->requested.fullscreen_output_destroy.link); + toplevel->requested.fullscreen_output = NULL; + } + toplevel->requested.fullscreen = false; + toplevel->requested.maximized = false; + toplevel->requested.minimized = false; } void wlr_xdg_toplevel_send_close(struct wlr_xdg_toplevel *toplevel) {