diff options
author | gotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2> | 2007-05-24 10:43:37 +0000 |
---|---|---|
committer | gotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2> | 2007-05-24 10:43:37 +0000 |
commit | b607cba0a9cb835143e61625ebbe9e1e5750d197 (patch) | |
tree | e3c19218d7fac7e5f6d71e56535cc3d7559574d9 | |
parent | 4ad34ccd36a59c1c5ec2ea9b4263ae6381f3feae (diff) | |
download | dzen-b607cba0a9cb835143e61625ebbe9e1e5750d197.tar.gz dzen-b607cba0a9cb835143e61625ebbe9e1e5750d197.zip |
added optional Xinerama support, thanks David Glasser
git-svn-id: http://dzen.googlecode.com/svn/trunk@29 f2baff5b-bf2c-0410-a398-912abdc3d8b2
-rw-r--r-- | README | 7 | ||||
-rw-r--r-- | config.mk | 10 | ||||
-rw-r--r-- | draw.c | 8 | ||||
-rw-r--r-- | dzen.h | 6 | ||||
-rw-r--r-- | main.c | 85 |
5 files changed, 92 insertions, 24 deletions
@@ -15,6 +15,7 @@ Features * flexible event/action mechanism * hideable, collapsable + * Xinerama support Requirements @@ -33,6 +34,10 @@ necessary as root): make clean install +Note: By default dzen will not be compiled with Xinerama support. + Uncomment the respective lines in config.mk to change this. + + Contact: -------- Feature requests, patches or anything else related to dzen can be send @@ -49,6 +54,7 @@ dzen accepts a couple of options: -ta alignement of title window content l(eft), c(center), r(right) -tw title window width + -sa alignment of slave window, see "-ta" -l lines, see (1) -e events and actions, see (2) -m menu, see (3) @@ -56,6 +62,7 @@ dzen accepts a couple of options: -x x position -y y position -w width + -xs number of Xinerama screen -v version information Termination: @@ -10,13 +10,19 @@ MANPREFIX = ${PREFIX}/share/man X11INC = /usr/X11R6/include X11LIB = /usr/X11R6/lib -# includes and libs INCS = -I. -I/usr/include -I${X11INC} +# No Xinerama: LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lpthread +# With Xinerama: +#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lpthread -lXinerama -# flags +# No Xinerama: CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" +# With Xinerama: +#CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA LDFLAGS = ${LIBS} + +# Debugging #CFLAGS = -g -Wall -O0 ${INCS} -DVERSION=\"${VERSION}\" -DPOSIX_SOURCE #LDFLAGS = -g ${LIBS} @@ -18,7 +18,9 @@ textnw(const char *text, unsigned int len) { return XTextWidth(dzen.font.xfont, text, len); } -void drawtext(const char *text, int reverse, int line, int align) { + +void +drawtext(const char *text, int reverse, int line, int align) { int x, y, w, h; static char buf[1024]; unsigned int len, olen; @@ -28,9 +30,9 @@ void drawtext(const char *text, int reverse, int line, int align) { mgc = reverse ? dzen.gc : dzen.rgc; - if(line == -1) + if(line == -1) /* title window */ XFillRectangles(dzen.dpy, dzen.title_win.drawable, mgc, &r, 1); - else + else /* slave window */ XFillRectangles(dzen.dpy, dzen.slave_win.drawable, mgc, &r, 1); if(!text) @@ -5,6 +5,9 @@ #include <X11/Xlib.h> #include <X11/Xutil.h> +#ifdef DZEN_XINERAMA +#include <X11/extensions/Xinerama.h> +#endif #include <pthread.h> #define FONT "-*-fixed-*-*-*-*-*-*-*-*-*-*-*-*" @@ -93,6 +96,9 @@ struct DZEN { pthread_mutex_t mt; int ret_val; + + /* should always be 0 if DZEN_XINERAMA not defined */ + int xinescreen; }; extern Dzen dzen; @@ -149,42 +149,73 @@ x_draw_body(void) { } static void -x_check_geometry(void) { - if(dzen.title_win.x > DisplayWidth(dzen.dpy, dzen.screen)) - dzen.title_win.x = 0; +x_check_geometry(XRectangle si) { + if(dzen.title_win.x > si.width) + dzen.title_win.x = si.x; + if (dzen.title_win.x < si.x) + dzen.title_win.x = si.x; if(!dzen.title_win.width) - dzen.title_win.width = DisplayWidth(dzen.dpy, dzen.screen); + dzen.title_win.width = si.width; - if((dzen.title_win.x + dzen.title_win.width) > DisplayWidth(dzen.dpy, dzen.screen)) - dzen.title_win.width = DisplayWidth(dzen.dpy, dzen.screen) - dzen.title_win.x; + if((dzen.title_win.x + dzen.title_win.width) > (si.x + si.width)) + dzen.title_win.width = si.width - (dzen.title_win.x - si.x); if(!dzen.slave_win.width) { - dzen.slave_win.x = 0; - dzen.slave_win.width = DisplayWidth(dzen.dpy, dzen.screen); + dzen.slave_win.x = si.x; + dzen.slave_win.width = si.width; } if( dzen.title_win.width == dzen.slave_win.width) { dzen.slave_win.x = dzen.title_win.x; dzen.slave_win.width = dzen.title_win.width; } - if(dzen.slave_win.width != DisplayWidth(dzen.dpy, dzen.screen)) { + if(dzen.slave_win.width != si.width) { dzen.slave_win.x = dzen.title_win.x + (dzen.title_win.width - dzen.slave_win.width)/2; - if(dzen.slave_win.x < 0) - dzen.slave_win.x = 0; - if(dzen.slave_win.width > DisplayWidth(dzen.dpy, dzen.screen)) - dzen.slave_win.width = DisplayWidth(dzen.dpy, dzen.screen); - if(dzen.slave_win.x + dzen.slave_win.width > DisplayWidth(dzen.dpy, dzen.screen)) - dzen.slave_win.x = DisplayWidth(dzen.dpy, dzen.screen) - dzen.slave_win.width; + if(dzen.slave_win.x < si.x) + dzen.slave_win.x = si.x; + if(dzen.slave_win.width > si.width) + dzen.slave_win.width = si.width; + if(dzen.slave_win.x + dzen.slave_win.width > si.width) + dzen.slave_win.x = si.x + (si.width - dzen.slave_win.width); } dzen.line_height = dzen.font.height + 2; - dzen.title_win.y = (dzen.title_win.y + dzen.line_height) > DisplayHeight(dzen.dpy, dzen.screen) ? 0 : dzen.title_win.y; + dzen.title_win.y = si.y + ((dzen.title_win.y + dzen.line_height) > si.height ? 0 : dzen.title_win.y); } static void +qsi_no_xinerama(Display *dpy, XRectangle *rect) { + rect->x = 0; + rect->y = 0; + rect->width = DisplayWidth( dpy, DefaultScreen(dpy)); + rect->height = DisplayHeight(dpy, DefaultScreen(dpy)); +} + +#ifdef DZEN_XINERAMA +static void +queryscreeninfo(Display *dpy, XRectangle *rect, int screen) { + XineramaScreenInfo *xsi = NULL; + int nscreens = 1; + + if(XineramaIsActive(dpy)) + xsi = XineramaQueryScreens(dpy, &nscreens); + + if(xsi == NULL || screen > nscreens || screen <= 0) { + qsi_no_xinerama(dpy, rect); + } else { + rect->x = xsi[screen-1].x_org; + rect->y = xsi[screen-1].y_org; + rect->width = xsi[screen-1].width; + rect->height = xsi[screen-1].height; + } +} +#endif + +static void x_create_windows(void) { XSetWindowAttributes wa; Window root; int i; + XRectangle si; dzen.dpy = XOpenDisplay(0); if(!dzen.dpy) @@ -203,7 +234,13 @@ x_create_windows(void) { wa.background_pixmap = ParentRelative; wa.event_mask = ExposureMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask; - x_check_geometry(); +#ifdef DZEN_XINERAMA + queryscreeninfo(dzen.dpy, &si, dzen.xinescreen); +#else + qsi_no_xinerama(dzen.dpy, &si); +#endif + + x_check_geometry(si); /* title window */ dzen.title_win.win = XCreateWindow(dzen.dpy, root, @@ -221,7 +258,7 @@ x_create_windows(void) { dzen.slave_win.issticky = False; dzen.slave_win.y = dzen.title_win.y + dzen.line_height; - if(dzen.title_win.y + dzen.line_height*dzen.slave_win.max_lines > DisplayHeight(dzen.dpy, dzen.screen)) + if(dzen.title_win.y + dzen.line_height*dzen.slave_win.max_lines > si.height) dzen.slave_win.y = (dzen.title_win.y - dzen.line_height) - dzen.line_height*(dzen.slave_win.max_lines) + dzen.line_height; dzen.slave_win.win = XCreateWindow(dzen.dpy, root, @@ -425,6 +462,7 @@ main(int argc, char *argv[]) { dzen.fg = FGCOLOR; dzen.slave_win.max_lines = 0; dzen.running = True; + dzen.xinescreen = 0; /* cmdline args */ @@ -468,12 +506,21 @@ main(int argc, char *argv[]) { else if(!strncmp(argv[i], "-tw", 3)) { if(++i < argc) dzen.title_win.width = atoi(argv[i]); } +#ifdef DZEN_XINERAMA + else if(!strncmp(argv[i], "-xs", 4)) { + if(++i < argc) dzen.xinescreen = atoi(argv[i]); + } +#endif else if(!strncmp(argv[i], "-v", 3)) eprint("dzen-"VERSION", (C)opyright 2007 Robert Manea\n"); else eprint("usage: dzen2 [-v] [-p] [-m] [-ta <l|c|r>] [-sa <l|c|r>] [-tw <pixel>]\n" " [-e <string>] [-x <pixel>] [-y <pixel>] [-w <pixel>] \n" - " [-l <lines>] [-fn <font>] [-bg <color>] [-fg <color>] \n"); + " [-l <lines>] [-fn <font>] [-bg <color>] [-fg <color>] \n" +#ifdef DZEN_XINERAMA + " [-xs <screen>]\n" +#endif + ); if(!dzen.title_win.width) dzen.title_win.width = dzen.slave_win.width; |