xdg-popup: destroy popup-less grab

This also fixes a seat destruction segfaulting if xdg-shell was
destroyed first.
This commit is contained in:
Kirill Primak 2022-01-08 22:52:56 +03:00
parent d2b36b7bd1
commit 88f3040438
2 changed files with 19 additions and 9 deletions

View file

@ -32,8 +32,6 @@ void create_xdg_popup(struct wlr_xdg_surface *surface,
struct wlr_xdg_positioner_resource *positioner, uint32_t id); struct wlr_xdg_positioner_resource *positioner, uint32_t id);
void unmap_xdg_popup(struct wlr_xdg_popup *popup); void unmap_xdg_popup(struct wlr_xdg_popup *popup);
void handle_xdg_popup_committed(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, void create_xdg_toplevel(struct wlr_xdg_surface *surface,
uint32_t id); uint32_t id);

View file

@ -148,15 +148,15 @@ static const struct wlr_touch_grab_interface xdg_touch_grab_impl = {
.cancel = xdg_touch_grab_cancel .cancel = xdg_touch_grab_cancel
}; };
static void xdg_popup_grab_handle_seat_destroy( static void destroy_xdg_popup_grab(struct wlr_xdg_popup_grab *xdg_grab) {
struct wl_listener *listener, void *data) { if (xdg_grab == NULL) {
struct wlr_xdg_popup_grab *xdg_grab = return;
wl_container_of(listener, xdg_grab, seat_destroy); }
wl_list_remove(&xdg_grab->seat_destroy.link); wl_list_remove(&xdg_grab->seat_destroy.link);
struct wlr_xdg_popup *popup, *next; struct wlr_xdg_popup *popup, *tmp;
wl_list_for_each_safe(popup, next, &xdg_grab->popups, grab_link) { wl_list_for_each_safe(popup, tmp, &xdg_grab->popups, grab_link) {
destroy_xdg_surface(popup->base); destroy_xdg_surface(popup->base);
} }
@ -164,7 +164,14 @@ static void xdg_popup_grab_handle_seat_destroy(
free(xdg_grab); 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_shell *shell, struct wlr_seat *seat) {
struct wlr_xdg_popup_grab *xdg_grab; struct wlr_xdg_popup_grab *xdg_grab;
wl_list_for_each(xdg_grab, &shell->popup_grabs, link) { 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) { if (grab->seat->keyboard_state.grab == &grab->keyboard_grab) {
wlr_seat_keyboard_end_grab(grab->seat); 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; popup->seat = NULL;