From 0e812d4eef48a6e355a5c39c3a7c52a3723c0f1e Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sun, 12 Oct 2008 06:01:42 +0200 Subject: [PATCH] [bar] Improve a lot the bar stuff (taglist, layout symbol, barbutton... --- bar.c | 128 ++++++++++++++++++++++++++++++++++---------------------- event.c | 47 +++++++++------------ util.c | 16 +++---- wmfs.c | 4 +- wmfs.h | 7 +++- 5 files changed, 115 insertions(+), 87 deletions(-) diff --git a/bar.c b/bar.c index 5c254bd..a6a6ad4 100644 --- a/bar.c +++ b/bar.c @@ -75,7 +75,13 @@ bar_moveresize(BarWindow *bw, int x, int y, uint w, uint h) bw->dr = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen)); bw->w = w; bw->h = h; } - bw->x = x; bw->y = y; + + if(x != bw->x || y != bw->y) + { + bw->x = x; + bw->y = y; + } + XMoveResizeWindow(dpy, bw->win, x, y, w, h); return; @@ -98,48 +104,76 @@ bar_refresh(BarWindow *bw) return; } +void +draw_taglist(Drawable dr) +{ + int i; + char buf[conf.ntag][256]; + char p[4]; + taglen[0] = PAD/2; + + for(i = 0; i < conf.ntag; ++i) + { + /* Make the tags string */ + ITOA(p, clientpertag(i+1)); + sprintf(buf[i], "%s<%s>", tags[i+1].name, (clientpertag(i+1)) ? p : ""); + + /* Draw the string */ + xprint(dr, taglen[i], fonth, + ((i+1 == seltag) ? conf.colors.tagselfg : conf.colors.text), + ((i+1 == seltag) ? conf.colors.tagselbg : conf.colors.bar), PAD, buf[i]); + + /* Draw the tag border */ + XSetForeground(dpy, gc, conf.colors.tagbord); + XFillRectangle(dpy, dr, gc, + taglen[i] + textw(buf[i]) + PAD/2, + 0, conf.tagbordwidth, barheight); + + /* Edit taglen[i+1] for the next time */ + taglen[i+1] = taglen[i] + textw(buf[i]) + PAD + conf.tagbordwidth; + } + + return; +} + +void +draw_layoutsym(int x, int y) +{ + + if(!layoutsym) + { + layoutsym = bar_create(x, y, + textw(tags[seltag].layout.symbol) + BPAD, + barheight, 0, conf.colors.layout_bg); + XMapRaised(dpy, layoutsym->win); + } + + bar_refresh_color(layoutsym); + bar_moveresize(layoutsym, x, y, textw(tags[seltag].layout.symbol) + BPAD, barheight); + + xprint(layoutsym->dr, BPAD/2, fonth, conf.colors.layout_fg, + conf.colors.layout_bg, BPAD, tags[seltag].layout.symbol); + + bar_refresh(layoutsym); + + return; +} + /* Top/Bottom Bar Manage Function */ void updatebar(void) { - int i , k, sp = 6; - char buf[conf.ntag][256]; - char p[4]; - + /* Refresh bar color */ bar_refresh_color(bar); - /* TAGLIST */ - { - for(i = 0; i < conf.ntag; ++i) - { - /* Make the tags string */ - ITOA(p, clientpertag(i+1)); - sprintf(buf[i], "%s<%s>", tags[i+1].name, (clientpertag(i+1)) ? p : ""); - taglen[i+1] = taglen[i] + textw(buf[i]) + sp; + /* Draw taglist */ + draw_taglist(bar->dr); - /* Draw tags */ - xprint(bar->dr, taglen[i], fonth, - ((i+1 == seltag) ? conf.colors.tagselfg : conf.colors.text), - ((i+1 == seltag) ? conf.colors.tagselbg : conf.colors.bar), sp-1, -sp, buf[i]); - - /* Tags border separation */ - XSetForeground(dpy, gc, conf.colors.tagbord); - if(i > 0) - XFillRectangle(dpy, bar->dr, gc, taglen[i]-sp+1, 0, conf.tagbordwidth, barheight); - } - XFillRectangle(dpy, bar->dr, gc, taglen[conf.ntag]-sp+1, 0, conf.tagbordwidth, barheight); - } - - /* Layout symbol */ - { - xprint(bar->dr, taglen[conf.ntag] - sp/3, fonth, - conf.colors.layout_fg, conf.colors.layout_bg, - 0, 0, tags[seltag].layout.symbol); - } + /* Draw layout symbol */ + draw_layoutsym(taglen[conf.ntag], bary); /* Draw status text */ - k = textw(bartext); - xprint(bar->dr, mw-k, fonth, conf.colors.text, conf.colors.bar, 0, 0, bartext); + xprint(bar->dr, mw - textw(bartext), fonth, conf.colors.text, conf.colors.bar, 0, bartext); /* Bar border */ if(conf.tagbordwidth) @@ -147,11 +181,11 @@ updatebar(void) XSetForeground(dpy, gc, conf.colors.tagbord); XFillRectangle(dpy, bar->dr, gc, 0, ((conf.bartop) ? barheight-1: 0), mw, 1); - XFillRectangle(dpy, bar->dr, gc, mw-k-5, 0, 1, barheight); + XFillRectangle(dpy, bar->dr, gc, mw - textw(bartext) - 5, 0, 1, barheight); } + /* Refresh the bar */ bar_refresh(bar); - XSync(dpy, False); /* Update Bar Buttons */ updatebutton(True); @@ -167,13 +201,8 @@ updatebutton(Bool c) { int i, j, x, pm = 0; int y = 0, hi = 0; - XSetWindowAttributes at; - at.override_redirect = 1; - at.background_pixmap = ParentRelative; - at.event_mask = ButtonPressMask | ExposureMask; - - j = taglen[conf.ntag] + textw(tags[seltag].layout.symbol) + xftfont->ascent; + j = taglen[conf.ntag] + textw(tags[seltag].layout.symbol) + PAD; if(!conf.bartop) y = bary + 1; @@ -186,16 +215,15 @@ updatebutton(Bool c) if(!(x = conf.barbutton[i].x)) { if(i) - pm += textw(conf.barbutton[i-1].text); + pm += textw(conf.barbutton[i-1].text) + BPAD; x = (!i) ? j : j + pm; } if(!c) { - conf.barbutton[i].bw = bar_create(x, y, - textw(conf.barbutton[i].text), - barheight + hi, - 0, conf.barbutton[i].bg_color); + conf.barbutton[i].bw = bar_create(x, y, textw(conf.barbutton[i].text) + BPAD, + barheight + hi, 0, + conf.barbutton[i].bg_color); XMapRaised(dpy, conf.barbutton[i].bw->win); } @@ -203,9 +231,9 @@ updatebutton(Bool c) return; bar_refresh_color(conf.barbutton[i].bw); - bar_moveresize(conf.barbutton[i].bw, x, y, textw(conf.barbutton[i].text), barheight + hi); - xprint(conf.barbutton[i].bw->dr, 1, fonth, conf.barbutton[i].fg_color, - conf.barbutton[i].bg_color, 0, 0, conf.barbutton[i].text); + bar_moveresize(conf.barbutton[i].bw, x, y, textw(conf.barbutton[i].text) + BPAD, barheight + hi); + xprint(conf.barbutton[i].bw->dr, BPAD/2, fonth, conf.barbutton[i].fg_color, + conf.barbutton[i].bg_color, BPAD, conf.barbutton[i].text); bar_refresh(conf.barbutton[i].bw); } XSync(dpy, False); diff --git a/event.c b/event.c index 79ebee3..adc2810 100644 --- a/event.c +++ b/event.c @@ -189,34 +189,27 @@ buttonpress(XEvent ev) } - - /* ****** */ - /* LAYOUT */ - /* ****** */ - { - - if(ev.xbutton.x >= taglen[conf.ntag] - 3 - && ev.xbutton.x < taglen[conf.ntag] + - textw(tags[seltag].layout.symbol) - 3) - { - /* BUTTON 1 / 4 */ - { - if(ev.xbutton.button == Button1 - || ev.xbutton.button == Button4) - layoutswitch(True); - } - /* BUTTON 3 / 5 */ - { - if(ev.xbutton.button == Button3 - || ev.xbutton.button == Button5) - layoutswitch(False); - } - } - - } - - } + + /* ****** */ + /* LAYOUT */ + /* ****** */ + else if(ev.xbutton.window == layoutsym->win) + { + /* BUTTON 1 / 4 */ + { + if(ev.xbutton.button == Button1 + || ev.xbutton.button == Button4) + layoutswitch(True); + } + /* BUTTON 3 / 5 */ + { + if(ev.xbutton.button == Button3 + || ev.xbutton.button == Button5) + layoutswitch(False); + } + } + } /* **** */ diff --git a/util.c b/util.c index db22434..7770f38 100644 --- a/util.c +++ b/util.c @@ -89,7 +89,7 @@ textw(const char *text) } void -xprint(Drawable d, int x, int y, char* fg, uint bg, int decx, int decw, char *str) +xprint(Drawable d, int x, int y, char* fg, uint bg, int pad, char *str) { XftColor xftcolor; XftDraw *xftd; @@ -99,14 +99,16 @@ xprint(Drawable d, int x, int y, char* fg, uint bg, int decx, int decw, char *st /* Color the text font */ XSetForeground(dpy, gc, bg); - XFillRectangle(dpy, d, gc, x - decx, 0, textw(str) - decw, barheight); + XFillRectangle(dpy, d, gc, x - pad/2, 0, textw(str) + pad, barheight); - /* Alloc text color and draw */ - XftColorAllocName(dpy, - DefaultVisual(dpy, screen), - DefaultColormap(dpy, screen), - fg, &xftcolor); + /* Alloc text color */ + XftColorAllocName(dpy, DefaultVisual(dpy, screen), + DefaultColormap(dpy, screen), fg, &xftcolor); + + /* Draw the text */ XftDrawStringUtf8(xftd, &xftcolor, xftfont, x, y, (FcChar8 *)str, strlen(str)); + + /* Free the text color */ XftColorFree(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), &xftcolor); return; diff --git a/wmfs.c b/wmfs.c index 6c78b56..6ede3da 100644 --- a/wmfs.c +++ b/wmfs.c @@ -199,6 +199,7 @@ focus(Client *c) for(cc = clients; cc; cc = cc->next) if(!ishide(cc)) updatetitle(cc); + return; } @@ -348,7 +349,6 @@ init(void) mh = DisplayHeight (dpy, screen); /* INIT TAG / LAYOUT ATTRIBUTE */ - taglen[0] = 3; seltag = 1; for(i = 0; i < conf.ntag + 1; ++i) tags[i] = conf.tag[i - 1]; @@ -934,7 +934,7 @@ updatetitle(Client *c) bar_refresh_color(c->tbar); xprint(c->tbar->dr, 3, ((fonth - xftfont->descent) + ((conf.ttbarheight - fonth) / 2)), ((c == sel) ? conf.colors.ttbar_text_focus : conf.colors.ttbar_text_normal), - conf.colors.bar, 0, 0, c->title); + conf.colors.bar, 0, c->title); bar_refresh(c->tbar); } diff --git a/wmfs.h b/wmfs.h index 39c58b8..da992bb 100644 --- a/wmfs.h +++ b/wmfs.h @@ -66,6 +66,8 @@ #define BUTH conf.ttbarheight - 6 #define BUTX(x, w) x + w - BUTH/400 #define MAXLAYOUT 3 +#define PAD 8 +#define BPAD 2 /* Client Structure & Typedef */ typedef const char* uicb_t; @@ -219,6 +221,8 @@ void bar_delete(BarWindow *bw); void bar_moveresize(BarWindow *bw, int x, int y, uint w, uint h); void bar_refresh_color(BarWindow *bw); void bar_refresh(BarWindow *bw); +void draw_taglist(Drawable dr); +void draw_layoutsym(int x, int y); void updatebar(void); void updatebutton(Bool c); @@ -245,7 +249,7 @@ ulong getcolor(char *color); ushort textw(const char *text); void xprint(Drawable d, int x, int y, char* fg, uint bg, - int decx, int decw, char* str); + int pad, char* str); void uicb_spawn(uicb_t); /* tag.c */ @@ -330,6 +334,7 @@ XftFont *xftfont; /* Bar / Tags */ BarWindow *bar; +BarWindow *layoutsym; Tag tags[MAXTAG]; int barheight; char bartext[1024];