We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1155

Summary: Should SDL_WM_GrabInput()/X11_GrabInputNoLock() block?
Product: SDL Reporter: Petr Pisar <ppisar>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: renesd, sezeroz
Version: HG 1.2   
Hardware: x86_64   
OS: Linux   
Attachments: Proposed patch for SDL-1.2 unblocking GrabNotViewable case
Test case

Description Petr Pisar 2011-03-01 06:50:35 UTC
There was a thread on SDL mailing list <http://lists.libsdl.org/htdig.cgi/sdl-libsdl.org/2009-February/068334.html> regarding waiting for X11 input grab. I have been poked by an SDL application developer <https://bugzilla.redhat.com/show_bug.cgi?id=664771> who has the same problem.

In short: Public SDL_WM_GrabInput() calls X11_GrabInputNoLock() that loops around XGrabPointer() until it succeeds.

According X11 manual, XGrabPointer() will fail, if window is not visible (return value GrabNotViewable), if other window holds grab already (AlreadyGrabbed), if other window holds grab and has frozen the input (GrabFrozen) and if invalid arguments (window ID etc.) are supplied.

SDL-1.2 branch does not handle these errors. It just waits until it grabs pointer. On the other hand it does not loop on grabbing keyboard focus.

There is also a comment in SDL code that raises this question: What to do in case of error.

Application developers want to return SDL_GRAB_OFF immediately. I worry it will break SDL 1.2 API. OTOH, SDL-1.3 tries to grab only if the window has focus. However it still loops (e.g. on AlreadyGrabbed).

What's your opinion?
Comment 1 Sam Lantinga 2011-03-01 08:25:39 UTC
I was actually thinking about this, this morning!  SDL 1.3 is not going to block, and I'll probably be implementing that code today.

See ya!
Comment 2 Petr Pisar 2011-07-20 07:10:50 UTC
Created attachment 648 [details]
Proposed patch for SDL-1.2 unblocking GrabNotViewable case

This patch changes behavior of SDL-1.2. If SDL window is not viewable, SDL_WM_GrabInput() will not block and will return failure.

My question is whether this patch is acceptable for inclusion into SDL-1.2 or whether it changes API that applications could expect inappropriately.
Comment 3 Petr Pisar 2011-07-20 07:12:24 UTC
Created attachment 649 [details]
Test case

It links to SDL and X11. It moves SDL window out of root window to create not viewable window where XGrabPointer fails.
Comment 4 Sam Lantinga 2011-12-29 01:37:04 UTC
I don't want to change application behavior in 1.2, but you're welcome to submit a patch for SDL 1.3.

Thanks!
Comment 5 Rene Dudfield 2018-08-13 06:57:40 UTC
Note, at least Arch linux includes this: https://git.archlinux.org/svntogit/packages.git/tree/trunk/SDL-1.2.10-GrabNotViewable.patch?h=packages/sdl
Comment 6 Ozkan Sezer 2018-08-16 20:37:03 UTC
Sam:  At least two distros (RedHat/Fedora and Arch) has been applying
this patch for quite some time, e.g. for about 7 years.  Can we at
least provide it under a 'contrib' directory along with its testcase?
Comment 7 Sam Lantinga 2018-08-28 20:07:54 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL/rev/0f469a8b5110