Updated with the last patch series to make the state/config change requests asynchronous I believe this is working fine now. I also included a fix for https://bugs.winehq.org/show_bug.cgi?id=57423
This will then make it possible to handle client state updates during event polling, as well as requesting client state updates outside of the event handlers.
There's still some occasional test failures, but they are caused by some remaining focus race condition, either triggered by multiple threads creating windows concurrently, or by FVWM bug which causes it to randomly lose focus.