implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
9cd686c9
6 file(s) · +95 −31
| 3 | 3 | ||
| 4 | 4 | include config.mk |
|
| 5 | 5 | ||
| 6 | - | SRC = client.c dev.c draw.c event.c main.c util.c |
|
| 6 | + | SRC = bar.c client.c dev.c draw.c event.c main.c util.c |
|
| 7 | 7 | OBJ = ${SRC:.c=.o} |
|
| 8 | 8 | MAN1 = dwm.1 |
|
| 9 | 9 | BIN = dwm |
| 1 | + | /* |
|
| 2 | + | * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> |
|
| 3 | + | * See LICENSE file for license details. |
|
| 4 | + | */ |
|
| 5 | + | ||
| 6 | + | #include "dwm.h" |
|
| 7 | + | ||
| 8 | + | void |
|
| 9 | + | draw_bar() |
|
| 10 | + | { |
|
| 11 | + | int i; |
|
| 12 | + | dc.x = dc.y = 0; |
|
| 13 | + | dc.w = bw; |
|
| 14 | + | drawtext(NULL, False); |
|
| 15 | + | ||
| 16 | + | dc.w = 0; |
|
| 17 | + | for(i = 0; i < TLast; i++) { |
|
| 18 | + | dc.x += dc.w; |
|
| 19 | + | dc.w = textw(tags[i]) + dc.font.height; |
|
| 20 | + | if(i == tsel) { |
|
| 21 | + | swap((void **)&dc.fg, (void **)&dc.bg); |
|
| 22 | + | drawtext(tags[i], True); |
|
| 23 | + | swap((void **)&dc.fg, (void **)&dc.bg); |
|
| 24 | + | } |
|
| 25 | + | else |
|
| 26 | + | drawtext(tags[i], True); |
|
| 27 | + | } |
|
| 28 | + | if(sel) { |
|
| 29 | + | swap((void **)&dc.fg, (void **)&dc.bg); |
|
| 30 | + | dc.x += dc.w; |
|
| 31 | + | dc.w = textw(sel->name) + dc.font.height; |
|
| 32 | + | drawtext(sel->name, True); |
|
| 33 | + | swap((void **)&dc.fg, (void **)&dc.bg); |
|
| 34 | + | } |
|
| 35 | + | dc.w = textw(stext) + dc.font.height; |
|
| 36 | + | dc.x = bx + bw - dc.w; |
|
| 37 | + | drawtext(stext, False); |
|
| 38 | + | XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0); |
|
| 39 | + | XFlush(dpy); |
|
| 40 | + | } |
| 49 | 49 | if(!sel) |
|
| 50 | 50 | return; |
|
| 51 | 51 | sel->x = sx; |
|
| 52 | - | sel->y = sy; |
|
| 52 | + | sel->y = sy + bh; |
|
| 53 | 53 | sel->w = sw - 2 * sel->border; |
|
| 54 | - | sel->h = sh - 2 * sel->border; |
|
| 54 | + | sel->h = sh - 2 * sel->border - bh; |
|
| 55 | 55 | craise(sel); |
|
| 56 | 56 | resize(sel, False); |
|
| 57 | 57 | discard_events(EnterWindowMask); |
|
| 67 | 67 | ||
| 68 | 68 | for(c = clients; c; c = next(c->next)) |
|
| 69 | 69 | draw_client(c); |
|
| 70 | + | draw_bar(); |
|
| 70 | 71 | } |
|
| 71 | 72 | ||
| 72 | 73 | void |
|
| 131 | 132 | if(c->tags[tsel] && !c->floating) |
|
| 132 | 133 | n++; |
|
| 133 | 134 | ||
| 134 | - | h = (n > 1) ? sh / (n - 1) : sh; |
|
| 135 | + | if(n > 1) |
|
| 136 | + | h = (sh - bh) / (n - 1); |
|
| 137 | + | else |
|
| 138 | + | h = sh - bh; |
|
| 135 | 139 | ||
| 136 | 140 | for(i = 0, c = clients; c; c = c->next) { |
|
| 137 | 141 | if(c->tags[tsel]) { |
|
| 142 | 146 | } |
|
| 143 | 147 | if(n == 1) { |
|
| 144 | 148 | c->x = sx; |
|
| 145 | - | c->y = sy; |
|
| 149 | + | c->y = sy + bh; |
|
| 146 | 150 | c->w = sw - 2 * c->border; |
|
| 147 | - | c->h = sh - 2 * c->border; |
|
| 151 | + | c->h = sh - 2 * c->border - bh; |
|
| 148 | 152 | } |
|
| 149 | 153 | else if(i == 0) { |
|
| 150 | 154 | c->x = sx; |
|
| 151 | - | c->y = sy; |
|
| 155 | + | c->y = sy + bh; |
|
| 152 | 156 | c->w = mw - 2 * c->border; |
|
| 153 | - | c->h = sh - 2 * c->border; |
|
| 157 | + | c->h = sh - 2 * c->border - bh; |
|
| 154 | 158 | } |
|
| 155 | 159 | else { |
|
| 156 | 160 | c->x = sx + mw; |
|
| 157 | - | c->y = sy + (i - 1) * h; |
|
| 161 | + | c->y = sy + (i - 1) * h + bh; |
|
| 158 | 162 | c->w = w - 2 * c->border; |
|
| 159 | 163 | c->h = h - 2 * c->border; |
|
| 160 | 164 | } |
|
| 373 | 377 | c->win = w; |
|
| 374 | 378 | c->tx = c->x = wa->x; |
|
| 375 | 379 | c->ty = c->y = wa->y; |
|
| 380 | + | if(c->y < bh) |
|
| 381 | + | c->ty = c->y += bh; |
|
| 376 | 382 | c->tw = c->w = wa->width; |
|
| 377 | 383 | c->h = wa->height; |
|
| 378 | - | c->th = th; |
|
| 384 | + | c->th = bh; |
|
| 379 | 385 | c->border = 1; |
|
| 380 | 386 | c->proto = win_proto(c->win); |
|
| 381 | 387 | update_size(c); |
|
| 570 | 576 | { |
|
| 571 | 577 | int i; |
|
| 572 | 578 | if(c == sel) { |
|
| 579 | + | draw_bar(); |
|
| 573 | 580 | XUnmapWindow(dpy, c->title); |
|
| 574 | 581 | XSetWindowBorder(dpy, c->win, dc.fg); |
|
| 575 | 582 | return; |
|
| 579 | 586 | XMapWindow(dpy, c->title); |
|
| 580 | 587 | ||
| 581 | 588 | dc.x = dc.y = 0; |
|
| 582 | - | dc.h = c->th; |
|
| 583 | 589 | ||
| 584 | 590 | dc.w = 0; |
|
| 585 | 591 | for(i = 0; i < TLast; i++) { |
|
| 586 | 592 | if(c->tags[i]) { |
|
| 587 | 593 | dc.x += dc.w; |
|
| 588 | 594 | dc.w = textw(c->tags[i]) + dc.font.height; |
|
| 589 | - | draw(True, c->tags[i]); |
|
| 595 | + | drawtext(c->tags[i], True); |
|
| 590 | 596 | } |
|
| 591 | 597 | } |
|
| 592 | 598 | dc.x += dc.w; |
|
| 593 | 599 | dc.w = textw(c->name) + dc.font.height; |
|
| 594 | - | draw(True, c->name); |
|
| 600 | + | drawtext(c->name, True); |
|
| 595 | 601 | XCopyArea(dpy, dc.drawable, c->title, dc.gc, |
|
| 596 | 602 | 0, 0, c->tw, c->th, 0, 0); |
|
| 597 | 603 | XFlush(dpy); |
|
| 30 | 30 | } |
|
| 31 | 31 | ||
| 32 | 32 | void |
|
| 33 | - | draw(Bool border, const char *text) |
|
| 33 | + | drawtext(const char *text, Bool border) |
|
| 34 | 34 | { |
|
| 35 | 35 | int x, y, w, h; |
|
| 36 | 36 | unsigned int len; |
| 88 | 88 | }; |
|
| 89 | 89 | ||
| 90 | 90 | extern Display *dpy; |
|
| 91 | - | extern Window root; |
|
| 91 | + | extern Window root, barwin; |
|
| 92 | 92 | extern Atom wm_atom[WMLast], net_atom[NetLast]; |
|
| 93 | 93 | extern Cursor cursor[CurLast]; |
|
| 94 | 94 | extern Bool running, issel; |
|
| 95 | 95 | extern void (*handler[LASTEvent])(XEvent *); |
|
| 96 | 96 | extern void (*arrange)(Arg *); |
|
| 97 | 97 | ||
| 98 | - | extern int tsel, screen, sx, sy, sw, sh, mw, th; |
|
| 99 | - | extern char *tags[TLast]; |
|
| 98 | + | extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw; |
|
| 99 | + | extern char *tags[TLast], stext[1024]; |
|
| 100 | 100 | ||
| 101 | 101 | extern DC dc; |
|
| 102 | 102 | extern Client *clients, *sel; |
|
| 103 | + | ||
| 104 | + | /* bar.c */ |
|
| 105 | + | extern void draw_bar(); |
|
| 103 | 106 | ||
| 104 | 107 | /* client.c */ |
|
| 105 | 108 | extern void manage(Window w, XWindowAttributes *wa); |
|
| 126 | 129 | extern void gravitate(Client *c, Bool invert); |
|
| 127 | 130 | ||
| 128 | 131 | /* draw.c */ |
|
| 129 | - | extern void draw(Bool border, const char *text); |
|
| 132 | + | extern void drawtext(const char *text, Bool border); |
|
| 130 | 133 | extern unsigned long initcolor(const char *colstr); |
|
| 131 | 134 | extern void initfont(const char *fontstr); |
|
| 132 | 135 | extern unsigned int textnw(char *text, unsigned int len); |
|
| 6 | 6 | #include <stdarg.h> |
|
| 7 | 7 | #include <stdio.h> |
|
| 8 | 8 | #include <stdlib.h> |
|
| 9 | + | #include <string.h> |
|
| 9 | 10 | ||
| 10 | 11 | #include <X11/cursorfont.h> |
|
| 11 | 12 | #include <X11/Xatom.h> |
|
| 34 | 35 | Bool issel; |
|
| 35 | 36 | ||
| 36 | 37 | int tsel = Tdev; /* default tag */ |
|
| 37 | - | int screen, sx, sy, sw, sh, mw, th; |
|
| 38 | + | int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; |
|
| 39 | + | char stext[1024]; |
|
| 38 | 40 | ||
| 39 | 41 | DC dc = {0}; |
|
| 40 | 42 | Client *clients = NULL; |
|
| 42 | 44 | ||
| 43 | 45 | static Bool other_wm_running; |
|
| 44 | 46 | static const char version[] = |
|
| 45 | - | "dwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; |
|
| 47 | + | "dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; |
|
| 46 | 48 | static int (*x_error_handler) (Display *, XErrorEvent *); |
|
| 47 | 49 | ||
| 48 | 50 | static void |
|
| 219 | 221 | if(other_wm_running) |
|
| 220 | 222 | error("dwm: another window manager is already running\n"); |
|
| 221 | 223 | ||
| 222 | - | sx = sy = 0; |
|
| 223 | - | sw = DisplayWidth(dpy, screen); |
|
| 224 | - | sh = DisplayHeight(dpy, screen); |
|
| 225 | - | mw = (sw * MASTERW) / 100; |
|
| 226 | - | issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); |
|
| 227 | - | ||
| 228 | 224 | XSetErrorHandler(0); |
|
| 229 | 225 | x_error_handler = XSetErrorHandler(error_handler); |
|
| 230 | 226 | ||
| 233 | 229 | wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
|
| 234 | 230 | net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); |
|
| 235 | 231 | net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); |
|
| 236 | - | ||
| 237 | 232 | XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32, |
|
| 238 | 233 | PropModeReplace, (unsigned char *) net_atom, NetLast); |
|
| 239 | - | ||
| 240 | 234 | ||
| 241 | 235 | /* init cursors */ |
|
| 242 | 236 | cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); |
|
| 251 | 245 | dc.border = initcolor(BORDERCOLOR); |
|
| 252 | 246 | initfont(FONT); |
|
| 253 | 247 | ||
| 254 | - | th = dc.font.height + 4; |
|
| 248 | + | sx = sy = 0; |
|
| 249 | + | sw = DisplayWidth(dpy, screen); |
|
| 250 | + | sh = DisplayHeight(dpy, screen); |
|
| 251 | + | mw = (sw * MASTERW) / 100; |
|
| 252 | + | ||
| 253 | + | wa.override_redirect = 1; |
|
| 254 | + | wa.background_pixmap = ParentRelative; |
|
| 255 | + | wa.event_mask = ExposureMask; |
|
| 256 | + | ||
| 257 | + | bx = by = 0; |
|
| 258 | + | bw = sw; |
|
| 259 | + | dc.h = bh = dc.font.height + 4; |
|
| 260 | + | barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen), |
|
| 261 | + | CopyFromParent, DefaultVisual(dpy, screen), |
|
| 262 | + | CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); |
|
| 263 | + | XDefineCursor(dpy, barwin, cursor[CurNormal]); |
|
| 264 | + | XMapRaised(dpy, barwin); |
|
| 255 | 265 | ||
| 256 | - | dc.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen)); |
|
| 257 | - | dc.gc = XCreateGC(dpy, root, 0, 0); |
|
| 266 | + | issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); |
|
| 258 | 267 | ||
| 259 | 268 | wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ |
|
| 260 | 269 | | LeaveWindowMask; |
|
| 261 | 270 | wa.cursor = cursor[CurNormal]; |
|
| 271 | + | ||
| 262 | 272 | XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
|
| 263 | 273 | ||
| 274 | + | dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); |
|
| 275 | + | dc.gc = XCreateGC(dpy, root, 0, 0); |
|
| 276 | + | ||
| 277 | + | strcpy(stext, "dwm-"VERSION); |
|
| 264 | 278 | scan_wins(); |
|
| 279 | + | draw_bar(); |
|
| 265 | 280 | ||
| 266 | 281 | while(running) { |
|
| 267 | 282 | XNextEvent(dpy, &ev); |
|