Also, from what I understand, it's the foreground thread that receives the ClipCursor callback, but that can become out of sync with the currently pointer focused_hwnd which I am using here.
Yes. And focus_hwnd might very well a window belonging to the same process but a different thread, if the cursor is outside of the active window, or somehow the other window is covering it.
This guarantees that this callback will always be called in the matching (i.e., foreground) thread (except possibly the reset case), so no check is required, correct? Of course the constraint will likely be applied by the compositor only when the surface it gets the Wayland focus.
I think as well.