Isn't this a bug in the X11 server then? Also the current code would only hide this problem if the application would issue redundant calls to `ClipCursor`. Or do I overlook something?
No, the X server is free to release the mouse whenever it likes. It's the case for instance when the WM decides to take over when you want to switch to another application. The application is in charge of retrying often enough if it wants the cursor to be grabbed.
We actually probably receive a NotifyGrabbed focus event, when for instance the WM takes a keyboard grab and frees the mouse, but trying to grab it again in response will simply fail.
This is also how it works on Windows and why games are calling ClipCursor repeatedly.
In any case, like I said, this is touching a very sensitive and complex area, so I wouldn't get much hopes to get any changes in, here unless this gets thoroughly tested somehow.
I also think the issue is part of a bigger problem we have, and that it would better be solved by moving all the logic out of the application threads, instead of adding more complexity to the mess.