Search code examples
cwindowx11xlib

Why window without borders is always on top


I'm trying to create window without borders (popup?) in xlib. I'm using this code:

#include <stdio.h>
#include <X11/Xlib.h>

int main( int argc, char **argv )
{
    Display *display = NULL;
    Window window;
    XSetWindowAttributes attribs;

    display = XOpenDisplay( NULL );
    if( !display )
    {
        printf( "Cannot to open display." );
        return 1;
    }

    attribs.override_redirect = 1;

    window = XCreateWindow( display, RootWindow(display, 0), 20, 20, 400, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWOverrideRedirect, &attribs );
    XSetWindowBackground( display, window, 0x00F0FF );
    XClearWindow( display, window );

    XMapWindow( display, window );
    XFlush( display );

    getchar( );
    return 0;
}

It creating window without borders, but this window is always on top. The question is: Why and what to do in xlib to display it as a normal window.


Solution

  • That's how override-redirect windows are meant to behave. They are designed for implementing pop-up menus and similar windows which are transient and stay above other windows.

    If that's not what you want, do not use override-redirect flag. Instead, use WM hints. See here for the full list of hints. You want to tell your WM which window type you have (_NET_WM_WINDOW_TYPE_TOOLBAR etc), not how it's decorated. See here for a usage example.

    If that's still not what you want, use the (somewhat outdated) Motif WM hints. See for example here.