drastic simplifications for own_window=yes
authorPhilip Kovacs <pkovacs@users.sourceforge.net>
Tue, 14 Feb 2006 06:15:38 +0000 (06:15 +0000)
committerPhilip Kovacs <pkovacs@users.sourceforge.net>
Tue, 14 Feb 2006 06:15:38 +0000 (06:15 +0000)
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@532 7f574dfc-610e-0410-a909-a81674777703

ChangeLog
src/conky.c
src/conky.h
src/x11.c

index b1c21ce..e2854ec 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 # $Id$
 
+2006-02-14
+       * Drastically simplified own_window=yes window creation code.
+
 2006-02-13
        * Fixed typo bug in portmon code that caused incorrect monitor data 
        to be displayed.
index 7e2d704..31e3759 100644 (file)
@@ -4691,8 +4691,12 @@ void clean_up(void)
        }
 #endif
 #ifdef OWN_WINDOW
-       if (own_window)
+       if (own_window) 
+       {
                XDestroyWindow(display, window.window);
+               XClearWindow(display, RootWindow(display, screen));
+               XFlush(display);
+       }
        else
 #endif
        {
index c674bab..ab09e2c 100644 (file)
@@ -300,7 +300,7 @@ char tmpstring2[TEXT_BUFFER_SIZE];
 #define ATOM(a) XInternAtom(display, #a, False)
 
 struct conky_window {
-       Window window;
+       Window root,window;
        Drawable drawable;
        GC gc;
 #ifdef XDBE
index 4e17d41..bf29d45 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
@@ -45,7 +45,7 @@ struct conky_window window;
 
 /* local prototypes */
 static void update_workarea();
-static Window find_window_to_draw();
+static Window find_desktop_window();
 static Window find_subwindow(Window win, int w, int h);
 
 /* X11 initializer */
@@ -95,7 +95,7 @@ static void update_workarea()
        }
 }
 
-static Window find_window_to_draw()
+static Window find_desktop_window()
 {
        Atom type;
        int format, i;
@@ -118,7 +118,7 @@ static Window find_window_to_draw()
                        XFree(buf);
                        XFree(children);
                        fprintf(stderr,
-                               "Conky: drawing to window from __SWM_VROOT property\n");
+                               "Conky: desktop window (%lx) found from __SWM_VROOT property\n", win);
                        return win;
                }
 
@@ -143,10 +143,9 @@ static Window find_window_to_draw()
 
        if (win != root)
                fprintf(stderr,
-                       "Conky: drawing to subwindow of root window (%lx)\n",
-                       win);
+                       "Conky: desktop window (%lx) is subwindow of root window (%lx)\n",win,root);
        else
-               fprintf(stderr, "Conky: drawing to root window\n");
+               fprintf(stderr, "Conky: desktop window (%lx) is root window\n",win);
 
        return win;
 }
@@ -185,141 +184,41 @@ void init_window(int own_window, int w, int h, int l, int set_trans, int back_co
         * happens but I bet the bug is somewhere here. */
        set_transparent = set_trans;
        background_colour = back_colour;
-       char * window_name = NULL;
-#ifdef OWN_WINDOW
-       if (own_window) {
-
-               /* looks like root pixmap isn't needed for anything */
-               {
-                       XSetWindowAttributes attrs;
-                       XClassHint class_hints;
-
-                       /* just test color
-                       attrs.background_pixel = get_x11_color("green");
-                       */
-
-                       window.window = XCreateWindow(display, RootWindow(display, screen), window.x, window.y, w, h, 0, CopyFromParent,        /* depth */
-                                                     CopyFromParent,   /* class */
-                                                     CopyFromParent,   /* visual */
-                                                     CWBackPixel, &attrs);
-/*                     XWMHints wmhints;
-
-                       this doesn't work properly
 
-                       wmhints.flags = StateHint;
-                       wmhints.initial_state = WithdrawnState;
-                       XSetWMHints(display, window.window, &wmhints);*/
-
-
-
-                       class_hints.res_class = wm_class_name;
-                       class_hints.res_name = wm_class_name;
-                       XSetClassHint(display, window.window,
-                                     &class_hints);
-
-                       /*set_transparent_background(window.window);*/
-                       window_name = (char *) malloc(strlen(WINDOW_NAME_FMT) + strlen(nodename)+1);
-                       sprintf(window_name, WINDOW_NAME_FMT, nodename);
-                       XStoreName(display, window.window, window_name);
-                       free(window_name);
-                       XClearWindow(display, window.window);
-
-                       if (!fixed_pos)
-                               XMoveWindow(display, window.window, window.x,
-                       window.y);
-               }
+       wm_class_name = (char *)wm_class_name;
+       l = (int)l;
+       fixed_pos = (int)fixed_pos;
+       nodename = (char *)nodename;
 
+#ifdef OWN_WINDOW
+       if (own_window) {
                {
-                       /* turn off decorations */
-                       Atom a =
-                           XInternAtom(display, "_MOTIF_WM_HINTS", True);
-                       if (a != None) {
-                               long prop[5] = { 2, 0, 0, 0, 0 };
-                               XChangeProperty(display, window.window, a,
-                                               a, 32, PropModeReplace,
-                                               (unsigned char *) prop, 5);
-                       }
+                       /* DRASTICALLY SIMPLIFIED - 
+                        * override_redirect=True impedes the WM from manipulating
+                        * the window, adding decorations, etc.  we do not register
+                        * for button events so you should have menu clicking over
+                        * the conky window now too.  PHK. */
+                       XSetWindowAttributes attrs = {
+                               ParentRelative,0L,0,0L,0,0,Always,0L,0L,False,
+                               StructureNotifyMask|ExposureMask,
+                               0L,True,0,0 };
 
-                       /* set window sticky (to all desktops) */
-                       a = XInternAtom(display, "_NET_WM_DESKTOP", True);
-                       if (a != None) {
-                               long prop = 0xFFFFFFFF;
-                               XChangeProperty(display, window.window, a,
-                                               XA_CARDINAL, 32,
-                                               PropModeReplace,
-                                               (unsigned char *) &prop,
-                                               1);
-                       }
+                       window.root = find_desktop_window();
 
-                       /* PHK: Use EWMH window type NORMAL for _NET_WM_WINDOW_TYPE. 
-                           For XFCE 4+, keeps the window from going under the desktop. */
-                       a = XInternAtom(display, "_NET_WM_WINDOW_TYPE", True);
-                       if (a != None) {
-                               Atom prop = XInternAtom(display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
-                               XChangeProperty(display, window.window, a,
-                                               XA_ATOM, 32,
-                                               PropModeReplace,
-                                               (unsigned char *) &prop,
-                                               1);
-                       }
+                       window.window = XCreateWindow(display, window.root, 
+                                                     window.x, window.y, w, h, 0, 
+                                                     CopyFromParent,
+                                                     InputOutput,
+                                                     CopyFromParent,
+                                                     CWBackPixel|CWOverrideRedirect, &attrs);
 
-                       /* PHK: Add EWMH hint STICKY to _NET_WM_STATE */
-                       a = XInternAtom(display, "_NET_WM_STATE", True);
-                       if (a != None) {
-                               Atom prop = XInternAtom(display, "_NET_WM_STATE_STICKY", True);
-                               XChangeProperty(display, window.window, a,
-                                               XA_ATOM, 32,
-                                               PropModeAppend,
-                                               (unsigned char *) &prop,
-                                               1);
-                       }
+                       fprintf(stderr, "Conky: drawing to created window (%lx)\n", window.window);
 
-                       /* PHK: Add EWMH hint SKIP_TASKBAR to _NET_WM_STATE */
-                       a = XInternAtom(display, "_NET_WM_STATE", True);
-                       if (a != None) {
-                               Atom prop = XInternAtom(display, "_NET_WM_STATE_SKIP_TASKBAR", True);
-                               XChangeProperty(display, window.window, a,
-                                               XA_ATOM, 32,
-                                               PropModeAppend,
-                                               (unsigned char *) &prop,
-                                               1);
-                       }
+                       XLowerWindow(display, window.window);
 
-                       /* PHK: Add EWMH hint SKIP_PAGER to _NET_WM_STATE */
-                       a = XInternAtom(display, "_NET_WM_STATE", True);
-                       if (a != None) {
-                               Atom prop = XInternAtom(display, "_NET_WM_STATE_SKIP_PAGER", True);
-                               XChangeProperty(display, window.window, a,
-                                               XA_ATOM, 32,
-                                               PropModeAppend,
-                                               (unsigned char *) &prop,
-                                               1);
-                       }
+                       XMapWindow(display, window.window);
 
-                       if(l) {
-                               /* make sure the layer is on the bottom */
-                               a = XInternAtom(display, "_WIN_LAYER", True);
-                               if (a != None) {
-                                       long prop = 0;
-                                       XChangeProperty(display, window.window, a,
-                                                       XA_CARDINAL, 32,
-                                                       PropModeReplace,
-                                                       (unsigned char *) &prop, 1);
-                               }
-                               /* PHK: also append EWMH hint for BELOW also */
-                               a = XInternAtom(display, "_NET_WM_STATE", True);
-                               if (a != None) {
-                                       Atom prop = XInternAtom(display, "_NET_WM_STATE_BELOW", True);
-                                       XChangeProperty(display, window.window, a,
-                                               XA_ATOM, 32,
-                                               PropModeAppend,
-                                               (unsigned char *) &prop,
-                                               1);
-                               }
-                       }
                }
-
-               XMapWindow(display, window.window);
        } else
 #endif
                /* root / desktop window */
@@ -327,12 +226,14 @@ void init_window(int own_window, int w, int h, int l, int set_trans, int back_co
                XWindowAttributes attrs;
 
                if (!window.window)
-                       window.window = find_window_to_draw();
+                       window.window = find_desktop_window();
 
                if (XGetWindowAttributes(display, window.window, &attrs)) {
                        window.width = attrs.width;
                        window.height = attrs.height;
                }
+
+               fprintf(stderr, "Conky: drawing to desktop window\n");
        }
 
        /* Drawable is same as window. This may be changed by double buffering. */