aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README4
-rw-r--r--draw.c14
-rw-r--r--dzen.h11
-rw-r--r--main.c30
4 files changed, 46 insertions, 13 deletions
diff --git a/README b/README
index 515f50a..3098e4f 100644
--- a/README
+++ b/README
@@ -46,6 +46,8 @@ dzen accepts a couple of options:
-fg foreground color
-bg background color
-fn font
+ -ta alignement of title window content
+ l(eft), c(center), r(right)
-a autohide, see 1)
-l lines, see 2)
-e events and actions, see 3)
@@ -243,7 +245,7 @@ Examples:
* Dzen as xmonad (see http://xmonad.org) statusbar:
- status.sh | dzen2 -fn '-*-profont-*-*-*-*-11-*-*-*-*-*-iso8859' -bg '#aecf96' -fg black \
+ status.sh | dzen2 -ta r -fn '-*-profont-*-*-*-*-11-*-*-*-*-*-iso8859' -bg '#aecf96' -fg black \
-p -e 'sigusr1=raise;sigusr2=lower;onquit=exec:rm /tmp/dzen2-pid;button3=exit' & echo $! > /tmp/dzen2-pid
diff --git a/draw.c b/draw.c
index 7360b23..bfc018c 100644
--- a/draw.c
+++ b/draw.c
@@ -18,7 +18,7 @@ textnw(const char *text, unsigned int len) {
return XTextWidth(dzen.font.xfont, text, len);
}
-void drawtext(const char *text, int reverse, int line) {
+void drawtext(const char *text, int reverse, int line, int aligne) {
int x, y, w, h;
static char buf[1024];
unsigned int len, olen;
@@ -61,8 +61,14 @@ void drawtext(const char *text, int reverse, int line) {
if(line != -1)
x = h/2;
- else
- x = (dzen.w - textw(buf)+h)/2;
+ else {
+ if(!aligne)
+ x = (dzen.w - textw(buf)+h)/2;
+ else if(aligne == ALIGNELEFT)
+ x = h/2;
+ else
+ x = (dzen.title_win.width - h/2) - textw(buf);
+ }
y = dzen.font.ascent + (dzen.mh - h) / 2;
mgc = reverse ? dzen.rgc : dzen.gc;
@@ -148,7 +154,7 @@ drawheader(char * text) {
dzen.h = dzen.mh;
if(text)
- drawtext(text, 0, -1);
+ drawtext(text, 0, -1, dzen.title_win.alignement);
XCopyArea(dzen.dpy, dzen.title_win.drawable, dzen.title_win.win,
dzen.gc, 0, 0, dzen.title_win.width, dzen.mh, 0, 0);
}
diff --git a/dzen.h b/dzen.h
index e9ea535..fc49cdc 100644
--- a/dzen.h
+++ b/dzen.h
@@ -12,8 +12,11 @@
#define BGCOLOR "#ab0b0b"
#define FGCOLOR "#efefef"
-//#define BUF_SIZE 4096
-#define BUF_SIZE 1024
+#define ALIGNECENTER 0
+#define ALIGNELEFT 1
+#define ALIGNERIGHT 2
+
+#define BUF_SIZE 4096
/* gui data structures */
enum { ColFG, ColBG, ColLast };
@@ -41,6 +44,7 @@ struct TW {
Window win;
Drawable drawable;
+ char alignement;
Bool autohide;
Bool ishidden;
};
@@ -112,7 +116,8 @@ void x_draw_body(void);
/* draw.c */
extern void drawtext(const char *text,
int reverse,
- int line);
+ int line,
+ int aligne);
extern unsigned long getcolor(const char *colstr); /* returns color of colstr */
extern void setfont(const char *fontstr); /* sets global font */
extern unsigned int textw(const char *text); /* returns width of text in px */
diff --git a/main.c b/main.c
index 7a00647..f32422b 100644
--- a/main.c
+++ b/main.c
@@ -101,14 +101,14 @@ x_resize_header(int width, int height) {
static void
x_highlight_line(int line) {
- drawtext(dzen.slave_win.tbuf[line + dzen.slave_win.first_line_vis], 1, line+1);
+ drawtext(dzen.slave_win.tbuf[line + dzen.slave_win.first_line_vis], 1, line+1, ALIGNELEFT);
XCopyArea(dzen.dpy, dzen.slave_win.drawable, dzen.slave_win.line[line], dzen.rgc,
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);
+ drawtext(dzen.slave_win.tbuf[line + dzen.slave_win.first_line_vis], 0, line+1, ALIGNELEFT);
XCopyArea(dzen.dpy, dzen.slave_win.drawable, dzen.slave_win.line[line], dzen.gc,
0, 0, dzen.slave_win.width, dzen.mh, 0, 0);
}
@@ -135,12 +135,12 @@ 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);
+ drawtext(dzen.slave_win.tbuf[i + dzen.slave_win.first_line_vis], 0, i, ALIGNELEFT);
XCopyArea(dzen.dpy, dzen.slave_win.drawable, dzen.slave_win.line[i], dzen.gc,
0, 0, dzen.slave_win.width, dzen.mh, 0, 0);
}
else if(i < dzen.slave_win.max_lines) {
- drawtext("", 0, i);
+ drawtext("", 0, i, ALIGNELEFT);
XCopyArea(dzen.dpy, dzen.slave_win.drawable, dzen.slave_win.line[i], dzen.gc,
0, 0, dzen.slave_win.width, dzen.mh, 0, 0);
}
@@ -379,6 +379,7 @@ main(int argc, char *argv[]) {
dzen.cur_line = 0;
dzen.ret_val = 0;
dzen.hy = 0;
+ dzen.title_win.alignement = ALIGNECENTER;
dzen.title_win.x = dzen.slave_win.x = 0;
dzen.title_win.width = dzen.slave_win.width = 0;
dzen.fnt = FONT;
@@ -400,6 +401,9 @@ main(int argc, char *argv[]) {
else if(!strncmp(argv[i], "-a", 3)) {
dzen.title_win.autohide = True;
}
+ else if(!strncmp(argv[i], "-ta", 4)) {
+ ++i; dzen.title_win.alignement = argv[i][0];
+ }
else if(!strncmp(argv[i], "-m", 3)) {
dzen.slave_win.ismenu = True;
}
@@ -430,7 +434,7 @@ main(int argc, char *argv[]) {
else if(!strncmp(argv[i], "-v", 3))
eprint("dzen-"VERSION", (C)opyright 2007 Robert Manea\n");
else
- eprint("usage: dzen [-v] [-p] [-a] [-m] [-e <string>] \n"
+ eprint("usage: dzen [-v] [-p] [-a] [-m] [-ta <l|c|r>] [-e <string>] \n"
" [-x <pixel>] [-y <pixel>] [-w <pixel>] [-tw <pixel>]\n"
" [-l <lines>] [-fn <font>] [-bg <color>] [-fg <color>]\n");
@@ -461,6 +465,22 @@ main(int argc, char *argv[]) {
if(ev_table[sigusr2].isset && (setup_signal(SIGUSR2, catch_sigusr2) == SIG_ERR))
fprintf(stderr, "dzen: error hooking SIGUSR2\n");
+ if(dzen.title_win.alignement) {
+ switch(dzen.title_win.alignement) {
+ case 'l':
+ dzen.title_win.alignement = ALIGNELEFT;
+ break;
+ case 'c':
+ dzen.title_win.alignement = ALIGNECENTER;
+ break;
+ case 'r':
+ dzen.title_win.alignement = ALIGNERIGHT;
+ break;
+ defualt:
+ dzen.title_win.alignement = ALIGNECENTER;
+ }
+ }
+
x_create_windows();
x_map_window(dzen.title_win.win);