Index: main.c =================================================================== --- main.c (revision 28) +++ main.c (working copy) @@ -149,42 +149,73 @@ } 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,8 +234,14 @@ 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, dzen.title_win.x, dzen.title_win.y, dzen.title_win.width, dzen.line_height, 0, @@ -221,7 +258,7 @@ 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 @@ dzen.fg = FGCOLOR; dzen.slave_win.max_lines = 0; dzen.running = True; + dzen.xinescreen = 0; /* cmdline args */ @@ -468,12 +506,21 @@ 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 ] [-sa ] [-tw ]\n" " [-e ] [-x ] [-y ] [-w ] \n" - " [-l ] [-fn ] [-bg ] [-fg ] \n"); + " [-l ] [-fn ] [-bg ] [-fg ] \n" +#ifdef DZEN_XINERAMA + " [-xs ]\n" +#endif + ); if(!dzen.title_win.width) dzen.title_win.width = dzen.slave_win.width; Index: dzen.h =================================================================== --- dzen.h (revision 28) +++ dzen.h (working copy) @@ -5,6 +5,9 @@ #include #include +#ifdef DZEN_XINERAMA +#include +#endif #include #define FONT "-*-fixed-*-*-*-*-*-*-*-*-*-*-*-*" @@ -93,6 +96,9 @@ pthread_mutex_t mt; int ret_val; + + /* should always be 0 if DZEN_XINERAMA not defined */ + int xinescreen; }; extern Dzen dzen; Index: config.mk =================================================================== --- config.mk (revision 28) +++ config.mk (working copy) @@ -12,10 +12,16 @@ # includes and libs INCS = -I. -I/usr/include -I${X11INC} -LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lpthread +# No Xinerama: +# LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lpthread +# With Xinerama: +LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lpthread -lXinerama # flags -CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" +# No Xinerama: +# CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" +# With Xinerama: +CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA LDFLAGS = ${LIBS} #CFLAGS = -g -Wall -O0 ${INCS} -DVERSION=\"${VERSION}\" -DPOSIX_SOURCE #LDFLAGS = -g ${LIBS}