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.
This commit is contained in:
John Lindgren 2022-09-13 12:51:23 -04:00
parent b8c3fdaef9
commit a8fbe1aac2

View file

@ -10,13 +10,8 @@
#include "labwc.h" #include "labwc.h"
#include "node.h" #include "node.h"
struct view_child {
struct wlr_surface *surface;
struct view *parent;
};
struct xdg_popup { struct xdg_popup {
struct view_child view_child; struct view *parent_view;
struct wlr_xdg_popup *wlr_popup; struct wlr_xdg_popup *wlr_popup;
struct wl_listener destroy; 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 xdg_popup *popup = wl_container_of(listener, popup, new_popup);
struct wlr_xdg_popup *wlr_popup = data; 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 void
xdg_popup_create(struct view *view, struct wlr_xdg_popup *wlr_popup) 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)); struct xdg_popup *popup = calloc(1, sizeof(struct xdg_popup));
if (!popup) { if (!popup) {
return; return;
} }
popup->parent_view = view;
popup->wlr_popup = wlr_popup; 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; popup->destroy.notify = handle_xdg_popup_destroy;
wl_signal_add(&wlr_popup->base->events.destroy, &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 * this, we always set the user data field of xdg_surfaces to the
* corresponding scene node. * 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; struct wlr_scene_tree *parent_tree = parent->surface->data;
wlr_popup->base->surface->data = wlr_popup->base->surface->data =
wlr_scene_xdg_surface_create(parent_tree, wlr_popup->base); wlr_scene_xdg_surface_create(parent_tree, wlr_popup->base);