-
Notifications
You must be signed in to change notification settings - Fork 903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retry XGrabPointer a couple of times (up to 500ms) if it failes #1961
base: master
Are you sure you want to change the base?
Conversation
This can happen if we try to grab the pointer right after we created the window
Is there something I can do to speed up merging? Or is something missing? I'm not too familiar with the process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome!
Depending on the application, this delay may be significant, so I recommend adding a warning about this to the documentation of the set_cursor_grab
function. If you have any better idea how we can let the developers know about this, I'm open to other suggestions.
Would a viable alternative be to wait until the first cursor event is received and then request the cursor grab? It shouldn't make any difference to the user except that if the cursor isn't initially over the window it won't be captured until it is (which seems fine?). That way you're never blocking. |
Related: #2080 |
The SDL solution to this looks like a hack really. The X11 backend could be updated to track the 'mapped' state of the window to account for the asynchronous nature of creating X windows. The code for cursor grabs would then need to have a "pending" state that's used in case the window is not currently mapped. Whenever winit gets notified of a window being mapped then it would check for any pending grabs an then apply them, which should then succeed. |
Once #3122 is merged, I can update this PR to wait for events using the new userspace event queue introduced in that PR. |
If you try to grab the cursor right after you created the window you get the error:
Minimal repro:
Checking the sdl implementation, it looks like they are solving it by retrying it a couple of times:
https://github.com/libsdl-org/SDL/blob/e65a6583201ee1a9a3bc3064655b186fc16ef719/src/video/x11/SDL_x11window.c#L1611-L1619
This PR simply implements the same scheme and retries XGrabPointer up to 10 times with a slight delay between each, for a total delay up to 500ms.
cargo fmt
has been run on this branchcargo doc
builds successfullyCHANGELOG.md
if knowledge of this change could be valuable to users