Alexandros Frantzis (@afrantzis) commented about dlls/winewayland.drv/wayland_surface.c:
} pthread_mutex_unlock(&process_wayland.pointer.mutex);
- if (process_wayland.keyboard.focused_hwnd == surface->hwnd)
process_wayland.keyboard.focused_hwnd = NULL;
This compare-exchange operation needs to be explicitly atomic or locked, to avoid the following thread interleaving scenario:
1. [Wayland] keyboard enter hwnd1 2. [Window] destroy hwnd1, up until and including the `focused_hwnd == surface->hwnd` check above. 3. [Wayland] keyboard leave hwnd1 4. [Wayland] keyboard enter hwnd2 5. [Window] continue destroy hwnd1, setting `focused_hwnd = NULL`, so hwnd2 loses focus
This also means that all other accesses to `focused_hwnd` should ideally also be locked or explicitly atomic (to guarantee memory order). Looking at subsequent commits, I think both approaches would work, but since we are going to have a lock anyway (for xkb_state), perhaps it would be simpler to just use that for all keyboard synchronization needs.