+static void
+stay_on_top(struct osd_state *osd)
+{
+ /* Heavily inspired by a similar function in libxosd */
+ Window root = DefaultRootWindow(osd->dpy);
+ int format;
+ unsigned long nitems, bytes_after;
+ unsigned char *prop = NULL;
+ Atom type;
+
+ // Gnome-compliant way
+ Atom gnome = XInternAtom(osd->dpy, "_WIN_SUPPORTING_WM_CHECK", False);
+ if (XGetWindowProperty(osd->dpy, root, gnome, 0, 16384, False, AnyPropertyType,
+ &type, &format, &nitems, &bytes_after, &prop) == Success &&
+ nitems > 0)
+ {
+ DBG("stay_on_top: Gnome mode\n");
+ // FIXME: check capabilities
+ XClientMessageEvent e;
+ memset(&e, 0, sizeof(e));
+ e.type = ClientMessage;
+ e.window = osd->win;
+ e.message_type = XInternAtom(osd->dpy, "_WIN_LAYER", False);
+ e.format = 32;
+ e.data.l[0] = 6; // WIN_LAYER_ONTOP */
+ XSendEvent(osd->dpy, root, False, SubstructureNotifyMask, (XEvent *) &e);
+ XFree(prop);
+ return;
+ }
+
+ // NetWM-compliant way
+ Atom net_wm = XInternAtom(osd->dpy, "_NET_SUPPORTED", False);
+ if (XGetWindowProperty(osd->dpy, root, net_wm, 0, 16384, False, AnyPropertyType,
+ &type, &format, &nitems, &bytes_after, &prop) == Success &&
+ nitems > 0)
+ {
+ DBG("stay_on_top: NetWM mode\n");
+ XEvent e;
+ memset(&e, 0, sizeof(e));
+ e.xclient.type = ClientMessage;
+ e.xclient.message_type = XInternAtom(osd->dpy, "_NET_WM_STATE", False);
+ e.xclient.display = osd->dpy;
+ e.xclient.window = osd->win;
+ e.xclient.format = 32;
+ e.xclient.data.l[0] = 1; // _NET_WM_STATE_ADD
+ e.xclient.data.l[1] = XInternAtom(osd->dpy, "_NET_WM_STATE_STAYS_ON_TOP", False);
+ XSendEvent(osd->dpy, root, False, SubstructureRedirectMask, &e);
+ XFree(prop);
+ return;
+ }
+
+ DBG("stay_on_top: WM does not support any known protocol\n");
+}
+