Keyboard focus loss in X11

Hello there!

I imagine this is a fairly common problem, but I haven’t been able to find
anything to help me in the archives of this mailing list. I’m somewhat of a
newbie to Xlib, GLX, and SDL, so bear with me here. :slight_smile:

My application is a 3D engine which I am porting from Win32 to linux. I made
two versions: one where I used Xlib, GLX, DGA, etc., myself, and one in which I
simply use SDL to handle everything for me (OpenAL is used for sound in both
cases, though). You should know that the version of SDL I am working with is
1.1.8–I’m afraid I haven’t had a chance to check out 1.2.0 yet.

My application calls SDL_SetVideoMode() to achieve fullscreen under OpenGL. I
also grab the input, though this is somewhat redundant I believe in fullscreen.
When a new window from another application (specifically gaim or kit, my AIM
clones) gains keyboard focus, SDL automatically drops out of fullscreen, and
lets the new window raise itself over the engine window. Although the new
window technically has keyboard focus, I cannot give it any input (possibly
because the SDL X11 Grab of the keyboard is still in effect?). Mouse is also
unresponsive. I end up having to switch to a VC to kill the 3D engine
process, but that means SDL didn’t properly release the DGA mouse, so my mouse
is still unresponsive, requiring me to navigate to a shell in X11 via keyboard
and start up another program that uses DGA to get my mouse back. (Note: Tux
Racer (www.tuxracer.com) behaves in the same exact manner.) This isn’t
exactly something that I would normally bitch about, but it is a problem if I
ever hope to release the application to the public. :slight_smile: I can get around this
slightly by simply releasing my input grab upon receipt of a SDL_APPINPUTFOCUS
loss event, but I’d much rather have SDL just not even budge in the first
place when it gets a FocusOut: that is, don’t let keyboard focus change, don’t
let the foreign window raise itself over ours, and don’t toggle fullscreen.
This is exactly how my native linux/X11, non-SDL port of the engine works.

I’ve been experimenting with various Xlib hacks within my app’s SDL code to no
avail. Does anyone know a way of getting SDL to stay on top of the screen,
come hell or high water? I hope it’s not just something that I missed in the
docs…

Possibly pertinent information:
Window Manager: WindowMaker
XFree86 4.0.2
SDL 1.1.8

Thank you very much in advance…
Harris

Hello there!

Hi ya…

My application calls SDL_SetVideoMode() to achieve fullscreen under OpenGL.

I would wager your problem relates to the fact that your X11 window is losing
focus.

While I personally haven’t used SDL to do OpenGL graphics yet, I do know that a
general problem with OpenGL under X11 is that the X11 window that the OpenGL
app opens up can loose focus if the mouse moves outside of it (if your window
manager is set up for “sloppy focus”) or if another window gains focus.

See, even tho your app is “full-screen”, the rest of the desktop and windows
are still there.

Make certain that when you call SDL_SetVideoMode(…) one of the flags you are
using is SDL_FULLSCREEN . Like I said, I haven’t done any OpenGL in SDL yet,
(just some OpenGL externally), so I am just guessing you will be sure to need
that to grab mouse focus.

I hope someone else on this list can back me up on this… or correct me if I
am wrong ;-)On Fri, 30 Mar 2001, you wrote:


Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: < http://www.geekcomix.com/snh/ >
PGP Info: < http://www.geekcomix.com/snh/contact/ >
Advogato: < http://advogato.org/person/criswell/ >

I’ve been experimenting with various Xlib hacks within my app’s SDL code to no
avail. Does anyone know a way of getting SDL to stay on top of the screen,
come hell or high water? I hope it’s not just something that I missed in the
docs…

hmm, it’s been awhile since i dealt with Xlib. i’m quite sure there
is a way to grab the entire Xwindows environment so no other app
can do anything (ie, drawing, raising focus, or anything). i assume
this is pretty frowned apon, but hey, if you’ve got fullscreen, i
guess things are a little different than for normal apps.

in SDL it is possible to get a system dependent window ID for the
SDL window. (so under X you get the Xwindow ID handle). i suppose
it is easy enough to get a copy of the window ID and grab the entire
display for yourself?

(whew, it has been awhile, sorry if this doesn’t assist)