From a8fbe1aac207cf7efe8c2f464de3c83c107818dd Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Tue, 13 Sep 2022 12:51:23 -0400 Subject: [PATCH] xdg-popup: Check for NULL from wlr_xdg_surface_from_wlr_surface() Also eliminate struct view_child and replace it with a simple (struct view *)parent_view field. --- src/xdg-popup.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/xdg-popup.c b/src/xdg-popup.c index 3c92d609..36873b6c 100644 --- a/src/xdg-popup.c +++ b/src/xdg-popup.c @@ -10,13 +10,8 @@ #include "labwc.h" #include "node.h" -struct view_child { - struct wlr_surface *surface; - struct view *parent; -}; - struct xdg_popup { - struct view_child view_child; + struct view *parent_view; struct wlr_xdg_popup *wlr_popup; struct wl_listener destroy; @@ -58,20 +53,27 @@ popup_handle_new_xdg_popup(struct wl_listener *listener, void *data) { struct xdg_popup *popup = wl_container_of(listener, popup, new_popup); struct wlr_xdg_popup *wlr_popup = data; - xdg_popup_create(popup->view_child.parent, wlr_popup); + xdg_popup_create(popup->parent_view, wlr_popup); } void xdg_popup_create(struct view *view, struct wlr_xdg_popup *wlr_popup) { + struct wlr_xdg_surface *parent = + wlr_surface_is_xdg_surface(wlr_popup->parent) ? + wlr_xdg_surface_from_wlr_surface(wlr_popup->parent) : NULL; + if (!parent) { + wlr_log(WLR_ERROR, "parent is not a valid XDG surface"); + return; + } + struct xdg_popup *popup = calloc(1, sizeof(struct xdg_popup)); if (!popup) { return; } + popup->parent_view = view; popup->wlr_popup = wlr_popup; - popup->view_child.parent = view; - popup->view_child.surface = wlr_popup->base->surface; popup->destroy.notify = handle_xdg_popup_destroy; wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy); @@ -85,12 +87,6 @@ xdg_popup_create(struct view *view, struct wlr_xdg_popup *wlr_popup) * this, we always set the user data field of xdg_surfaces to the * corresponding scene node. */ - if (!wlr_surface_is_xdg_surface(wlr_popup->parent)) { - wlr_log(WLR_ERROR, "xdg_surface is not xdg"); - return; - } - struct wlr_xdg_surface *parent = - wlr_xdg_surface_from_wlr_surface(wlr_popup->parent); struct wlr_scene_tree *parent_tree = parent->surface->data; wlr_popup->base->surface->data = wlr_scene_xdg_surface_create(parent_tree, wlr_popup->base);