diff options
author | gotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2> | 2007-08-14 13:51:10 +0000 |
---|---|---|
committer | gotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2> | 2007-08-14 13:51:10 +0000 |
commit | 8637be0fdc4e67434d76fed1ca65e54bb92ddb41 (patch) | |
tree | 1d88643b3b2c241d6457f0409abea13c4a3a59fc | |
parent | c6884614e88d1f194f4572711b2493a6da6561c4 (diff) | |
download | dzen-8637be0fdc4e67434d76fed1ca65e54bb92ddb41.tar.gz dzen-8637be0fdc4e67434d76fed1ca65e54bb92ddb41.zip |
added XPM icons support
drawing enhancement and fixes
added command line option '-h' to set the line height
git-svn-id: http://dzen.googlecode.com/svn/trunk@153 f2baff5b-bf2c-0410-a398-912abdc3d8b2
-rw-r--r-- | INSTALL | 2 | ||||
-rw-r--r-- | README | 23 | ||||
-rw-r--r-- | README.dzen | 22 | ||||
-rw-r--r-- | TODO | 13 | ||||
-rw-r--r-- | action.c | 17 | ||||
-rw-r--r-- | action.h | 2 | ||||
-rw-r--r-- | config.mk | 23 | ||||
-rw-r--r-- | draw.c | 167 | ||||
-rw-r--r-- | main.c | 7 |
9 files changed, 213 insertions, 63 deletions
@@ -18,7 +18,7 @@ Optionally if you want to use dzen's gadgets: make clean install -Note: By default dzen will not be compiled with Xinerama support. +Note: By default dzen will not be compiled with Xinerama and XPM support. Uncomment the respective lines in config.mk to change this. @@ -59,7 +59,7 @@ Optionally if you want to use dzen's gadgets: make clean install -Note: By default dzen will not be compiled with Xinerama support. +Note: By default dzen will not be compiled with Xinerama and XPM support. Uncomment the respective lines in config.mk to change this. @@ -88,6 +88,7 @@ dzen accepts a couple of options: -p persist EOF (optional timeout in seconds) -x x position -y y position + -h line height (default: fontheight + 2 pixels) -w width -xs number of Xinerama screen -v version information @@ -149,7 +150,7 @@ Q4: Ok, the title and slave thing works, can I update the A4: Sure, see "(4) Simultaneous updates" or use the in-text command "^tw()" to explicitly draw to the title windwow. - See section (5) for further details + See section (5) for further details Q5: Can i chnage color of my input at runtime? @@ -290,6 +291,10 @@ Supported actions: scrolldown:n scroll slave window n lines down (default n=1) grabkeys enable keyboard support ungrabkeys disable keyboard support + grabmouse enable mouse support + only needed with specific windowmanagers, such as fluxbox + ungrabmouse release mouse + only needed with specific windowmanagers, such as fluxbox Note: If no events/actions are specified dzen defaults to: @@ -399,7 +404,10 @@ Currently the following commands are supported: ^co(RADIUS) circle outline ^p(PIXEL) increment momentary position by PIXEL + ^i(path) draw icon specified by path + Supported formats: XBM and optionally XPM + ^tw() draw to title window This command has some annoyances, as only @@ -414,10 +422,13 @@ input. The color can be specified either as symbolic name (e.g. red, darkgreen, etc.) or as #rrggbb hex-value (e.g. #ffffaa). -Icons must be in the XBM format, see the "bitmaps" directory for some -sample icons. With the standard "bitmap" application you can easily draw -your own icons, though there are lots floating around on your harddisk -or on the web. +Icons must be in the XBM or optionally XPM format, see the "bitmaps" +directory for some sample icons. With the standard "bitmap" application +you can easily draw your own icons. + +Note: Displaying XPM (pixmap) files imposes a somewhat + higher load than lightweight XBM files, so use + them with care in tight loops. Rectangles will be truncated to the maximum possible size if you specify a size bigger than dzen's window. diff --git a/README.dzen b/README.dzen index 952ca63..0f1790e 100644 --- a/README.dzen +++ b/README.dzen @@ -20,6 +20,8 @@ Script archive with a collection of interesting ideas: ^co(4x4) dynamic colorizer + ^co(4x4) icons support + ^co(4x4) keyboard support ^co(4x4) single line and/or windows holding multiple lines @@ -57,7 +59,7 @@ Optionally if you want to use dzen's gadgets: ^fg(grey85)make clean install -^fg(Khaki)Note: By default dzen will ^fg(red)not^fg(Khaki) be compiled with Xinerama support. +^fg(Khaki)Note: By default dzen will ^fg(red)not^fg(Khaki) be compiled with Xinerama and XPM support. ^fg(Khaki)Uncomment the respective lines in config.mk to change this. @@ -86,6 +88,7 @@ dzen accepts a couple of options: -p persist EOF (optional timeout in seconds) -x x position -y y position + -h line height (default: fontheight + 2 pixels) -w width -xs number of Xinerama screen -v version information @@ -287,6 +290,10 @@ An example: scrolldown:n scroll slave window n lines down (default n=1) grabkeys enable keyboard support ungrabkeys disable keyboard support + grabmouse enable mouse support + only needed with specific windowmanagers, such as fluxbox + ungrabmouse release mouse + only needed with specific windowmanagers, such as fluxbox ^fg(Khaki)Note: If no events/actions are specified dzen defaults to: @@ -396,7 +403,9 @@ Currently the following commands are supported: ^^co(RADIUS) circle outline ^^p(PIXEL) increment momentary position by PIXEL + ^^i(path) draw icon specified by path + Supported formats: XBM and optionally XPM ^^tw() draw to title window This command has some annoyances, as only @@ -411,10 +420,13 @@ input. The color can be specified either as symbolic name (e.g. red, darkgreen, etc.) or as #rrggbb hex-value (e.g. #ffffaa). -Icons must be in the XBM format, see the "bitmaps" directory for some -sample icons. With the standard "bitmap" application you can easily draw -your own icons, though there are lots floating around on your harddisk -or on the web. +Icons must be in the XBM or optionally XPM format, see the "bitmaps" +directory for some sample icons. With the standard "bitmap" application +you can easily draw your own icons. + +^fg(Khaki)Note: Displaying XPM (pixmap) files imposes a somewhat + ^fg(Khaki)higher load than lightweight XBM files, so use + ^fg(Khaki)them with care in tight loops. Rectangles will be truncated to the maximum possible size if you specify a size bigger than dzen's window. @@ -1,16 +1,19 @@ # X related - o XRandR support + o XRandR support (MEDIUM PRIORITY) + o cache XPM files in order to improve drawing + performace (HIGH PRIORITY) # extend available actions - o set font action - o any other useful action + o set font action (LOW PRIORITY) + o any other useful action (LOW PRIORITY) # user interface o improve in-text command to draw - to the title window - o auto fit window width to text length + to the title window (MEDIUM PRIORITY) + o auto fit window width to + text length (MEDIUM PRIORITY) @@ -53,6 +53,8 @@ struct action_lookup ac_lookup_table[] = { { "scrollend", a_scrollend}, { "grabkeys", a_grabkeys}, { "ungrabkeys", a_ungrabkeys}, + { "grabmouse", a_grabmouse}, + { "ungrabmouse", a_ungrabmouse}, { 0, 0 } }; @@ -526,3 +528,18 @@ a_ungrabkeys(char * opt[]) { return 0; } +int +a_grabmouse(char * opt[]) { + (void)opt; + XGrabPointer(dzen.dpy, RootWindow(dzen.dpy, dzen.screen), + True, ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); + return 0; +} + +int +a_ungrabmouse(char * opt[]) { + (void)opt; + XUngrabPointer(dzen.dpy, CurrentTime); + return 0; +} + @@ -80,4 +80,6 @@ int a_scrollhome(char **); int a_scrollend(char **); int a_grabkeys(char **); int a_ungrabkeys(char **); +int a_grabmouse(char **); +int a_ungrabmouse(char **); @@ -11,15 +11,32 @@ X11INC = /usr/X11R6/include X11LIB = /usr/X11R6/lib INCS = -I. -I/usr/include -I${X11INC} - -# No Xinerama, comment the following two lines for Xinerama +# Configure the features you want to be supported +# Only one of the following options has to be uncommented, +# all others must be commented! +# +# Uncomment: Remove # from the beginning of respective lines +# Comment : Add # to the beginning of the respective lines + +# Option 1: No Xinerama no XPM LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -# With Xinerama, uncomment the following two lines for Xinerama +# Option 2: No Xinerama with XPM +#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXpm +#CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XPM + +# Option 3: With Xinerama no XPM #LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama #CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA +# Option 4: With Xinerama and XPM +#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama -lXpm +#CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA -DDZEN_XPM + +# END of feature configuration + + LDFLAGS = ${LIBS} # Solaris, uncomment for Solaris @@ -9,6 +9,9 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#ifdef DZEN_XPM +#include <X11/xpm.h> +#endif /* command types for the in-text parser */ enum ctype {bg, fg, icon, rect, recto, circle, circleo, pos, titlewin}; @@ -184,24 +187,14 @@ get_token(const char *line, int * t, char **tval) { return next_pos+off; } -static void -set_opts(int type, char * value, int reverse) { - - if(!strncmp(value, "", 1)) - value = NULL; - - switch(type) { - case fg: - reverse ? - XSetBackground(dzen.dpy, dzen.tgc, value ? getcolor(value) : dzen.norm[ColFG]): - XSetForeground(dzen.dpy, dzen.tgc, value ? getcolor(value) : dzen.norm[ColFG]); - break; - case bg: - reverse ? - XSetForeground(dzen.dpy, dzen.tgc, value ? getcolor(value) : dzen.norm[ColBG]): - XSetBackground(dzen.dpy, dzen.tgc, value ? getcolor(value) : dzen.norm[ColBG]); - break; - } +static void +setcolor(Drawable *pm, int x, int width, long fg, long bg, int reverse) { + + XSetForeground(dzen.dpy, dzen.tgc, reverse ? fg : bg); + //XSetBackground(dzen.dpy, dzen.tgc, reverse ? bg : fg); + XFillRectangle(dzen.dpy, *pm, dzen.tgc, x, 0, width, dzen.line_height); + XSetForeground(dzen.dpy, dzen.tgc, reverse ? bg : fg); + XSetBackground(dzen.dpy, dzen.tgc, reverse ? fg : bg); } static void @@ -228,10 +221,18 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { char lbuf[MAX_LINE_LEN], *rbuf = NULL; int t=-1; char *tval=NULL; + long lastfg = dzen.norm[ColFG], lastbg = dzen.norm[ColBG]; XGCValues gcv; Drawable pm=0, bm; +#ifdef DZEN_XPM + int free_xpm_attrib = 0; + Pixmap xpm_pm; + XpmAttributes xpma; + XpmColorSymbol xpms; +#endif XRectangle r = { dzen.x, dzen.y, dzen.w, dzen.h}; + /* parse line and return the text without control commands*/ if(nodraw) { rbuf = emalloc(MAX_LINE_LEN); @@ -248,6 +249,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { py = dzen.font.ascent + (dzen.line_height - h) / 2; xorig = 0; + if(lnr != -1) { pm = XCreatePixmap(dzen.dpy, RootWindow(dzen.dpy, DefaultScreen(dzen.dpy)), dzen.slave_win.width, dzen.line_height, DefaultDepth(dzen.dpy, dzen.screen)); @@ -260,10 +262,16 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { if(!reverse) { XSetBackground(dzen.dpy, dzen.tgc, dzen.norm[ColBG]); XSetForeground(dzen.dpy, dzen.tgc, dzen.norm[ColBG]); +#ifdef DZEN_XPM + xpms.pixel = dzen.norm[ColBG]; +#endif } else { XSetBackground(dzen.dpy, dzen.tgc, dzen.norm[ColFG]); XSetForeground(dzen.dpy, dzen.tgc, dzen.norm[ColFG]); +#ifdef DZEN_XPM + xpms.pixel = dzen.norm[ColFG]; +#endif } XFillRectangles(dzen.dpy, pm, dzen.tgc, &r, 1); @@ -274,6 +282,18 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { XSetForeground(dzen.dpy, dzen.tgc, dzen.norm[ColBG]); } +#ifdef DZEN_XPM + xpms.name = NULL; + xpms.value = "none"; + + xpma.colormap = DefaultColormap(dzen.dpy, dzen.screen); + xpma.depth = DefaultDepth(dzen.dpy, dzen.screen); + xpma.visual = DefaultVisual(dzen.dpy, dzen.screen); + xpma.colorsymbols = &xpms; + xpma.numsymbols = 1; + xpma.valuemask = XpmColormap|XpmDepth|XpmVisual|XpmColorSymbols; +#endif + if(!dzen.font.set){ gcv.font = dzen.font.xfont->fid; XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv); @@ -306,18 +326,32 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { if(XReadBitmapFile(dzen.dpy, pm, tval, &bm_w, &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess && (h/2 + px + (signed)bm_w < dzen.w)) { + setcolor(&pm, px, bm_w, lastfg, lastbg, reverse); XCopyPlane(dzen.dpy, bm, pm, dzen.tgc, 0, 0, bm_w, bm_h, px, dzen.line_height >= (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0, 1); XFreePixmap(dzen.dpy, bm); px += bm_w; } +#ifdef DZEN_XPM + else if(XpmReadFileToPixmap(dzen.dpy, dzen.title_win.win, tval, &xpm_pm, NULL, &xpma) == XpmSuccess) { + setcolor(&pm, px, xpma.width, lastfg, lastbg, reverse); + XCopyArea(dzen.dpy, xpm_pm, pm, dzen.tgc, + 0, 0, xpma.width, xpma.height, px, + dzen.line_height >= (signed)xpma.height ? (dzen.line_height - xpma.height)/2 : 0); + px += xpma.width; + + XFreePixmap(dzen.dpy, xpm_pm); + free_xpm_attrib = 1; + } +#endif } else if(t == rect) { get_rect_vals(tval, &rectw, &recth); rectw = rectw+px > dzen.w ? dzen.w-px : rectw; recth = recth > dzen.line_height ? dzen.line_height : recth; recty = (dzen.line_height - recth)/2; + setcolor(&pm, px, rectw, lastfg, lastbg, reverse); XFillRectangle(dzen.dpy, pm, dzen.tgc, px, (int)recty, rectw, recth); px += rectw; @@ -327,27 +361,40 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { rectw = rectw+px > dzen.w ? dzen.w-px : rectw; recth = recth > dzen.line_height ? dzen.line_height : recth-1; recty = (dzen.line_height - recth)/2; + setcolor(&pm, px, rectw, lastfg, lastbg, reverse); XDrawRectangle(dzen.dpy, pm, dzen.tgc, px, (int)recty, rectw-1, recth); px += rectw; } else if(t == circle) { rectw = recth = atoi(tval); + setcolor(&pm, px, rectw, lastfg, lastbg, reverse); XFillArc(dzen.dpy, pm, dzen.tgc, px, (dzen.line_height - recth)/2, rectw, recth, 2880, 23040); px += rectw; } else if(t == circleo) { rectw = recth = atoi(tval); + setcolor(&pm, px, rectw, lastfg, lastbg, reverse); XDrawArc(dzen.dpy, pm, dzen.tgc, px, (dzen.line_height - recth)/2, rectw-1, recth-1, 2880, 23040); px += rectw; } else if(t == pos) { if((n_pos = atoi(tval)) < 0) n_pos *= -1; + setcolor(&pm, px, n_pos, lastfg, lastbg, reverse); px += n_pos; } - else - set_opts(t, tval, reverse); + else { + if(!strncmp(tval, "", 1)) + tval = NULL; + if(t == bg) { + lastbg = (tval ? getcolor(tval) : dzen.norm[ColBG]); + } + else if(t == fg) { + lastfg = tval ? getcolor(tval) : dzen.norm[ColFG]; + XSetForeground(dzen.dpy, dzen.tgc, lastfg); + } + } free(tval); } @@ -367,11 +414,12 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { } + setcolor(&pm, px, tw, lastfg, lastbg, reverse); if(dzen.font.set) - XmbDrawImageString(dzen.dpy, pm, dzen.font.set, + XmbDrawString(dzen.dpy, pm, dzen.font.set, dzen.tgc, px, py, lbuf, strlen(lbuf)); else - XDrawImageString(dzen.dpy, pm, dzen.tgc, px, py, lbuf, strlen(lbuf)); + XDrawString(dzen.dpy, pm, dzen.tgc, px, py, lbuf, strlen(lbuf)); px += tw; } @@ -392,52 +440,80 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { strcat(rbuf, lbuf); } else { - if(t != -1 && tval){ + if(t != -1 && tval) { if(t == icon) { if(XReadBitmapFile(dzen.dpy, pm, tval, &bm_w, &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess && (h/2 + px + (signed)bm_w < dzen.w)) { + setcolor(&pm, px, bm_w, lastfg, lastbg, reverse); XCopyPlane(dzen.dpy, bm, pm, dzen.tgc, 0, 0, bm_w, bm_h, px, - dzen.line_height > (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0, 1); + dzen.line_height >= (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0, 1); XFreePixmap(dzen.dpy, bm); px += bm_w; } +#ifdef DZEN_XPM + else if(XpmReadFileToPixmap(dzen.dpy, dzen.title_win.win, tval, &xpm_pm, NULL, &xpma) == XpmSuccess) { + setcolor(&pm, px, xpma.width, lastfg, lastbg, reverse); + XCopyArea(dzen.dpy, xpm_pm, pm, dzen.tgc, + 0, 0, xpma.width, xpma.height, px, + dzen.line_height >= (signed)xpma.height ? (dzen.line_height - xpma.height)/2 : 0); + px += xpma.width; + + XFreePixmap(dzen.dpy, xpm_pm); + free_xpm_attrib = 1; + } +#endif } - else if(t == rect) { - get_rect_vals(tval, &rectw, &recth); - rectw = rectw+px > dzen.w ? dzen.w-px : rectw; - recth = recth > dzen.line_height ? dzen.line_height : recth; + else if(t == rect) { + get_rect_vals(tval, &rectw, &recth); + rectw = rectw+px > dzen.w ? dzen.w-px : rectw; + recth = recth > dzen.line_height ? dzen.line_height : recth; recty = (dzen.line_height - recth)/2; + setcolor(&pm, px, rectw, lastfg, lastbg, reverse); XFillRectangle(dzen.dpy, pm, dzen.tgc, px, (int)recty, rectw, recth); - px += rectw; - } - else if(t == recto) { - get_rect_vals(tval, &rectw, &recth); - rectw = rectw+px > dzen.w ? dzen.w-px : rectw; - recth = recth > dzen.line_height ? dzen.line_height : recth-1; + + px += rectw; + } + else if(t == recto) { + get_rect_vals(tval, &rectw, &recth); + rectw = rectw+px > dzen.w ? dzen.w-px : rectw; + recth = recth > dzen.line_height ? dzen.line_height : recth-1; recty = (dzen.line_height - recth)/2; + setcolor(&pm, px, rectw, lastfg, lastbg, reverse); XDrawRectangle(dzen.dpy, pm, dzen.tgc, px, (int)recty, rectw-1, recth); - px += rectw; - } + px += rectw; + } else if(t == circle) { rectw = recth = atoi(tval); + setcolor(&pm, px, rectw, lastfg, lastbg, reverse); XFillArc(dzen.dpy, pm, dzen.tgc, px, (dzen.line_height - recth)/2, rectw, recth, 2880, 23040); px += rectw; } else if(t == circleo) { rectw = recth = atoi(tval); + setcolor(&pm, px, rectw, lastfg, lastbg, reverse); XDrawArc(dzen.dpy, pm, dzen.tgc, px, (dzen.line_height - recth)/2, rectw-1, recth-1, 2880, 23040); px += rectw; } else if(t == pos) { if((n_pos = atoi(tval)) < 0) n_pos *= -1; + setcolor(&pm, px, n_pos, lastfg, lastbg, reverse); px += n_pos; } - else - set_opts(t, tval, reverse); + else { + if(!strncmp(tval, "", 1)) + tval = NULL; + if(t == bg) { + lastbg = (tval ? getcolor(tval) : dzen.norm[ColBG]); + } + else if(t == fg) { + lastfg = tval ? getcolor(tval) : dzen.norm[ColFG]; + XSetForeground(dzen.dpy, dzen.tgc, lastfg); + } + } free(tval); } @@ -457,12 +533,12 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { } - if(dzen.font.set) - XmbDrawImageString(dzen.dpy, pm, dzen.font.set, + setcolor(&pm, px, tw, lastfg, lastbg, reverse); + if(dzen.font.set) + XmbDrawString(dzen.dpy, pm, dzen.font.set, dzen.tgc, px, py, lbuf, strlen(lbuf)); else - XDrawImageString(dzen.dpy, pm, dzen.tgc, px, py, lbuf, strlen(lbuf)); - + XDrawString(dzen.dpy, pm, dzen.tgc, px, py, lbuf, strlen(lbuf)); px += tw; @@ -488,6 +564,13 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { 0, 0, px, dzen.line_height, xorig, 0); } XFreePixmap(dzen.dpy, pm); + +#ifdef DZEN_XPM + if(free_xpm_attrib) { + XFreeColors(dzen.dpy, xpma.colormap, xpma.pixels, xpma.npixels, xpma.depth); + XpmFreeAttributes(&xpma); + } +#endif } return nodraw ? rbuf : NULL; @@ -239,7 +239,8 @@ x_check_geometry(XRectangle si) { if(dzen.slave_win.x + dzen.slave_win.width > si.x + si.width) dzen.slave_win.x = si.x + (si.width - dzen.slave_win.width); } - dzen.line_height = dzen.font.height + 2; + if(!dzen.line_height) + dzen.line_height = dzen.font.height + 2; if (dzen.title_win.y + dzen.line_height > si.y + si.height) dzen.title_win.y = 0; @@ -693,6 +694,7 @@ main(int argc, char *argv[]) { dzen.running = True; dzen.xinescreen = 0; dzen.tsupdate = 0; + dzen.line_height = 0; /* cmdline args */ for(i = 1; i < argc; i++) @@ -747,6 +749,9 @@ main(int argc, char *argv[]) { else if(!strncmp(argv[i], "-w", 3)) { if(++i < argc) dzen.slave_win.width = atoi(argv[i]); } + else if(!strncmp(argv[i], "-h", 3)) { + if(++i < argc) dzen.line_height= atoi(argv[i]); + } else if(!strncmp(argv[i], "-tw", 4)) { if(++i < argc) dzen.title_win.width = atoi(argv[i]); } |