On Wed Aug 30 15:38:14 2023 +0000, Rémi Bernon wrote:
Do we have to set the cursor here? Could it wait until `SetCursor` is called instead? Fwiw it should be called on every window/cursor change now, and I think it would save you the need to keep the window cursor surface around, unless it is required after `wl_pointer_set_cursor`.
We need to keep the cursor `wl_surface` around, since destroying a `wl_surface` while it has a role (the cursor role in this case) is a protocol error.
Concerning whether we have to set the cursor here or wait for `SetCursor`: what I am seeing is that after leaving a window for the desktop area and then reentering that window we don't get a new `SetCursor` callback. That's true for both the Wayland driver and the X11 driver. If this is not intended, what I assume is happening is that since neither driver is informing Wine about leave events, from Wine's perspective the cursor stays within that window, although it has left the window in the native system.
This is less of a problem for WineX11 because `XDefineCursor` is persistent, whereas `wl_pointer_set_cursor` is ephemeral (valid only while the surface has the focus) and needs to be called after every `enter` event. The proposed approach effectively matches the WineX11 behavior.
If we could guarantee that after *every* `enter` we would get a `SetCursor`, we could drop the `wl_pointer_set_cursor` here. Even then it's not clear that doing so would provide the best user experience. Different compositors deal differently with the lack of a set cursor after `enter`: some show no cursor, some keep whatever cursor was shown before entering. If a compositor does the former, then there could be a short cursor flicker when entering the surface: after `enter` no cursor is set, so the compositor hides it, after a bit `SetCursor` is called and the right cursor is set. If the compositor does the latter then the transition will be smoother.
Of course, even with the current approach things are not perfect (but at least match WineX11), since on enter we will (possibly transiently) use whatever cursor was last used for that window, which could be incorrect. In the end, if the transitions are quick enough it may not matter what approach we use.