I am trying to create a simple panel for Openbox in Arch Linux using c++, but I cannot figure out how to remove the title bar from a window.
I am creating the window with XCreateWindow(...)
, and that gives a window with the correct size, but it contains a title bar, and the window also opens in the top-left corner of the screen, no matter what offset coordinates I specify.
I read here that both of these problems are probably caused by the window manager (Openbox), which overrides the window attributes I specified in XCreateWindow(..., &window_attributes)
. This could be solved by adding window_attributes.override_redirect = True;
, although this does not seem to do anything for me. When I try this I get the exact same window as before. (I did compile the file after this change.)
Also I read into the code of Tint2 (link), which is another panel for Openbox. They create a window using the following code:
XSetWindowAttributes att = { .colormap=server.colormap, .background_pixel=0, .border_pixel=0 }; p->main_win = XCreateWindow(server.dsp, server.root_win, p->posx, p->posy, p->area.width, p->area.height, 0, server.depth, InputOutput, server.visual, mask, &att);
I don't see an override_redirect
anywhere in their code, so I'm not sure how they are removing the title bar.
As additional information, I thought it would be worth mentioning how I'm executing the script:
/* The c++ file is saved as 'panel.cpp' */ $ gcc panel.cpp -lX11 -o panel $ ./panel
Also, I am running Arch Linux through VirtualBox with Windows 8 as host. I'm not sure if this changes anything, but it won't hurt to mention.
Since I found the solution, I figured I'd post the solution here if anyone else needs it.
As @JoachimPileborg mentioned, I needed to alter the Openbox settings in ~/.config/openbox/rc.xml
. Inside the <applications>
tag, I added the following code:
<application class="*"> <decor>no</decor> <position force="no"></position> </application>
The class="*"
means that all applications will follow these rules, you could fill in the class name of the application instead. The <decor>no</decor>
removes the title bar, and <position force="no"></position>
ensures that my own script is able to handle the positioning. You could also add another <application>
tag after this one to make exceptions to this rule.
Also, the window_attributes.override_redirect = True;
is not needed anymore.
A more correct way is to use the Extended Window Manager Hints.
The idea is that you don't tell the window manager how to decorate or not your window, you just indicate the window type with _NET_WM_WINDOW_TYPE
:
Atom window_type = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(display, "_NET_WM_WINDOW_TYPE_DOCK", False); XChangeProperty(display, your_window, window_type, XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
"Dock" is the type for panels and taskbar. Usually they are undecorated and appear on all desktops. As written on the documentation, previously the _MOTIF_WM_HINTS
property was used to define the appearance and decorations of the window. Window managers still support it, but _NET_WM_WINDOW_TYPE
is prefered as it describe the function and let the window manager (and user) decide on the appearance and behavior of that type of window.
Another interesting property for a panel is _NET_WM_STRUT_PARTIAL, to "reserve" space.