X11/GLX - Fullscreen mode?

DigitalMan picture DigitalMan · Jan 30, 2012 · Viewed 10.1k times · Source

I am trying to create a Linux application - a screensaver, in this case - and it is proving remarkably difficult to find information on the simple task of making a window full-screen. Even the code of existing screensavers makes no mention of how they manage it, and I've yet to see any obvious function like XRemoveDecoration().

After much fumbling around, I did manage to create a window that's the same size as the desktop, with this:

Window win = DefaultRootWindow(disp);
XWindowAttributes getWinAttr;
XGetWindowAttributes(disp, win, &getWinAttr);
win = XCreateWindow(disp, win, 0, 0, getWinAttr.width, getWinAttr.height, 0, vInfo->depth, InputOutput, vInfo->visual, CWBorderPixel|CWColormap|CWEventMask|CWOverrideRedirect, &winAttr );

But that doesn't do anything to get rid of the titlebar and borders. I know there's a way, obviously - but I have yet to find anything even pointing in that direction that doesn't rely on some other massive library being thrown on top (which existing screensavers are definitely not using).

EDIT: Please don't remove information from my posts. There is a very good reason I explicitly pointed out that existing screensavers aren't using optional libraries, and that is because I have been analyzing source code for most of the past day.

I have chosen the answer that most directly answers the question, and applies to applications in general.

If you have found this question researching xscreensavers... the same still applies. Yes, xscreensaver has its own API - which is complicated, and actually involves writing more lines of code (yes, seriously). If you want OpenGL in your screensaver, you'll need to go through another API (xlockmore, a competing system) and a compatibility layer that translates it to xscreensaver.

However, xscreensaver is capable of running any program that can use virtual root windows (look into vroot.h) as a screensaver. So my advice is to just do that - you'll have more control, no limiting API, and greater portability. (One example I looked at can even compile for Linux or Windows, with the same file!)

Answer

eile picture eile · Jan 30, 2012

One way is to bypass the window manager:

XSetWindowAttributes wa;                                                     
wa.override_redirect = True;                                           
XCreateWindow( ..., &wa );