From 88f30404386ce305b436b3877a56034eada3060f Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Sat, 8 Jan 2022 22:52:56 +0300 Subject: [PATCH] xdg-popup: destroy popup-less grab This also fixes a seat destruction segfaulting if xdg-shell was destroyed first. --- include/types/wlr_xdg_shell.h | 2 -- types/xdg_shell/wlr_xdg_popup.c | 26 +++++++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/types/wlr_xdg_shell.h b/include/types/wlr_xdg_shell.h index 0c2b5cd5..c0f97798 100644 --- a/include/types/wlr_xdg_shell.h +++ b/include/types/wlr_xdg_shell.h @@ -32,8 +32,6 @@ void create_xdg_popup(struct wlr_xdg_surface *surface, 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); diff --git a/types/xdg_shell/wlr_xdg_popup.c b/types/xdg_shell/wlr_xdg_popup.c index 6f887fca..6fca3316 100644 --- a/types/xdg_shell/wlr_xdg_popup.c +++ b/types/xdg_shell/wlr_xdg_popup.c @@ -148,15 +148,15 @@ static const struct wlr_touch_grab_interface xdg_touch_grab_impl = { .cancel = xdg_touch_grab_cancel }; -static void xdg_popup_grab_handle_seat_destroy( - struct wl_listener *listener, void *data) { - struct wlr_xdg_popup_grab *xdg_grab = - wl_container_of(listener, xdg_grab, seat_destroy); +static void destroy_xdg_popup_grab(struct wlr_xdg_popup_grab *xdg_grab) { + if (xdg_grab == NULL) { + return; + } wl_list_remove(&xdg_grab->seat_destroy.link); - struct wlr_xdg_popup *popup, *next; - wl_list_for_each_safe(popup, next, &xdg_grab->popups, grab_link) { + struct wlr_xdg_popup *popup, *tmp; + wl_list_for_each_safe(popup, tmp, &xdg_grab->popups, grab_link) { destroy_xdg_surface(popup->base); } @@ -164,7 +164,14 @@ static void xdg_popup_grab_handle_seat_destroy( free(xdg_grab); } -struct wlr_xdg_popup_grab *get_xdg_shell_popup_grab_from_seat( +static void xdg_popup_grab_handle_seat_destroy( + struct wl_listener *listener, void *data) { + struct wlr_xdg_popup_grab *xdg_grab = + wl_container_of(listener, xdg_grab, seat_destroy); + destroy_xdg_popup_grab(xdg_grab); +} + +static struct wlr_xdg_popup_grab *get_xdg_shell_popup_grab_from_seat( struct wlr_xdg_shell *shell, struct wlr_seat *seat) { struct wlr_xdg_popup_grab *xdg_grab; wl_list_for_each(xdg_grab, &shell->popup_grabs, link) { @@ -371,6 +378,11 @@ void unmap_xdg_popup(struct wlr_xdg_popup *popup) { if (grab->seat->keyboard_state.grab == &grab->keyboard_grab) { wlr_seat_keyboard_end_grab(grab->seat); } + if (grab->seat->touch_state.grab == &grab->touch_grab) { + wlr_seat_touch_end_grab(grab->seat); + } + + destroy_xdg_popup_grab(grab); } popup->seat = NULL;