I want to create a non-resizable window for my little game engine. I found out that override_redirect attribute set to true is exactly what I need. So I wrote my sample program:
#include <X11/Xlib.h>
#include <unistd.h>
Display *display;
Window window;
Visual *visual;
XSetWindowAttributes attributes;
int depth;
int screen;
int main(){
display = XOpenDisplay(NULL);
screen = DefaultScreen(display);
visual = DefaultVisual(display,screen);
depth = DefaultDepth(display,screen);
attributes.background_pixel = XWhitePixel(display,screen);
attributes.override_redirect = True;
window = XCreateWindow( display,XRootWindow(display,screen),
200, 200, 350, 200, 5, depth, InputOutput,
visual ,CWBackPixel, &attributes);
XSelectInput(display,window,ExposureMask | KeyPressMask) ;
XMapWindow(display, window);
XFlush(display);
sleep(10);
return 0;
}
However, my window is resizable and there is a title bar on the top of it. How can I get rid of those and why doesn't this code work as intended?
How can I get rid of those and why doesn't this code work as intended?
You forgot to set the CWOverrideRedirect
bit in the bitmask:
CWBackPixel
means that the background_pixel
element in the attributes
structure is considered.
You must use CWBackPixel|CWOverrideRedirect
if both the elements background_pixel
and override_redirect
shall be considered:
attributes.background_pixel = XWhitePixel(display,screen);
attributes.override_redirect = True;
window = XCreateWindow( display,XRootWindow(display,screen),
200, 200, 350, 200, 5, depth, InputOutput,
visual, CWBackPixel|CWOverrideRedirect, &attributes);