From 317b0417b2b189fa15de3fc9542fb9c6ffe8239e Mon Sep 17 00:00:00 2001 From: gotmor Date: Fri, 30 Mar 2007 13:06:41 +0000 Subject: added '-tw' title window width option revised geometry checking git-svn-id: http://dzen.googlecode.com/svn/trunk@7 f2baff5b-bf2c-0410-a398-912abdc3d8b2 --- README | 1 + TODO | 2 +- action.c | 10 ++++----- config.mk | 2 +- draw.c | 8 ++++--- main.c | 74 +++++++++++++++++++++++++++++++++++++++++++++------------------ 6 files changed, 66 insertions(+), 31 deletions(-) diff --git a/README b/README index 43db1c0..ad36c33 100644 --- a/README +++ b/README @@ -46,6 +46,7 @@ dzen accepts a couple of options: -x x position -y y position -w width + -tw title window width -v version information Termination: diff --git a/TODO b/TODO index fc605aa..fa4b3e1 100644 --- a/TODO +++ b/TODO @@ -13,5 +13,5 @@ # user interface - o title and slave window should be allowed to have different bg/fg/font/width settings without making the command line arguments a mess + o title and slave window should be allowed to have different bg/fg/font/settings without making the command line arguments a mess o split lines longer than window width in multiple lines diff --git a/action.c b/action.c index 375efc7..a6813cc 100644 --- a/action.c +++ b/action.c @@ -143,7 +143,7 @@ static void x_draw_body(void) { dzen.x = 0; dzen.y = 0; - dzen.w = dzen.mw; + dzen.w = dzen.slave_win.width; dzen.h = dzen.mh; int i; @@ -161,14 +161,14 @@ x_draw_body(void) { for(i=0; i < dzen.slave_win.max_lines; i++) { if(i < dzen.slave_win.last_line_vis) { - drawtext(dzen.slave_win.tbuf[i + dzen.slave_win.first_line_vis], 0, i+1); + drawtext(dzen.slave_win.tbuf[i + dzen.slave_win.first_line_vis], 0, i); XCopyArea(dzen.dpy, dzen.slave_win.drawable, dzen.slave_win.line[i], dzen.gc, - 0, 0, dzen.mw, dzen.mh, 0, 0); + 0, 0, dzen.slave_win.width, dzen.mh, 0, 0); } else if(i < dzen.slave_win.max_lines) { - drawtext("", 0, i+1); + drawtext("", 0, i); XCopyArea(dzen.dpy, dzen.slave_win.drawable, dzen.slave_win.line[i], dzen.gc, - 0, 0, dzen.mw, dzen.mh, 0, 0); + 0, 0, dzen.slave_win.width, dzen.mh, 0, 0); } } pthread_mutex_unlock(&dzen.mt); diff --git a/config.mk b/config.mk index d839c08..2c98474 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # dzen version -VERSION = 0.1.9 +VERSION = 0.2.0 # Customize below to fit your system diff --git a/draw.c b/draw.c index d209d80..f753811 100644 --- a/draw.c +++ b/draw.c @@ -29,11 +29,13 @@ void drawtext(const char *text, int reverse, int line) { mgc = reverse ? dzen.gc : dzen.rgc; /* title win */ - if(line == -1) + if(line == -1) { XFillRectangles(dzen.dpy, dzen.title_win.drawable, mgc, &r, 1); + } /* slave win */ - else + else { XFillRectangles(dzen.dpy, dzen.slave_win.drawable, mgc, &r, 1); + } if(!text) return; @@ -58,7 +60,7 @@ void drawtext(const char *text, int reverse, int line) { } if(line != -1) - x = h; + x = h/2; else x = (dzen.w - textw(buf)+h)/2; y = dzen.font.ascent + (dzen.mh - h) / 2; diff --git a/main.c b/main.c index 67c48e0..0df4f5d 100644 --- a/main.c +++ b/main.c @@ -54,13 +54,13 @@ static void drawheader(char * text) { dzen.x = 0; dzen.y = 0; - dzen.w = dzen.mw; + dzen.w = dzen.title_win.width; dzen.h = dzen.mh; if(text) drawtext(text, 0, -1); XCopyArea(dzen.dpy, dzen.title_win.drawable, dzen.title_win.win, - dzen.gc, 0, 0, dzen.mw, dzen.mh, 0, 0); + dzen.gc, 0, 0, dzen.title_win.width, dzen.mh, 0, 0); } static void @@ -96,14 +96,14 @@ static void x_highlight_line(int line) { drawtext(dzen.slave_win.tbuf[line + dzen.slave_win.first_line_vis], 1, line+1); XCopyArea(dzen.dpy, dzen.slave_win.drawable, dzen.slave_win.line[line], dzen.rgc, - 0, 0, dzen.mw, dzen.mh, 0, 0); + 0, 0, dzen.slave_win.width, dzen.mh, 0, 0); } static void x_unhighlight_line(int line) { drawtext(dzen.slave_win.tbuf[line + dzen.slave_win.first_line_vis], 0, line+1); XCopyArea(dzen.dpy, dzen.slave_win.drawable, dzen.slave_win.line[line], dzen.gc, - 0, 0, dzen.mw, dzen.mh, 0, 0); + 0, 0, dzen.slave_win.width, dzen.mh, 0, 0); } static void @@ -247,20 +247,44 @@ x_create_windows(void) { /* check geometry */ - dzen.hx = dzen.hx > DisplayWidth(dzen.dpy, dzen.screen) ? 0 : dzen.hx; - dzen.mw = dzen.hw ? (dzen.hw + dzen.hx > DisplayWidth(dzen.dpy, dzen.screen) - ? (DisplayWidth(dzen.dpy, dzen.screen) - dzen.hx) : dzen.hw) - : DisplayWidth(dzen.dpy, dzen.screen); + if(dzen.title_win.x > DisplayWidth(dzen.dpy, dzen.screen)) + dzen.title_win.x = 0; + + if(!dzen.title_win.width) + dzen.title_win.width = DisplayWidth(dzen.dpy, dzen.screen); + + 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.slave_win.width) { + dzen.slave_win.x = 0; + dzen.slave_win.width = DisplayWidth(dzen.dpy, dzen.screen); + } + 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)) { + dzen.slave_win.x = dzen.title_win.x + dzen.title_win.width/2 - 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; + } dzen.mh = dzen.font.height + 2; dzen.hy = (dzen.hy + dzen.mh) > DisplayHeight(dzen.dpy, dzen.screen) ? 0 : dzen.hy; + /* title window */ dzen.title_win.win = XCreateWindow(dzen.dpy, root, - dzen.hx, dzen.hy, dzen.mw, dzen.mh, 0, + dzen.title_win.x, dzen.hy, dzen.title_win.width, dzen.mh, 0, DefaultDepth(dzen.dpy, dzen.screen), CopyFromParent, DefaultVisual(dzen.dpy, dzen.screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); - dzen.title_win.drawable = XCreatePixmap(dzen.dpy, root, dzen.mw, dzen.mh, DefaultDepth(dzen.dpy, dzen.screen)); + dzen.title_win.drawable = XCreatePixmap(dzen.dpy, root, dzen.title_win.width, + dzen.mh, DefaultDepth(dzen.dpy, dzen.screen)); /* slave window */ if(dzen.slave_win.max_lines) { @@ -272,19 +296,19 @@ x_create_windows(void) { dzen.hy = (dzen.hy - dzen.mh) - dzen.mh*(dzen.slave_win.max_lines); dzen.slave_win.win = XCreateWindow(dzen.dpy, root, - dzen.hx, dzen.hy+dzen.mh, dzen.mw, dzen.slave_win.max_lines * dzen.mh, 0, + dzen.slave_win.x, dzen.hy+dzen.mh, dzen.slave_win.width, dzen.slave_win.max_lines * dzen.mh, 0, DefaultDepth(dzen.dpy, dzen.screen), CopyFromParent, DefaultVisual(dzen.dpy, dzen.screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); - dzen.slave_win.drawable = XCreatePixmap(dzen.dpy, root, dzen.mw, + dzen.slave_win.drawable = XCreatePixmap(dzen.dpy, root, dzen.slave_win.width, dzen.mh, DefaultDepth(dzen.dpy, dzen.screen)); /* windows holding the lines */ dzen.slave_win.line = emalloc(sizeof(Window) * dzen.slave_win.max_lines); for(i=0; i < dzen.slave_win.max_lines; i++) { dzen.slave_win.line[i] = XCreateWindow(dzen.dpy, dzen.slave_win.win, - 0, i*dzen.mh, dzen.mw, dzen.mh, 0, + 0, i*dzen.mh, dzen.slave_win.width, dzen.mh, 0, DefaultDepth(dzen.dpy, dzen.screen), CopyFromParent, DefaultVisual(dzen.dpy, dzen.screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); @@ -315,9 +339,9 @@ main(int argc, char *argv[]) { /* default values */ dzen.cur_line = 0; dzen.ret_val = 0; - dzen.hx = 0; dzen.hy = 0; - dzen.hw = 0; + dzen.title_win.x = dzen.slave_win.x = 0; + dzen.title_win.width = dzen.slave_win.width = 0; dzen.fnt = FONT; dzen.bg = BGCOLOR; dzen.fg = FGCOLOR; @@ -353,20 +377,28 @@ main(int argc, char *argv[]) { if(++i < argc) dzen.fg = argv[i]; } else if(!strncmp(argv[i], "-x", 3)) { - if(++i < argc) dzen.hx = atoi(argv[i]); + if(++i < argc) dzen.title_win.x = dzen.slave_win.x = atoi(argv[i]); + //if(++i < argc) dzen.hx = atoi(argv[i]); } else if(!strncmp(argv[i], "-y", 3)) { if(++i < argc) dzen.hy = atoi(argv[i]); } else if(!strncmp(argv[i], "-w", 3)) { - if(++i < argc) dzen.hw = atoi(argv[i]); + if(++i < argc) dzen.slave_win.width = atoi(argv[i]); + //if(++i < argc) dzen.hw = atoi(argv[i]); + } + else if(!strncmp(argv[i], "-tw", 3)) { + if(++i < argc) dzen.title_win.width = atoi(argv[i]); } else if(!strncmp(argv[i], "-v", 3)) eprint("dzen-"VERSION", (C)opyright 2007 Robert Manea\n"); else - eprint("usage: dzen [-v] [-p] [-a] [-m] [-x ] [-y ] [-w ]\n" - " [-l ] [-fn ] [-bg ] [-fg ]\n" - " [-e ]\n"); + eprint("usage: dzen [-v] [-p] [-a] [-m] [-e ] \n" + " [-x ] [-y ] [-w ] [-tw ]\n" + " [-l ] [-fn ] [-bg ] [-fg ]\n"); + + if(dzen.title_win.width == 0) + dzen.title_win.width = dzen.slave_win.width; if(!XInitThreads()) eprint("dzen: no multithreading support in xlib.\n"); @@ -397,7 +429,7 @@ main(int argc, char *argv[]) { /* autohiding */ if(dzen.title_win.autohide) { - x_resize_header(dzen.mw, 1); + x_resize_header(dzen.title_win.width, 1); dzen.title_win.ishidden = True; } -- cgit v1.2.3-54-g00ecf