2

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.

Community
  • 1
  • 1
JeroenD
  • 343
  • 1
  • 6
  • 16
  • It's not really something you can do in your application, window title bars are added as a decoration by the window manager. Without knowing Openbox that well, you should look into if you can configure it to not show title bar for your window (i.e. by recognizing your `WM_CLASS` and not decorate windows of that class). – Some programmer dude Jun 23 '15 at 12:41
  • Thanks @JoachimPileborg, I came accross a solution to remove the title bar from all windows in Openbox ([link](https://bbs.archlinux.org/viewtopic.php?pid=975964#p975964)), although this does not solve the positioning yet. Maybe there is a way to tell Openbox to let my code handle the decoration / positioning? – JeroenD Jun 23 '15 at 13:10
  • The key word is "_MOTIF_WM_HINTS" atom, see [this question](https://stackoverflow.com/questions/5134297/xlib-how-does-this-removing-window-decoration-work). – popkc Nov 16 '17 at 22:36

2 Answers2

0

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.

JeroenD
  • 343
  • 1
  • 6
  • 16
0

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.

Leiaz
  • 2,867
  • 2
  • 20
  • 23
  • 1
    While this removes the decoration, it also removes the ability for the window to appear on the panel/taskbar. Do you know how to have both? – bparker Feb 11 '18 at 03:23