diff --git a/config.def.h b/config.def.h index a2ac963..4a33036 100644 --- a/config.def.h +++ b/config.def.h @@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int snap = 32; /* snap pixel */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ +static const int bartabseps = 1; /* separators between tabs? */ static const char *fonts[] = { "monospace:size=10" }; static const char dmenufont[] = "monospace:size=10"; static const char col_gray1[] = "#222222"; diff --git a/dwm.c b/dwm.c index 0fc328a..787f56f 100644 --- a/dwm.c +++ b/dwm.c @@ -380,6 +380,52 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) return *x != c->x || *y != c->y || *w != c->w || *h != c->h; } +void +bartabdraw(Monitor *m, Client *c, int unused, int x, int w) { + if (!c) + return; + + drw_setscheme(drw, scheme[m->sel == c ? SchemeSel : SchemeNorm]); + drw_text(drw, x, 0, w, bh, lrpad / 2, c->name, 0); + + if (c->isfloating) + drw_rect(drw, x + 2, 2, 5, 5, 0, 0); + + if (bartabseps) { + XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBorder].pixel); + XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, 0, 1, bh); + } +} + +void +bartabclick(Monitor *m, Client *c, int passx, int x, int w) { + if (passx >= x && passx <= x + w) { + focus(c); + restack(selmon); + } +} + +void +bartabcalc( + Monitor *m, int offx, int sw, int passx, + void(*tabfn)(Monitor *, Client *, int, int, int) +) { + Client *c; + int i = 0, n = 0, x, w; + + for (c = m->clients; c; c = c->next) + if (ISVISIBLE(c)) + n++; + for (c = m->clients; c; c = c->next) { + if (!ISVISIBLE(c)) + continue; + x = offx + (((m->mw - offx - sw) / n) * i); + w = (m->mw - offx - sw) / n; + tabfn(m, c, passx, x, w); + i++; + } +} + void arrange(Monitor *m) { @@ -444,6 +490,9 @@ buttonpress(XEvent *e) click = ClkLtSymbol; else if (ev->x > selmon->ww - (int)TEXTW(stext)) click = ClkStatusText; + /* Focus window corresponding clicked tab */ + else if (ev->button == Button1 && 0 == CLEANMASK(ev->state)) + bartabcalc(selmon, x, TEXTW(stext) - lrpad + 2, ev->x, bartabclick); else click = ClkWinTitle; } else if ((c = wintoclient(ev->window))) { @@ -735,17 +784,9 @@ drawbar(Monitor *m) drw_setscheme(drw, scheme[SchemeNorm]); x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); - if ((w = m->ww - tw - x) > bh) { - if (m->sel) { - drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); - drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); - if (m->sel->isfloating) - drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); - } else { - drw_setscheme(drw, scheme[SchemeNorm]); - drw_rect(drw, x, 0, w, bh, 1, 1); - } - } + drw_rect(drw, x, 0, m->ww - tw - x, bh, 1, 1); + if ((w = m->ww - tw - x) > bh) + bartabcalc(m, x, tw, -1, bartabdraw); drw_map(drw, m->barwin, 0, 0, m->ww, bh); }