find_desktop_window() api changes. window parent s/b root, not desktop,
authorPhilip Kovacs <pkovacs@users.sourceforge.net>
Tue, 7 Mar 2006 19:46:51 +0000 (19:46 +0000)
committerPhilip Kovacs <pkovacs@users.sourceforge.net>
Tue, 7 Mar 2006 19:46:51 +0000 (19:46 +0000)
otherwise the window manager may not control the window.

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@558 7f574dfc-610e-0410-a909-a81674777703

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

index 343082e..bbaae22 100644 (file)
@@ -4573,9 +4573,9 @@ static void main_loop()
                        case ButtonPress:
                                if (own_window)
                                {
-                                   /* forward the click to the root window */
+                                   /* forward the click to the desktop window */
                                    XUngrabPointer(display, ev.xbutton.time);
-                                   ev.xbutton.window = window.root;
+                                   ev.xbutton.window = window.desktop;
                                    XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
                                }
                                break;
index fb949ee..ee817b7 100644 (file)
@@ -312,7 +312,7 @@ enum _window_hints {
 #define TEST_HINT(mask,hint)   (mask & (1<<hint))
 #endif
 struct conky_window {
-       Window root,window;
+       Window root,window,desktop;
        Drawable drawable;
        GC gc;
 #ifdef XDBE
index 341fc12..aae5035 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_desktop_window();
+static Window find_desktop_window(Window *p_root, Window *p_desktop);
 static Window find_subwindow(Window win, int w, int h);
 
 /* X11 initializer */
@@ -95,7 +95,9 @@ static void update_workarea()
        }
 }
 
-static Window find_desktop_window()
+/* Find root window and desktop window.  Return desktop window on success, 
+ * and set root and desktop byref return values.  Return 0 on failure. */  
+static Window find_desktop_window(Window *p_root, Window *p_desktop)
 {
        Atom type;
        int format, i;
@@ -106,6 +108,9 @@ static Window find_desktop_window()
        Window troot, parent, *children;
        unsigned char *buf = NULL;
 
+       if (!p_root || !p_desktop)
+           return(0);
+
        /* some window managers set __SWM_VROOT to some child of root window */
 
        XQueryTree(display, root, &troot, &parent, &children, &n);
@@ -120,6 +125,8 @@ static Window find_desktop_window()
                        fprintf(stderr,
                                "Conky: desktop window (%lx) found from __SWM_VROOT property\n", win);
                        fflush(stderr);
+                       *p_root=win;
+                       *p_desktop=win;
                        return win;
                }
 
@@ -144,11 +151,15 @@ static Window find_desktop_window()
 
        if (win != root)
                fprintf(stderr,
-                       "Conky: desktop window (%lx) is subwindow of root window (%lx)\n",win,root);
+                       "\nConky: desktop window (%lx) is subwindow of root window (%lx)\n",win,root);
        else
-               fprintf(stderr, "Conky: desktop window (%lx) is root window\n",win);
+               fprintf(stderr, "\nConky: desktop window (%lx) is root window\n",win);
 
        fflush(stderr);
+
+       *p_root=root;
+       *p_desktop=win;
+
        return win;
 }
 
@@ -204,7 +215,11 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
                        Atom xa;
                        char window_title[256];
 
-                       window.root = find_desktop_window();
+                       /* 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, 
@@ -373,7 +388,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
                XWindowAttributes attrs;
 
                if (!window.window)
-                       window.window = find_desktop_window();
+                       window.window = find_desktop_window( &window.root, &window.desktop );
 
                if (XGetWindowAttributes(display, window.window, &attrs)) {
                        window.width = attrs.width;