Since the role objects in the wayland_surface struct are part of a union, we first need to check whether the surface has the right role before checking the role objects themselves. Otherwise we risk using a subsurface as a toplevel or vice-versa.
The second commit introduces a helper to deduplicate the toplevel checks.