On Wed Aug 30 15:38:12 2023 +0000, Rémi Bernon wrote:
I'm a bit uncomfortable with the double locking everywhere. I think it'd be less scary if we could do something like:
HWND hwnd = wayland_surface_get_hwnd(wl_surface); pthread_mutex_lock(&process_wayland.pointer.mutex); process_wayland.pointer.hwnd = hwnd; pthread_mutex_unlock(&process_wayland.pointer.mutex);
My concern with the above is that the window (and backing wayland surface) could be destroyed (from a different thread) between getting the `hwnd` and setting it as the pointer focus, so we will end up with an invalid `pointer.hwnd` value. Although I am not a big fan of double locking either, having an inconsistent state like this also scares me.
That being said, I think that *at the moment* such an inconsistency would be inconsequential, *as long as the HWND value is not reused* (at least not in any reasonable timeframe). Is there a strong practical guarantee about this?
In such a case sending input events to the destroyed HWND would be nops and we would use `wayland_surface_lock_hwnd()` to get the surface when we need it (e.g, in `enter` to set the cursor, and in the future we will need it in `motion` for proper input coordinate system transformations), which would return NULL for a destroyed HWND. If this approach sounds more appealing than what is currently proposed, I will need to explore it more and ensure (for some value of "ensure") that there aren't any other races or edge cases that could affect us (especially related to concurrent window destruction).