Don't assume xdg_surface.{toplevel,popup} is non-NULL

This assumption will become incorrect with future commits.
This commit is contained in:
Kirill Primak 2023-07-26 10:50:09 +03:00 committed by Simon Ser
parent f0cc712af1
commit 10ba8ebc70
4 changed files with 44 additions and 20 deletions

View File

@ -122,7 +122,9 @@ static void focus_view(struct tinywl_view *view, struct wlr_surface *surface) {
struct wlr_xdg_surface *previous = struct wlr_xdg_surface *previous =
wlr_xdg_surface_try_from_wlr_surface(seat->keyboard_state.focused_surface); wlr_xdg_surface_try_from_wlr_surface(seat->keyboard_state.focused_surface);
assert(previous != NULL && previous->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); assert(previous != NULL && previous->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
wlr_xdg_toplevel_set_activated(previous->toplevel, false); if (previous->toplevel != NULL) {
wlr_xdg_toplevel_set_activated(previous->toplevel, false);
}
} }
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat); struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat);
/* Move the view to the front */ /* Move the view to the front */

View File

@ -59,8 +59,10 @@ static void scene_xdg_surface_update_position(
if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) {
struct wlr_xdg_popup *popup = xdg_surface->popup; struct wlr_xdg_popup *popup = xdg_surface->popup;
wlr_scene_node_set_position(&scene_xdg_surface->tree->node, if (popup != NULL) {
popup->current.geometry.x, popup->current.geometry.y); wlr_scene_node_set_position(&scene_xdg_surface->tree->node,
popup->current.geometry.x, popup->current.geometry.y);
}
} }
} }

View File

@ -485,7 +485,7 @@ void wlr_xdg_popup_get_toplevel_coords(struct wlr_xdg_popup *popup,
struct wlr_surface *parent = popup->parent; struct wlr_surface *parent = popup->parent;
struct wlr_xdg_surface *xdg_surface; struct wlr_xdg_surface *xdg_surface;
while ((xdg_surface = wlr_xdg_surface_try_from_wlr_surface(parent))) { while ((xdg_surface = wlr_xdg_surface_try_from_wlr_surface(parent))) {
if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP && xdg_surface->popup != NULL) {
popup_sx += xdg_surface->popup->current.geometry.x; popup_sx += xdg_surface->popup->current.geometry.x;
popup_sy += xdg_surface->popup->current.geometry.y; popup_sy += xdg_surface->popup->current.geometry.y;
parent = xdg_surface->popup->parent; parent = xdg_surface->popup->parent;

View File

@ -37,10 +37,14 @@ static void reset_xdg_surface(struct wlr_xdg_surface *surface) {
switch (surface->role) { switch (surface->role) {
case WLR_XDG_SURFACE_ROLE_TOPLEVEL: case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
reset_xdg_toplevel(surface->toplevel); if (surface->toplevel != NULL) {
reset_xdg_toplevel(surface->toplevel);
}
break; break;
case WLR_XDG_SURFACE_ROLE_POPUP: case WLR_XDG_SURFACE_ROLE_POPUP:
reset_xdg_popup(surface->popup); if (surface->popup != NULL) {
reset_xdg_popup(surface->popup);
}
break; break;
case WLR_XDG_SURFACE_ROLE_NONE: case WLR_XDG_SURFACE_ROLE_NONE:
break; break;
@ -100,12 +104,16 @@ static void xdg_surface_handle_ack_configure(struct wl_client *client,
assert(0 && "not reached"); assert(0 && "not reached");
break; break;
case WLR_XDG_SURFACE_ROLE_TOPLEVEL: case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
handle_xdg_toplevel_ack_configure(surface->toplevel, if (surface->toplevel != NULL) {
configure->toplevel_configure); handle_xdg_toplevel_ack_configure(surface->toplevel,
configure->toplevel_configure);
}
break; break;
case WLR_XDG_SURFACE_ROLE_POPUP: case WLR_XDG_SURFACE_ROLE_POPUP:
handle_xdg_popup_ack_configure(surface->popup, if (surface->popup != NULL) {
configure->popup_configure); handle_xdg_popup_ack_configure(surface->popup,
configure->popup_configure);
}
break; break;
} }
@ -137,12 +145,16 @@ static void surface_send_configure(void *user_data) {
assert(0 && "not reached"); assert(0 && "not reached");
break; break;
case WLR_XDG_SURFACE_ROLE_TOPLEVEL: case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
configure->toplevel_configure = if (surface->toplevel != NULL) {
send_xdg_toplevel_configure(surface->toplevel); configure->toplevel_configure =
send_xdg_toplevel_configure(surface->toplevel);
}
break; break;
case WLR_XDG_SURFACE_ROLE_POPUP: case WLR_XDG_SURFACE_ROLE_POPUP:
configure->popup_configure = if (surface->popup != NULL) {
send_xdg_popup_configure(surface->popup); configure->popup_configure =
send_xdg_popup_configure(surface->popup);
}
break; break;
} }
@ -288,10 +300,14 @@ void xdg_surface_role_commit(struct wlr_surface *wlr_surface) {
// inert toplevel or popup // inert toplevel or popup
return; return;
case WLR_XDG_SURFACE_ROLE_TOPLEVEL: case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
handle_xdg_toplevel_committed(surface->toplevel); if (surface->toplevel != NULL) {
handle_xdg_toplevel_committed(surface->toplevel);
}
break; break;
case WLR_XDG_SURFACE_ROLE_POPUP: case WLR_XDG_SURFACE_ROLE_POPUP:
handle_xdg_popup_committed(surface->popup); if (surface->popup != NULL) {
handle_xdg_popup_committed(surface->popup);
}
break; break;
} }
@ -391,12 +407,16 @@ void destroy_xdg_surface_role_object(struct wlr_xdg_surface *surface) {
switch (surface->role) { switch (surface->role) {
case WLR_XDG_SURFACE_ROLE_TOPLEVEL: case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
destroy_xdg_toplevel(surface->toplevel); if (surface->toplevel != NULL) {
surface->toplevel = NULL; destroy_xdg_toplevel(surface->toplevel);
surface->toplevel = NULL;
}
break; break;
case WLR_XDG_SURFACE_ROLE_POPUP: case WLR_XDG_SURFACE_ROLE_POPUP:
destroy_xdg_popup(surface->popup); if (surface->popup != NULL) {
surface->popup = NULL; destroy_xdg_popup(surface->popup);
surface->popup = NULL;
}
break; break;
case WLR_XDG_SURFACE_ROLE_NONE: case WLR_XDG_SURFACE_ROLE_NONE:
// This space is intentionally left blank // This space is intentionally left blank