This C function can be used to disable or enable windows decorations in many window managers. If ‘mode’ is ‘d’ the window will hide the decorations, otherwise if the ‘mode’ is ‘D’ the window will show them.
void window_tune_decorations(Display *disp, Window win, char mode) {
long hints[5] = { 2, 0, 0, 0, 0};
Atom motif_hints = XInternAtom(disp, "_MOTIF_WM_HINTS", False);
switch (mode) {
case 'D':
hints[2] = 1;
/* fall through */
case 'd':
XChangeProperty(disp, win, motif_hints, motif_hints, 32, PropModeReplace, (unsigned char *)hints, 5);
break;
default:
fputs("Invalid mode.\n", stderr);
}
}
I would like to implement a “toggle mode”. So my question is, there a way to detect if a windows has the decorations?
I tried using XGetWindowProperty with _MOTIF_WM_HINTS, but I am not sure how to interpret the output.
You interpret the data you get from
XGetWindowPropertythe same way you interpret data sent toXChangeProperty.In the case of
_MOTIF_WM_HINTSit’s an array of 5longs, or perhaps thestruct MwmHints(syn.MotifWmHints). It’s a struct of 5longfields, plus several#defined bit flags. It is inherited from the Motif window manager, but we don’t usually keep Motif includes and libraries around nowadays, so the struct gets copied to various places (bad practice but everyonee is doing it). You may find its definition inxprops.hof Gnome and several other places. Look it up on the ‘net and copy to your code, or find it in an include file you already depend on, or just look at the definition and keep using the array of 5longs, your choice.You need to check the right flags in the right fields. For decorations, check if the window is override-redirect first. If it is, it is undecorated (obviously) and you cannot add any decorations. If the window manager is not running, it’s undecorated as well, and you cannot add any decorations in this case too.
Otherwise, if the window does not have the property at all (
XGetWindowPropertysetstypetoNone), you may assume it’s decorated.If it does have the property, and
MWM_HINTS_DECORATIONSbit is set inflags, then it has exactly the decorations specified in thedecorationsfield by theMWM_DECOR_*bit values. If the field is non-zero, there are some decorations present. AFAIK ifMWM_HINTS_DECORATIONSis unset, then the window is (surprisingly) decorated. But please test this yourself, I don’t remember and don’t have an X11 machine around at the moment so I can’t check it.Naturally, some window managers don’t use
_MOTIF_WM_HINTS(e.g. ones that were around before Motif). If you have one of those, you cannot check or set decorations with this method.Don’t forget to
XFree(hints).