]> mj.ucw.cz Git - osdd.git/commitdiff
Experiments: stay_on_top
authorMartin Mares <mj@ucw.cz>
Wed, 9 Oct 2013 21:54:15 +0000 (23:54 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 9 Oct 2013 21:54:15 +0000 (23:54 +0200)
test.c

diff --git a/test.c b/test.c
index 15fcd9fd939d18efcc17cca1e251389a1b2209ce..5d48d8d0f726f74148ec73eec028676369baefa0 100644 (file)
--- a/test.c
+++ b/test.c
@@ -33,6 +33,60 @@ struct osd_state {
   XftDraw *image_draw;
 };
 
+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");
+}
+
 int
 main(int argc, char **argv)
 {
@@ -73,6 +127,7 @@ main(int argc, char **argv)
        CWOverrideRedirect,
        &win_attr);
   XStoreName(osd->dpy, osd->win, "OSD");
+  stay_on_top(osd);
 
   // FIXME: Size
   osd->mask_bitmap = XCreatePixmap(osd->dpy, osd->win, osd->screen_width, osd->screen_height, 1);
@@ -93,8 +148,6 @@ main(int argc, char **argv)
   XSetBackground(osd->dpy, osd->mask_gc, WhitePixel(osd->dpy, osd->screen));
   XSetForeground(osd->dpy, osd->mask_gc, BlackPixel(osd->dpy, osd->screen));
 
-  // FIXME: Stay on top
-
   XFillRectangle(osd->dpy, osd->image_pixmap, osd->gc, 0, 0, osd->screen_width, osd->screen_height);
 
   XFillRectangle(osd->dpy, osd->mask_bitmap, osd->mask_gc, 0, 0, osd->screen_width, osd->screen_height);