Allow keyboard and pointer grabs to hook clear_focus()
This is necessary for some grabs, which currently have no way of knowing when the pointer/keyboard focus has left a surface. For example, without this, a drag-and-drop grab can erroneously drop into a window that the cursor is no longer over.
This is the plumbing needed to properly fix swaywm/sway#5220. The existing fix, swaywm/sway#5222, relies on every grab's enter()
hook allowing a NULL
surface. This is not guaranteed by the API and, in fact, is not the case for the xdg-shell popup grab and results in a crash when the cursor leaves a surface and does not immediately enter another one while a popup is open (#2161 (closed)).
This fix also adds an assertion to wlr_seat_pointer_notify_enter() that ensures it's never called with a NULL
surface. This will make Sway crash much more until it fixes its usage of the API, so we should land this at the same time as a fix in Sway (which I haven't posted yet).
Also clean up the header declarations a bit in separate commits.
Unanswered questions:
- Should we rename the
clear_focus
functions toleave
like suggested by @emersion in #2162? that seems like a more breaking change to me, and I'm not sure it's worth it. - Do
wlr_seat_touch_point_focus()
andwlr_seat_touch_point_clear_focus()
also need the same treatment? I have no touch device to test with, and these functions aren't used by Sway or by tinywl. It looks like they were/are used by rootston, though.
Breaking change: the wlr_seat_*_enter
family of functions used to segfault when a NULL surface was passed under some circumstances, they now assert that the surface isn't NULL.