I want to create an application in which I draw a window, either in windowed or in fullscreen mode, where I have a captured mouse, but without intercepting any keyboard shortcuts, such as Alt + Tab, and I also need to be notified when the user Enters / leaves focus.
Regular apps like Google Chrome, Firefox, or gnome-terminal can handle this just fine (in full screen with F11, but with Alt + Tab), but they don't capture the mouse.
SDL has the notorious poor handling of this use case: SDL_WM_GrabInput captures the mouse, but also captures WM keyboard shortcuts; and SDL_FULLSCREEN seems to have a kind of automatic capture on its own (don't ask me why).
The solution may be to write the code for Alt + Tab yourself, but this sucks (and does not help for other WM shortcuts, for example, to move to another workspace).
Another solution is not to call SDL_WM_GrabInput, but instead fake the capture: just hide the mouse pointer (with SDL_ShowCursor) and move it back to the center whenever the user moves. Which is ugly, but works in practice - except, of course, for SDL_FULLSCREEN, because it captures automatically (as opposed to normal implementations). It is an SDL solution with full screen support, but it is still not what I want. I do not want to have hacks to enable or disable capture, I want to capture a mouse, but miss the keyboard.
So, I'm angry with SDL and want to see alternatives. I would like to use SDL, but this is optional.
This question seems to indicate that the SDL actually uses the XGrabKeyboard. When reading the man page, itโs not immediately clear to me whether you can grab the mouse without grabbing the keyboard (I never used Xlib).
I know how to make "fake full-screen mode" with GTK (i.e. friendly Alt + Tab, a kind of gnome-terminal). I believe this, combined with hiding the mouse and moving it back to the center (โfake gripโ), can do the trick, but it looks like too much masking tape. There should be an easier way. (Also, I don't want to add GTK to the dependency, but I'm also not sure that making raw Xlib calls is a good idea).
What is a good solution for this?
I need a Linux / X11 solution, but it would be nice to be cross-platform - I know this can be easily resolved on Windows, so maybe there is a library that does just that. (also, I render using OpenGL, but that doesn't matter)
PS: Perhaps I have a poor understanding of this problem, and I am not asking the right question, so feel free to indicate approaches that I have not considered.