diff --git a/config.def.h b/config.def.h index 77ff358..ea9758d 100644 --- a/config.def.h +++ b/config.def.h @@ -12,6 +12,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int snap = 32; /* snap pixel */ static const Bool showbar = True; /* False means no bar */ static const Bool topbar = True; /* False means bottom bar */ +static const Bool extrabar = True; /* False means no extra bar */ /* tagging */ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; @@ -54,6 +55,7 @@ static Key keys[] = { { MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, { MODKEY, XK_b, togglebar, {0} }, + { MODKEY, XK_b, toggleextrabar, {0} }, { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, { MODKEY, XK_i, incnmaster, {.i = +1 } }, diff --git a/dwm.c b/dwm.c index 1d78655..b322ff5 100644 --- a/dwm.c +++ b/dwm.c @@ -154,6 +154,13 @@ typedef struct { int monitor; } Rule; +typedef struct { + int y; + Bool show; + Window win; + char text[256]; +} Bar; + /* function declarations */ static void applyrules(Client *c); static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact); @@ -229,6 +236,7 @@ static void tagmon(const Arg *arg); static int textnw(const char *text, unsigned int len); static void tile(Monitor *); static void togglebar(const Arg *arg); +static void toggleextrabar(const Arg *arg); static void togglefloating(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); @@ -283,6 +291,7 @@ static Display *dpy; static DC dc; static Monitor *mons = NULL, *selmon = NULL; static Window root; +static Bar eb; /* configuration, allows nested code to access above variables */ #include "config.h" @@ -495,6 +504,8 @@ cleanup(void) { XFreeCursor(dpy, cursor[CurNormal]); XFreeCursor(dpy, cursor[CurResize]); XFreeCursor(dpy, cursor[CurMove]); + XUnmapWindow(dpy, eb.win); + XDestroyWindow(dpy, eb.win); while(mons) cleanupmon(mons); XSync(dpy, False); @@ -584,6 +595,7 @@ configurenotify(XEvent *e) { updatebars(); for(m = mons; m; m = m->next) XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh); + XMoveResizeWindow(dpy, eb.win, mons->wx, eb.y, mons->ww, bh); focus(NULL); arrange(NULL); } @@ -762,6 +774,10 @@ drawbar(Monitor *m) { drawtext(NULL, dc.norm, False); } XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0); + dc.x = 0; + dc.w = m->ww; + drawtext(eb.text, dc.norm, False); + XCopyArea(dpy, dc.drawable, eb.win, dc.gc, 0, 0, m->ww, bh, 0, 0); XSync(dpy, False); } @@ -1594,6 +1610,7 @@ setup(void) { sw = DisplayWidth(dpy, screen); sh = DisplayHeight(dpy, screen); bh = dc.h = dc.font.height + 2; + eb.show = extrabar; updategeom(); /* init atoms */ wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); @@ -1736,6 +1753,16 @@ togglebar(const Arg *arg) { } void +toggleextrabar(const Arg *arg) { + if(selmon == mons) { + eb.show = !eb.show; + updatebarpos(selmon); + XMoveResizeWindow(dpy, eb.win, selmon->wx, eb.y, selmon->ww, bh); + arrange(selmon); + } +} + +void togglefloating(const Arg *arg) { if(!selmon->sel) return; @@ -1833,6 +1860,13 @@ updatebars(void) { XDefineCursor(dpy, m->barwin, cursor[CurNormal]); XMapRaised(dpy, m->barwin); } + if(!eb.win) { + eb.win = XCreateWindow(dpy, root, mons->wx, eb.y, mons->ww, bh, 0, DefaultDepth(dpy, screen), + CopyFromParent, DefaultVisual(dpy, screen), + CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); + XDefineCursor(dpy, eb.win, cursor[CurNormal]); + XMapRaised(dpy, eb.win); + } } void @@ -1846,6 +1880,13 @@ updatebarpos(Monitor *m) { } else m->by = -bh; + if(m == mons && eb.show) { + m->wh -= bh; + eb.y = topbar ? m->wy + m->wh : m->wy; + m->wy = m->topbar ? m->wy : m->wy + bh; + } + else + eb.y = -bh; } Bool @@ -2005,8 +2046,21 @@ updatetitle(Client *c) { void updatestatus(void) { - if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) + char text[512]; + if(!gettextprop(root, XA_WM_NAME, text, sizeof(text))) { strcpy(stext, "dwm-"VERSION); + eb.text[0] = '\0'; + } + else { + char *e = strchr(text, ';'); + if(e) { + *e = '\0'; e++; + strncpy(eb.text, e, sizeof(eb.text)-1); + } + else + eb.text[0] = '\0'; + strncpy(stext, text, sizeof(stext)-1); + } drawbar(selmon); }