Update copyright stuff, fix conky.conf weirdness.
[monky] / src / x11.c
index 64bf6a8..d9b93c5 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
@@ -7,7 +7,7 @@
  * Please see COPYING for details
  *
  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
  *     (see AUTHORS)
  * All rights reserved.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- * $Id$ */
+ */
 
+#include "config.h"
 #include "conky.h"
+#include "logging.h"
+#include "common.h"
 
-#ifdef X11
+#include "x11.h"
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 #include <X11/Xmd.h>
 #include <X11/Xutil.h>
+
 #ifdef XFT
 #include <X11/Xft/Xft.h>
+int use_xft = 0;
 #endif
 
 #ifdef HAVE_XDBE
 int use_xdbe;
 #endif
 
-#ifdef XFT
-int use_xft = 0;
-#endif
-
 /* some basic X11 stuff */
 Display *display;
 int display_width;
@@ -59,12 +60,12 @@ int workarea[4];
 struct conky_window window;
 
 /* local prototypes */
-static void update_workarea();
+static void update_workarea(void);
 static Window find_desktop_window(Window *p_root, Window *p_desktop);
 static Window find_subwindow(Window win, int w, int h);
 
 /* X11 initializer */
-void init_X11()
+void init_X11(void)
 {
        if ((display = XOpenDisplay(0)) == NULL) {
                CRIT_ERR("can't open display: %s", XDisplayName(0));
@@ -77,7 +78,7 @@ void init_X11()
        update_workarea();
 }
 
-static void update_workarea()
+static void update_workarea(void)
 {
        Window root = RootWindow(display, screen);
        unsigned long nitems, bytes;
@@ -139,7 +140,7 @@ static Window find_desktop_window(Window *p_root, Window *p_desktop)
                        XFree(buf);
                        XFree(children);
                        fprintf(stderr,
-                               "Conky: desktop window (%lx) found from __SWM_VROOT property\n",
+                               PACKAGE_NAME": desktop window (%lx) found from __SWM_VROOT property\n",
                                win);
                        fflush(stderr);
                        *p_root = win;
@@ -168,10 +169,10 @@ static Window find_desktop_window(Window *p_root, Window *p_desktop)
 
        if (win != root) {
                fprintf(stderr,
-                       "Conky: desktop window (%lx) is subwindow of root window (%lx)\n",
+                       PACKAGE_NAME": 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, PACKAGE_NAME": desktop window (%lx) is root window\n", win);
        }
 
        fflush(stderr);
@@ -183,7 +184,7 @@ static Window find_desktop_window(Window *p_root, Window *p_desktop)
 }
 
 /* sets background to ParentRelative for the Window and all parents */
-inline void set_transparent_background(Window win)
+void set_transparent_background(Window win)
 {
        static int colour_set = -1;
 
@@ -238,7 +239,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
 
                        XLowerWindow(display, window.window);
 
-                       fprintf(stderr, "Conky: window type - override\n");
+                       fprintf(stderr, PACKAGE_NAME": window type - override\n");
                        fflush(stderr);
                } else { /* window.type != TYPE_OVERRIDE */
 
@@ -252,6 +253,9 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
                        XWMHints wmHint;
                        Atom xa;
 
+                       if (window.type == TYPE_DOCK) {
+                               window.x = window.y = 0;
+                       }
                        /* 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,
@@ -264,7 +268,8 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
                        /* allow decorated windows to be given input focus by WM */
                        wmHint.input =
                                TEST_HINT(window.hints, HINT_UNDECORATED) ? False : True;
-                       wmHint.initial_state = NormalState;
+                       wmHint.initial_state = ((window.type == TYPE_DOCK) ?
+                                               WithdrawnState : NormalState);
 
                        XmbSetWMProperties(display, window.window, window.title, NULL, argv,
                                argc, NULL, &wmHint, &classHint);
@@ -279,13 +284,18 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
                                switch (window.type) {
                                        case TYPE_DESKTOP:
                                                prop = ATOM(_NET_WM_WINDOW_TYPE_DESKTOP);
-                                               fprintf(stderr, "Conky: window type - desktop\n");
+                                               fprintf(stderr, PACKAGE_NAME": window type - desktop\n");
+                                               fflush(stderr);
+                                               break;
+                                       case TYPE_DOCK:
+                                               prop = ATOM(_NET_WM_WINDOW_TYPE_DOCK);
+                                               fprintf(stderr, PACKAGE_NAME": window type - dock\n");
                                                fflush(stderr);
                                                break;
                                        case TYPE_NORMAL:
                                        default:
                                                prop = ATOM(_NET_WM_WINDOW_TYPE_NORMAL);
-                                               fprintf(stderr, "Conky: window type - normal\n");
+                                               fprintf(stderr, PACKAGE_NAME": window type - normal\n");
                                                fflush(stderr);
                                                break;
                                }
@@ -297,7 +307,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
 
                        /* Window decorations */
                        if (TEST_HINT(window.hints, HINT_UNDECORATED)) {
-                               /* fprintf(stderr, "Conky: hint - undecorated\n");
+                               /* fprintf(stderr, PACKAGE_NAME": hint - undecorated\n");
                                fflush(stderr); */
 
                                xa = ATOM(_MOTIF_WM_HINTS);
@@ -310,7 +320,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
 
                        /* Below other windows */
                        if (TEST_HINT(window.hints, HINT_BELOW)) {
-                               /* fprintf(stderr, "Conky: hint - below\n");
+                               /* fprintf(stderr, PACKAGE_NAME": hint - below\n");
                                fflush(stderr); */
 
                                xa = ATOM(_WIN_LAYER);
@@ -332,7 +342,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
 
                        /* Above other windows */
                        if (TEST_HINT(window.hints, HINT_ABOVE)) {
-                               /* fprintf(stderr, "Conky: hint - above\n");
+                               /* fprintf(stderr, PACKAGE_NAME": hint - above\n");
                                fflush(stderr); */
 
                                xa = ATOM(_WIN_LAYER);
@@ -354,7 +364,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
 
                        /* Sticky */
                        if (TEST_HINT(window.hints, HINT_STICKY)) {
-                               /* fprintf(stderr, "Conky: hint - sticky\n");
+                               /* fprintf(stderr, PACKAGE_NAME": hint - sticky\n");
                                fflush(stderr); */
 
                                xa = ATOM(_NET_WM_DESKTOP);
@@ -376,7 +386,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
 
                        /* Skip taskbar */
                        if (TEST_HINT(window.hints, HINT_SKIP_TASKBAR)) {
-                               /* fprintf(stderr, "Conky: hint - skip_taskbar\n");
+                               /* fprintf(stderr, PACKAGE_NAME": hint - skip_taskbar\n");
                                fflush(stderr); */
 
                                xa = ATOM(_NET_WM_STATE);
@@ -390,7 +400,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
 
                        /* Skip pager */
                        if (TEST_HINT(window.hints, HINT_SKIP_PAGER)) {
-                               /* fprintf(stderr, "Conky: hint - skip_pager\n");
+                               /* fprintf(stderr, PACKAGE_NAME": hint - skip_pager\n");
                                fflush(stderr); */
 
                                xa = ATOM(_NET_WM_STATE);
@@ -403,7 +413,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
                        }
                } /* else { window.type != TYPE_OVERRIDE */
 
-               fprintf(stderr, "Conky: drawing to created window (%lx)\n",
+               fprintf(stderr, PACKAGE_NAME": drawing to created window (0x%lx)\n",
                        window.window);
                fflush(stderr);
 
@@ -423,7 +433,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
                        window.height = attrs.height;
                }
 
-               fprintf(stderr, "Conky: drawing to desktop window\n");
+               fprintf(stderr, PACKAGE_NAME": drawing to desktop window\n");
        }
 
        /* Drawable is same as window. This may be changed by double buffering. */
@@ -440,7 +450,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
                                window.window, XdbeBackground);
                        if (window.back_buffer != None) {
                                window.drawable = window.back_buffer;
-                               fprintf(stderr, "Conky: drawing to double buffer\n");
+                               fprintf(stderr, PACKAGE_NAME": drawing to double buffer\n");
                        } else {
                                use_xdbe = 0;
                        }
@@ -450,7 +460,7 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour,
                }
        }
        if (!use_xdbe) {
-               fprintf(stderr, "Conky: drawing to single buffer\n");
+               fprintf(stderr, PACKAGE_NAME": drawing to single buffer\n");
        }
 #endif
 
@@ -517,10 +527,10 @@ long get_x11_color(const char *name)
        if (!XParseColor(display, DefaultColormap(display, screen), name, &color)) {
                /* lets check if it's a hex colour with the # missing in front
                 * if yes, then do something about it */
-               char newname[64];
+               char newname[DEFAULT_TEXT_BUFFER_SIZE];
 
                newname[0] = '#';
-               strncpy(&newname[1], name, 62);
+               strncpy(&newname[1], name, DEFAULT_TEXT_BUFFER_SIZE - 1);
                /* now lets try again */
                if (!XParseColor(display, DefaultColormap(display, screen), &newname[0],
                                &color)) {
@@ -535,7 +545,7 @@ long get_x11_color(const char *name)
        return (long) color.pixel;
 }
 
-void create_gc()
+void create_gc(void)
 {
        XGCValues values;
 
@@ -545,4 +555,9 @@ void create_gc()
                GCFunction | GCGraphicsExposures, &values);
 }
 
-#endif /* X11 */
+void update_x11info(void)
+{
+       struct information *current_info = &info;
+       current_info->x11.monitor.number = XScreenCount(display);
+       current_info->x11.monitor.current = XDefaultScreen(display);
+}