[Xmonad] patch: Xinerama support for dzen
David Glasser
glasser at mit.edu
Wed May 23 21:58:18 EDT 2007
Inspired by jcreigh's patch for dmenu
(http://www.jcreigh.com/xmonad/xinerama-dmenu.html), here's a patch to
add Xinerama support to dzen. By changing stuff in config.mk, you can
make it entirely disappear. If it's compiled in, you can add "-xs 1"
to your command line to place the message on screen 1, etc.
--dave
--
David Glasser | glasser at mit.edu | http://www.davidglasser.net/
-------------- next part --------------
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 <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;
Index: dzen.h
===================================================================
--- dzen.h (revision 28)
+++ dzen.h (working copy)
@@ -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 @@
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}
More information about the Xmonad
mailing list