Experimental RSS code.
[monky] / src / x11.c
index 3763f3a..888f917 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
@@ -18,9 +18,7 @@
 #include <X11/Xft/Xft.h>
 #endif
 
-#include <stdio.h>
-
-#ifdef XDBE
+#ifdef HAVE_XDBE
 int use_xdbe;
 #endif
 
@@ -28,8 +26,6 @@ int use_xdbe;
 int use_xft = 0;
 #endif
 
-#define WINDOW_NAME_FMT "%s - conky" 
-
 /* some basic X11 stuff */
 Display *display;
 int display_width;
@@ -187,8 +183,8 @@ inline void set_transparent_background(Window win)
        //XClearWindow(display, win); not sure why this was here
 }
 
-void init_window(int own_window, int w, int h, int set_trans, int back_colour, char * nodename, 
-                char **argv, int argc)
+void init_window(int own_window, int w, int h, int set_trans, int back_colour, 
+                            char **argv, int argc)
 {
        /* There seems to be some problems with setting transparent background (on
         * fluxbox this time). It doesn't happen always and I don't know why it
@@ -196,53 +192,75 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
        set_transparent = set_trans;
        background_colour = back_colour;
 
-       nodename = (char *)nodename;
-
 #ifdef OWN_WINDOW
        if (own_window) {
-               {
-                       /* Allow WM control of conky again.  Shielding conky from the WM 
-                        * via override redirect creates more problems than it's worth and
-                        * makes it impossible to use tools like devilspie to manage the
-                        * conky windows beyond the parameters we offer.  ButtonPress 
-                        * events are now explicitly forwarded to the desktop window. */
+               
+               if ( !find_desktop_window( &window.root, &window.desktop ) )
+                       return;
+
+               if (window.type == TYPE_OVERRIDE) {
+       
+                       /* 
+                          An override_redirect True window.  No WM hints or button processing needed. 
+                       */
                        XSetWindowAttributes attrs = {
                                ParentRelative,0L,0,0L,0,0,Always,0L,0L,False,
-                               StructureNotifyMask|ExposureMask|ButtonPressMask,
-                               0L,False,0,0 };
+                               StructureNotifyMask|ExposureMask,
+                               0L,
+                               True,
+                               0,0 };
+
+                       /* Parent is desktop window (which might be a child of root) */
+                       window.window = XCreateWindow(display, 
+                                                  window.desktop, 
+                                                  window.x, window.y, w, h, 0, 
+                                                  CopyFromParent,
+                                                  InputOutput,
+                                                  CopyFromParent,
+                                                  CWBackPixel|CWOverrideRedirect,
+                                                  &attrs);
+
+                       XLowerWindow(display, window.window);   
+
+                       fprintf(stderr, "Conky: window type - override\n"); fflush(stderr);
+
+               }
+
+               else { /* window.type != TYPE_OVERRIDE */
+
+                       /* 
+                          A window managed by the window manager.  Process hints and buttons. 
+                       */
+                       XSetWindowAttributes attrs = {
+                               ParentRelative,0L,0,0L,0,0,Always,0L,0L,False,
+                               StructureNotifyMask|ExposureMask|ButtonPressMask|ButtonReleaseMask,
+                               0L,
+                               False,
+                               0,0 };
 
                        XClassHint classHint;
                        XWMHints wmHint;
                        Atom xa;
-                       char window_title[256];
-
-                       /* We want to parent the window to the root so it's under WM control,
-                        * but we want to forward button clicks to the desktop window for menus. 
-                        * On some desktop systems, the desktop window != root window. */
-                       if ( !find_desktop_window( &window.root, &window.desktop ) )
-                           return;
-
-                       window.window = XCreateWindow(display, window.root, 
-                                                     window.x, window.y, w, h, 0, 
-                                                     CopyFromParent,
-                                                     InputOutput,
-                                                     CopyFromParent,
-                                                     CWBackPixel|CWOverrideRedirect,
-                                                     &attrs);
-
-                       fprintf(stderr, "Conky: drawing to created window (%lx)\n", window.window);
-                       fflush(stderr);
 
-                       classHint.res_name = window.wm_class_name;
+                       /* Parent is root window so WM can take control */
+                       window.window = XCreateWindow(display, 
+                                                  window.root, 
+                                            window.x, window.y, w, h, 0, 
+                                                  CopyFromParent,
+                                                  InputOutput,
+                                                  CopyFromParent,
+                                                  CWBackPixel|CWOverrideRedirect,
+                                                  &attrs);
+
+                       classHint.res_name = window.class_name;
                        classHint.res_class = classHint.res_name;
 
                        wmHint.flags = InputHint | StateHint;
-                       wmHint.input = False;
+      /* allow decorated windows to be given input focus by WM */
+                       wmHint.input = TEST_HINT(window.hints,HINT_UNDECORATED) ? False : True;
                        wmHint.initial_state = NormalState;
 
-                       sprintf(window_title,WINDOW_NAME_FMT,nodename);
-
-                       XmbSetWMProperties (display, window.window, window_title, NULL, 
+                       XmbSetWMProperties (display, window.window, window.title, NULL, 
                                            argv, argc,
                                            NULL, &wmHint, &classHint);
 
@@ -250,22 +268,36 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
                        XSetWMProtocols(display,window.window,NULL,0);
 
 
-                       /* Set NORMAL window type for _NET_WM_WINDOW_TYPE. */
-                       xa = ATOM(_NET_WM_WINDOW_TYPE);
-                       if (xa != None) {
-                               Atom prop = ATOM(_NET_WM_WINDOW_TYPE_NORMAL);
+                       /* Set window type */
+                       if ( (xa = ATOM(_NET_WM_WINDOW_TYPE)) != None ) 
+                       {
+                               Atom prop;
+                               switch(window.type) {
+                               case TYPE_DESKTOP:
+                                       {
+                                       prop = ATOM(_NET_WM_WINDOW_TYPE_DESKTOP);
+                                       fprintf(stderr, "Conky: window type - desktop\n"); fflush(stderr);
+                                       }
+                                       break;                          
+                               case TYPE_NORMAL:
+                               default:
+                                       {
+                                       prop = ATOM(_NET_WM_WINDOW_TYPE_NORMAL);
+                                       fprintf(stderr, "Conky: window type - normal\n"); fflush(stderr);
+                                       }
+                                       break;
+                               }
                                XChangeProperty(display, window.window, xa,
                                                XA_ATOM, 32,
                                                PropModeReplace,
-                                               (unsigned char *) &prop,
-                                               1);
+                                               (unsigned char *) &prop, 1);
                        }
 
                        /* Set desired hints */
                        
                        /* Window decorations */
                        if (TEST_HINT(window.hints,HINT_UNDECORATED)) {
-                           fprintf(stderr, "Conky: hint - undecorated\n"); fflush(stderr);
+                           /*fprintf(stderr, "Conky: hint - undecorated\n"); fflush(stderr);*/
 
                            xa = ATOM(_MOTIF_WM_HINTS);
                            if (xa != None) {
@@ -278,7 +310,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
 
                        /* Below other windows */
                        if (TEST_HINT(window.hints,HINT_BELOW)) {
-                           fprintf(stderr, "Conky: hint - below\n"); fflush(stderr);
+                           /*fprintf(stderr, "Conky: hint - below\n"); fflush(stderr); */
 
                            xa = ATOM(_WIN_LAYER);
                            if (xa != None) {
@@ -302,7 +334,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
 
                        /* Above other windows */
                        if (TEST_HINT(window.hints,HINT_ABOVE)) {
-                            fprintf(stderr, "Conky: hint - above\n"); fflush(stderr);
+                            /*fprintf(stderr, "Conky: hint - above\n"); fflush(stderr);*/
 
                             xa = ATOM(_WIN_LAYER);
                             if (xa != None) {
@@ -326,7 +358,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
 
                        /* Sticky */
                        if (TEST_HINT(window.hints,HINT_STICKY)) {
-                            fprintf(stderr, "Conky: hint - sticky\n"); fflush(stderr);
+                            /*fprintf(stderr, "Conky: hint - sticky\n"); fflush(stderr); */
 
                             xa = ATOM(_NET_WM_DESKTOP);
                             if (xa != None) {
@@ -351,7 +383,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
 
                        /* Skip taskbar */
                         if (TEST_HINT(window.hints,HINT_SKIP_TASKBAR)) {
-                            fprintf(stderr, "Conky: hint - skip_taskbar\n"); fflush(stderr);
+                            /*fprintf(stderr, "Conky: hint - skip_taskbar\n"); fflush(stderr);*/
 
                             xa = ATOM(_NET_WM_STATE);
                             if (xa != None) {
@@ -366,7 +398,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
 
                        /* Skip pager */
                         if (TEST_HINT(window.hints,HINT_SKIP_PAGER)) {
-                            fprintf(stderr, "Conky: hint - skip_pager\n"); fflush(stderr);
+                            /*fprintf(stderr, "Conky: hint - skip_pager\n"); fflush(stderr);*/
 
                             xa = ATOM(_NET_WM_STATE);
                             if (xa != None) {
@@ -379,10 +411,14 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
                             }
                         }
 
-                       XMapWindow(display, window.window);
+               } /* else { window.type != TYPE_OVERRIDE */
+                       
+               fprintf(stderr, "Conky: drawing to created window (%lx)\n", window.window);
+               fflush(stderr);
 
-               }
-       } else
+               XMapWindow(display, window.window);
+
+       } else /* if (own_window) { */
 #endif
                /* root / desktop window */
        {
@@ -402,7 +438,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
        /* Drawable is same as window. This may be changed by double buffering. */
        window.drawable = window.window;
 
-#ifdef XDBE
+#ifdef HAVE_XDBE
        if (use_xdbe) {
                int major, minor;
                if (!XdbeQueryExtension(display, &major, &minor)) {
@@ -439,7 +475,8 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
        XSelectInput(display, window.window, ExposureMask
 #ifdef OWN_WINDOW
                     | (own_window
-                       ? (StructureNotifyMask | PropertyChangeMask | ButtonPressMask) : 0)
+                       ? (StructureNotifyMask | PropertyChangeMask | 
+                          ButtonPressMask | ButtonReleaseMask) : 0)
 #endif
            );
 }