view: Move xdg_surface + xwayland_surface to derived structs

Add xdg_surface_from_view() + xwayland_surface_from_view() accessors
that assert() the view is of the expected type before returning.

Fix a real bug in xdg.c parent_of() that dereferenced
`view->xdg_surface->toplevel` without first checking `view->type`.

The goal of the new accessors is to catch similar bugs in future.
This commit is contained in:
John Lindgren 2022-11-25 13:41:12 -05:00 committed by Johan Malm
parent df7276345f
commit 4da37c6532
7 changed files with 147 additions and 106 deletions

View file

@ -310,9 +310,9 @@ process_cursor_motion_out_of_surface(struct server *server, uint32_t time)
double sx = server->seat.cursor->x - lx;
double sy = server->seat.cursor->y - ly;
/* Take into account invisible xdg-shell CSD borders */
if (view && view->type == LAB_XDG_SHELL_VIEW && view->xdg_surface) {
if (view && view->type == LAB_XDG_SHELL_VIEW) {
struct wlr_box geo;
wlr_xdg_surface_get_geometry(view->xdg_surface, &geo);
wlr_xdg_surface_get_geometry(xdg_surface_from_view(view), &geo);
sx += geo.x;
sy += geo.y;
}