Skip to content

wayland: Unset keyboard focus if surface is destroyed

Depending on the ordering of the surface-associated resources being destroyed, we may fall into the following situation:

  • wl_surface is destroyed
  • destruction notifications for the surface runs
  • The MetaWaylandKeyboard attempts to synchronize the window focus
  • The MetaWindow is not destroyed yet, so the focused window remains the same, and the MetaWaylandKeyboard keeps the same focus MetaWaylandSurface.
  • wl_surface finalizes destruction, MetaWaylandSurface now has a NULL resource
  • xdg_toplevel destructor kicks in, it unmanages the window
  • The current focus window is again looked up, forced to look a different window
  • The MetaWaylandKeyboard focus now changes, tries to leave the old surface, but it has a NULL resource already, and raises a protocol error.

If the order is inverted, the window being unmanaged triggers a focus change into a different window, the MetaWaylandKeyboard triggers a focus change while the MetaWaylandSurface is still intact, it succeeds, and the window gets properly destroyed.

In order to make this independent of the order, it makes sense to make MetaWaylandKeyboard do like the other objects tracking focus surfaces, and have it care of its own little parcel. The surface destructor changed to simply unsetting the keyboard focus to NULL (guaranteeing that the old focus is left while the surface resource is still up), and leaving potential focus changes to the xdg_toplevel_destructor->unmanage->update_focus paths.

Closes: #2853 (closed)

Merge request reports