#ifdef X11
#include <X11/Xlib.h>
#include <X11/Xatom.h>
+#include <X11/Xmd.h>
#include <X11/Xutil.h>
#ifdef XFT
#include <X11/Xft/Xft.h>
#endif
+#include <stdio.h>
+
#ifdef XDBE
int use_xdbe;
#endif
int use_xft = 0;
#endif
+#define WINDOW_NAME_FMT "%s - conky"
+
/* some basic X11 stuff */
Display *display;
int display_width;
/* local prototypes */
static void update_workarea();
-static Window find_window_to_draw();
+static Window find_desktop_window(Window *p_root, Window *p_desktop);
static Window find_subwindow(Window win, int w, int h);
/* X11 initializer */
}
}
-static Window find_window_to_draw()
+/* 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;
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);
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);
+ fflush(stderr);
+ *p_root=win;
+ *p_desktop=win;
return win;
}
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);
+
+ fflush(stderr);
+
+ *p_root=root;
+ *p_desktop=win;
return win;
}
//XClearWindow(display, win); not sure why this was here
}
-#if defined OWN_WINDOW
-void init_window(int own_window, int w, int h, int l, int fixed_pos, int set_trans, int back_colour)
-#else
-void init_window(int own_window, int w, int h, int l, int set_trans, int back_colour)
-#endif
+void init_window(int own_window, int w, int h, int set_trans, int back_colour, char * nodename,
+ 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
* happens but I bet the bug is somewhere here. */
set_transparent = set_trans;
background_colour = back_colour;
+
+ nodename = (char *)nodename;
+
#ifdef OWN_WINDOW
if (own_window) {
+
+ if ( !find_desktop_window( &window.root, &window.desktop ) )
+ return;
- /* looks like root pixmap isn't needed for anything */
- {
- XSetWindowAttributes attrs;
- XClassHint class_hints;
-
- /* just test color
- attrs.background_pixel = get_x11_color("green");
+ 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,
+ 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);
- 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 = "conky";
- class_hints.res_name = "conky";
- XSetClassHint(display, window.window,
- &class_hints);
-
- /*set_transparent_background(window.window);*/
+ }
- XStoreName(display, window.window, "conky");
+ else { /* window.type != TYPE_OVERRIDE */
- XClearWindow(display, window.window);
+ /*
+ 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];
+
+ /* 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.wm_class_name;
+ classHint.res_class = classHint.res_name;
+
+ wmHint.flags = InputHint | StateHint;
+ wmHint.input = False;
+ wmHint.initial_state = NormalState;
+
+ sprintf(window_title,WINDOW_NAME_FMT,nodename);
+
+ XmbSetWMProperties (display, window.window, window_title, NULL,
+ argv, argc,
+ NULL, &wmHint, &classHint);
+
+ /* Sets an empty WM_PROTOCOLS property */
+ XSetWMProtocols(display,window.window,NULL,0);
+
+
+ /* 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);
+ }
- if (!fixed_pos)
- XMoveWindow(display, window.window, window.x,
- window.y);
- }
+ /* Set desired hints */
+
+ /* Window decorations */
+ if (TEST_HINT(window.hints,HINT_UNDECORATED)) {
+ fprintf(stderr, "Conky: hint - undecorated\n"); fflush(stderr);
- {
- /* turn off decorations */
- Atom a =
- XInternAtom(display, "_MOTIF_WM_HINTS", True);
- if (a != None) {
+ xa = ATOM(_MOTIF_WM_HINTS);
+ if (xa != None) {
long prop[5] = { 2, 0, 0, 0, 0 };
- XChangeProperty(display, window.window, a,
- a, 32, PropModeReplace,
+ XChangeProperty(display, window.window, xa,
+ xa, 32, PropModeReplace,
(unsigned char *) prop, 5);
+ }
}
- /* 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);
- }
- 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);
- }
+ /* Below other windows */
+ if (TEST_HINT(window.hints,HINT_BELOW)) {
+ fprintf(stderr, "Conky: hint - below\n"); fflush(stderr);
+
+ xa = ATOM(_WIN_LAYER);
+ if (xa != None) {
+ long prop = 0;
+ XChangeProperty(display, window.window, xa,
+ XA_CARDINAL, 32,
+ PropModeAppend,
+ (unsigned char *) &prop, 1);
+ }
+
+ xa = ATOM(_NET_WM_STATE);
+ if (xa != None) {
+ Atom xa_prop = ATOM(_NET_WM_STATE_BELOW);
+ XChangeProperty(display, window.window, xa,
+ XA_ATOM, 32,
+ PropModeAppend,
+ (unsigned char *) &xa_prop,
+ 1);
+ }
}
- }
+
+ /* Above other windows */
+ if (TEST_HINT(window.hints,HINT_ABOVE)) {
+ fprintf(stderr, "Conky: hint - above\n"); fflush(stderr);
+
+ xa = ATOM(_WIN_LAYER);
+ if (xa != None) {
+ long prop = 6;
+ XChangeProperty(display, window.window, xa,
+ XA_CARDINAL, 32,
+ PropModeAppend,
+ (unsigned char *) &prop, 1);
+ }
+
+ xa = ATOM(_NET_WM_STATE);
+ if (xa != None) {
+ Atom xa_prop = ATOM(_NET_WM_STATE_ABOVE);
+ XChangeProperty(display, window.window, xa,
+ XA_ATOM, 32,
+ PropModeAppend,
+ (unsigned char *) &xa_prop,
+ 1);
+ }
+ }
+
+ /* Sticky */
+ if (TEST_HINT(window.hints,HINT_STICKY)) {
+ fprintf(stderr, "Conky: hint - sticky\n"); fflush(stderr);
+
+ xa = ATOM(_NET_WM_DESKTOP);
+ if (xa != None) {
+ CARD32 xa_prop = 0xFFFFFFFF;
+ XChangeProperty(display, window.window, xa,
+ XA_CARDINAL, 32,
+ PropModeAppend,
+ (unsigned char *) &xa_prop,
+ 1);
+ }
+
+ xa = ATOM(_NET_WM_STATE);
+ if (xa != None) {
+ Atom xa_prop = ATOM(_NET_WM_STATE_STICKY);
+ XChangeProperty(display, window.window, xa,
+ XA_ATOM, 32,
+ PropModeAppend,
+ (unsigned char *) &xa_prop,
+ 1);
+ }
+ }
+
+ /* Skip taskbar */
+ if (TEST_HINT(window.hints,HINT_SKIP_TASKBAR)) {
+ fprintf(stderr, "Conky: hint - skip_taskbar\n"); fflush(stderr);
+
+ xa = ATOM(_NET_WM_STATE);
+ if (xa != None) {
+ Atom xa_prop = ATOM(_NET_WM_STATE_SKIP_TASKBAR);
+ XChangeProperty(display, window.window, xa,
+ XA_ATOM, 32,
+ PropModeAppend,
+ (unsigned char *) &xa_prop,
+ 1);
+ }
+ }
+
+ /* Skip pager */
+ if (TEST_HINT(window.hints,HINT_SKIP_PAGER)) {
+ fprintf(stderr, "Conky: hint - skip_pager\n"); fflush(stderr);
+
+ xa = ATOM(_NET_WM_STATE);
+ if (xa != None) {
+ Atom xa_prop = ATOM(_NET_WM_STATE_SKIP_PAGER);
+ XChangeProperty(display, window.window, xa,
+ XA_ATOM, 32,
+ PropModeAppend,
+ (unsigned char *) &xa_prop,
+ 1);
+ }
+ }
+
+ } /* else { window.type != TYPE_OVERRIDE */
+
+ fprintf(stderr, "Conky: drawing to created window (%lx)\n", window.window);
+ fflush(stderr);
XMapWindow(display, window.window);
- } else
+
+ } else /* if (own_window) { */
#endif
/* root / desktop window */
{
XWindowAttributes attrs;
if (!window.window)
- window.window = find_window_to_draw();
+ window.window = find_desktop_window( &window.root, &window.desktop );
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. */
XSelectInput(display, window.window, ExposureMask
#ifdef OWN_WINDOW
| (own_window
- ? (StructureNotifyMask | PropertyChangeMask) : 0)
+ ? (StructureNotifyMask | PropertyChangeMask |
+ ButtonPressMask | ButtonReleaseMask) : 0)
#endif
);
}
color.pixel = 0;
if (!XParseColor
(display, DefaultColormap(display, screen), name, &color)) {
- ERR("can't parse X color '%s'", name);
- return 0xFF00FF;
+ /* lets check if it's a hex colour with the # missing in front
+ * if yes, then do something about it
+ */
+ char newname[64];
+ newname[0] = '#';
+ strncpy(&newname[1], name, 62);
+ /* now lets try again */
+ if (!XParseColor(display, DefaultColormap(display, screen), &newname[0], &color)) {
+ ERR("can't parse X color '%s'", name);
+ return 0xFF00FF;
+ }
}
if (!XAllocColor
(display, DefaultColormap(display, screen), &color))