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

This assumption will become incorrect with future commits.
master
Kirill Primak 1 year ago committed by Simon Ser
parent f0cc712af1
commit 10ba8ebc70

@ -122,8 +122,10 @@ 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);
if (previous->toplevel != NULL) {
wlr_xdg_toplevel_set_activated(previous->toplevel, false); 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 */
wlr_scene_node_raise_to_top(&view->scene_tree->node); wlr_scene_node_raise_to_top(&view->scene_tree->node);

@ -59,10 +59,12 @@ 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;
if (popup != NULL) {
wlr_scene_node_set_position(&scene_xdg_surface->tree->node, wlr_scene_node_set_position(&scene_xdg_surface->tree->node,
popup->current.geometry.x, popup->current.geometry.y); popup->current.geometry.x, popup->current.geometry.y);
} }
} }
}
static void scene_xdg_surface_handle_xdg_surface_commit(struct wl_listener *listener, static void scene_xdg_surface_handle_xdg_surface_commit(struct wl_listener *listener,
void *data) { void *data) {

@ -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;

@ -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:
if (surface->toplevel != NULL) {
reset_xdg_toplevel(surface->toplevel); reset_xdg_toplevel(surface->toplevel);
}
break; break;
case WLR_XDG_SURFACE_ROLE_POPUP: case WLR_XDG_SURFACE_ROLE_POPUP:
if (surface->popup != NULL) {
reset_xdg_popup(surface->popup); 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:
if (surface->toplevel != NULL) {
handle_xdg_toplevel_ack_configure(surface->toplevel, handle_xdg_toplevel_ack_configure(surface->toplevel,
configure->toplevel_configure); configure->toplevel_configure);
}
break; break;
case WLR_XDG_SURFACE_ROLE_POPUP: case WLR_XDG_SURFACE_ROLE_POPUP:
if (surface->popup != NULL) {
handle_xdg_popup_ack_configure(surface->popup, handle_xdg_popup_ack_configure(surface->popup,
configure->popup_configure); 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:
if (surface->toplevel != NULL) {
configure->toplevel_configure = configure->toplevel_configure =
send_xdg_toplevel_configure(surface->toplevel); send_xdg_toplevel_configure(surface->toplevel);
}
break; break;
case WLR_XDG_SURFACE_ROLE_POPUP: case WLR_XDG_SURFACE_ROLE_POPUP:
if (surface->popup != NULL) {
configure->popup_configure = configure->popup_configure =
send_xdg_popup_configure(surface->popup); 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:
if (surface->toplevel != NULL) {
handle_xdg_toplevel_committed(surface->toplevel); handle_xdg_toplevel_committed(surface->toplevel);
}
break; break;
case WLR_XDG_SURFACE_ROLE_POPUP: case WLR_XDG_SURFACE_ROLE_POPUP:
if (surface->popup != NULL) {
handle_xdg_popup_committed(surface->popup); 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:
if (surface->toplevel != NULL) {
destroy_xdg_toplevel(surface->toplevel); destroy_xdg_toplevel(surface->toplevel);
surface->toplevel = NULL; surface->toplevel = NULL;
}
break; break;
case WLR_XDG_SURFACE_ROLE_POPUP: case WLR_XDG_SURFACE_ROLE_POPUP:
if (surface->popup != NULL) {
destroy_xdg_popup(surface->popup); destroy_xdg_popup(surface->popup);
surface->popup = NULL; 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

Loading…
Cancel
Save