diff options
| author | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-14 10:07:38 +0200 |
|---|---|---|
| committer | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-14 10:07:38 +0200 |
| commit | 9cd686c93a80b4095d4ee0960bef320ccd9ea02c (patch) | |
| tree | 5bc29a58baac6bd0d241a3e923380efe1d7b5f8f | |
| parent | continued with man page (diff) | |
| download | dwm-9cd686c93a80b4095d4ee0960bef320ccd9ea02c.tar.gz dwm-9cd686c93a80b4095d4ee0960bef320ccd9ea02c.zip | |
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | bar.c | 40 | ||||
| -rw-r--r-- | client.c | 30 | ||||
| -rw-r--r-- | draw.c | 2 | ||||
| -rw-r--r-- | dwm.h | 11 | ||||
| -rw-r--r-- | main.c | 41 |
6 files changed, 95 insertions, 31 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | include config.mk | 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 | OBJ = ${SRC:.c=.o} | 7 | OBJ = ${SRC:.c=.o} |
| 8 | MAN1 = dwm.1 | 8 | MAN1 = dwm.1 |
| 9 | BIN = dwm | 9 | BIN = dwm |
| @@ -0,0 +1,40 @@ | |||
| 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,9 +49,9 @@ max(Arg *arg) | |||
| 49 | if(!sel) | 49 | if(!sel) |
| 50 | return; | 50 | return; |
| 51 | sel->x = sx; | 51 | sel->x = sx; |
| 52 | sel->y = sy; | 52 | sel->y = sy + bh; |
| 53 | sel->w = sw - 2 * sel->border; | 53 | sel->w = sw - 2 * sel->border; |
| 54 | sel->h = sh - 2 * sel->border; | 54 | sel->h = sh - 2 * sel->border - bh; |
| 55 | craise(sel); | 55 | craise(sel); |
| 56 | resize(sel, False); | 56 | resize(sel, False); |
| 57 | discard_events(EnterWindowMask); | 57 | discard_events(EnterWindowMask); |
| @@ -67,6 +67,7 @@ view(Arg *arg) | |||
| 67 | 67 | ||
| 68 | for(c = clients; c; c = next(c->next)) | 68 | for(c = clients; c; c = next(c->next)) |
| 69 | draw_client(c); | 69 | draw_client(c); |
| 70 | draw_bar(); | ||
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | void | 73 | void |
| @@ -131,7 +132,10 @@ tiling(Arg *arg) | |||
| 131 | if(c->tags[tsel] && !c->floating) | 132 | if(c->tags[tsel] && !c->floating) |
| 132 | n++; | 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 | for(i = 0, c = clients; c; c = c->next) { | 140 | for(i = 0, c = clients; c; c = c->next) { |
| 137 | if(c->tags[tsel]) { | 141 | if(c->tags[tsel]) { |
| @@ -142,19 +146,19 @@ tiling(Arg *arg) | |||
| 142 | } | 146 | } |
| 143 | if(n == 1) { | 147 | if(n == 1) { |
| 144 | c->x = sx; | 148 | c->x = sx; |
| 145 | c->y = sy; | 149 | c->y = sy + bh; |
| 146 | c->w = sw - 2 * c->border; | 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 | else if(i == 0) { | 153 | else if(i == 0) { |
| 150 | c->x = sx; | 154 | c->x = sx; |
| 151 | c->y = sy; | 155 | c->y = sy + bh; |
| 152 | c->w = mw - 2 * c->border; | 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 | else { | 159 | else { |
| 156 | c->x = sx + mw; | 160 | c->x = sx + mw; |
| 157 | c->y = sy + (i - 1) * h; | 161 | c->y = sy + (i - 1) * h + bh; |
| 158 | c->w = w - 2 * c->border; | 162 | c->w = w - 2 * c->border; |
| 159 | c->h = h - 2 * c->border; | 163 | c->h = h - 2 * c->border; |
| 160 | } | 164 | } |
| @@ -373,9 +377,11 @@ manage(Window w, XWindowAttributes *wa) | |||
| 373 | c->win = w; | 377 | c->win = w; |
| 374 | c->tx = c->x = wa->x; | 378 | c->tx = c->x = wa->x; |
| 375 | c->ty = c->y = wa->y; | 379 | c->ty = c->y = wa->y; |
| 380 | if(c->y < bh) | ||
| 381 | c->ty = c->y += bh; | ||
| 376 | c->tw = c->w = wa->width; | 382 | c->tw = c->w = wa->width; |
| 377 | c->h = wa->height; | 383 | c->h = wa->height; |
| 378 | c->th = th; | 384 | c->th = bh; |
| 379 | c->border = 1; | 385 | c->border = 1; |
| 380 | c->proto = win_proto(c->win); | 386 | c->proto = win_proto(c->win); |
| 381 | update_size(c); | 387 | update_size(c); |
| @@ -570,6 +576,7 @@ draw_client(Client *c) | |||
| 570 | { | 576 | { |
| 571 | int i; | 577 | int i; |
| 572 | if(c == sel) { | 578 | if(c == sel) { |
| 579 | draw_bar(); | ||
| 573 | XUnmapWindow(dpy, c->title); | 580 | XUnmapWindow(dpy, c->title); |
| 574 | XSetWindowBorder(dpy, c->win, dc.fg); | 581 | XSetWindowBorder(dpy, c->win, dc.fg); |
| 575 | return; | 582 | return; |
| @@ -579,19 +586,18 @@ draw_client(Client *c) | |||
| 579 | XMapWindow(dpy, c->title); | 586 | XMapWindow(dpy, c->title); |
| 580 | 587 | ||
| 581 | dc.x = dc.y = 0; | 588 | dc.x = dc.y = 0; |
| 582 | dc.h = c->th; | ||
| 583 | 589 | ||
| 584 | dc.w = 0; | 590 | dc.w = 0; |
| 585 | for(i = 0; i < TLast; i++) { | 591 | for(i = 0; i < TLast; i++) { |
| 586 | if(c->tags[i]) { | 592 | if(c->tags[i]) { |
| 587 | dc.x += dc.w; | 593 | dc.x += dc.w; |
| 588 | dc.w = textw(c->tags[i]) + dc.font.height; | 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 | dc.x += dc.w; | 598 | dc.x += dc.w; |
| 593 | dc.w = textw(c->name) + dc.font.height; | 599 | dc.w = textw(c->name) + dc.font.height; |
| 594 | draw(True, c->name); | 600 | drawtext(c->name, True); |
| 595 | XCopyArea(dpy, dc.drawable, c->title, dc.gc, | 601 | XCopyArea(dpy, dc.drawable, c->title, dc.gc, |
| 596 | 0, 0, c->tw, c->th, 0, 0); | 602 | 0, 0, c->tw, c->th, 0, 0); |
| 597 | XFlush(dpy); | 603 | XFlush(dpy); |
| @@ -30,7 +30,7 @@ drawborder(void) | |||
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | void | 32 | void |
| 33 | draw(Bool border, const char *text) | 33 | drawtext(const char *text, Bool border) |
| 34 | { | 34 | { |
| 35 | int x, y, w, h; | 35 | int x, y, w, h; |
| 36 | unsigned int len; | 36 | unsigned int len; |
| @@ -88,19 +88,22 @@ struct Key { | |||
| 88 | }; | 88 | }; |
| 89 | 89 | ||
| 90 | extern Display *dpy; | 90 | extern Display *dpy; |
| 91 | extern Window root; | 91 | extern Window root, barwin; |
| 92 | extern Atom wm_atom[WMLast], net_atom[NetLast]; | 92 | extern Atom wm_atom[WMLast], net_atom[NetLast]; |
| 93 | extern Cursor cursor[CurLast]; | 93 | extern Cursor cursor[CurLast]; |
| 94 | extern Bool running, issel; | 94 | extern Bool running, issel; |
| 95 | extern void (*handler[LASTEvent])(XEvent *); | 95 | extern void (*handler[LASTEvent])(XEvent *); |
| 96 | extern void (*arrange)(Arg *); | 96 | extern void (*arrange)(Arg *); |
| 97 | 97 | ||
| 98 | extern int tsel, screen, sx, sy, sw, sh, mw, th; | 98 | extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw; |
| 99 | extern char *tags[TLast]; | 99 | extern char *tags[TLast], stext[1024]; |
| 100 | 100 | ||
| 101 | extern DC dc; | 101 | extern DC dc; |
| 102 | extern Client *clients, *sel; | 102 | extern Client *clients, *sel; |
| 103 | 103 | ||
| 104 | /* bar.c */ | ||
| 105 | extern void draw_bar(); | ||
| 106 | |||
| 104 | /* client.c */ | 107 | /* client.c */ |
| 105 | extern void manage(Window w, XWindowAttributes *wa); | 108 | extern void manage(Window w, XWindowAttributes *wa); |
| 106 | extern void unmanage(Client *c); | 109 | extern void unmanage(Client *c); |
| @@ -126,7 +129,7 @@ extern void zoom(Arg *arg); | |||
| 126 | extern void gravitate(Client *c, Bool invert); | 129 | extern void gravitate(Client *c, Bool invert); |
| 127 | 130 | ||
| 128 | /* draw.c */ | 131 | /* draw.c */ |
| 129 | extern void draw(Bool border, const char *text); | 132 | extern void drawtext(const char *text, Bool border); |
| 130 | extern unsigned long initcolor(const char *colstr); | 133 | extern unsigned long initcolor(const char *colstr); |
| 131 | extern void initfont(const char *fontstr); | 134 | extern void initfont(const char *fontstr); |
| 132 | extern unsigned int textnw(char *text, unsigned int len); | 135 | extern unsigned int textnw(char *text, unsigned int len); |
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <stdarg.h> | 6 | #include <stdarg.h> |
| 7 | #include <stdio.h> | 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <string.h> | ||
| 9 | 10 | ||
| 10 | #include <X11/cursorfont.h> | 11 | #include <X11/cursorfont.h> |
| 11 | #include <X11/Xatom.h> | 12 | #include <X11/Xatom.h> |
| @@ -34,7 +35,8 @@ Bool running = True; | |||
| 34 | Bool issel; | 35 | Bool issel; |
| 35 | 36 | ||
| 36 | int tsel = Tdev; /* default tag */ | 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 | DC dc = {0}; | 41 | DC dc = {0}; |
| 40 | Client *clients = NULL; | 42 | Client *clients = NULL; |
| @@ -42,7 +44,7 @@ Client *sel = NULL; | |||
| 42 | 44 | ||
| 43 | static Bool other_wm_running; | 45 | static Bool other_wm_running; |
| 44 | static const char version[] = | 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 | static int (*x_error_handler) (Display *, XErrorEvent *); | 48 | static int (*x_error_handler) (Display *, XErrorEvent *); |
| 47 | 49 | ||
| 48 | static void | 50 | static void |
| @@ -219,12 +221,6 @@ main(int argc, char *argv[]) | |||
| 219 | if(other_wm_running) | 221 | if(other_wm_running) |
| 220 | error("dwm: another window manager is already running\n"); | 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 | XSetErrorHandler(0); | 224 | XSetErrorHandler(0); |
| 229 | x_error_handler = XSetErrorHandler(error_handler); | 225 | x_error_handler = XSetErrorHandler(error_handler); |
| 230 | 226 | ||
| @@ -233,11 +229,9 @@ main(int argc, char *argv[]) | |||
| 233 | wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); | 229 | wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
| 234 | net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); | 230 | net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); |
| 235 | net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); | 231 | net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); |
| 236 | |||
| 237 | XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32, | 232 | XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32, |
| 238 | PropModeReplace, (unsigned char *) net_atom, NetLast); | 233 | PropModeReplace, (unsigned char *) net_atom, NetLast); |
| 239 | 234 | ||
| 240 | |||
| 241 | /* init cursors */ | 235 | /* init cursors */ |
| 242 | cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); | 236 | cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); |
| 243 | cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); | 237 | cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); |
| @@ -251,17 +245,38 @@ main(int argc, char *argv[]) | |||
| 251 | dc.border = initcolor(BORDERCOLOR); | 245 | dc.border = initcolor(BORDERCOLOR); |
| 252 | initfont(FONT); | 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; | ||
| 255 | 252 | ||
| 256 | dc.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen)); | 253 | wa.override_redirect = 1; |
| 257 | dc.gc = XCreateGC(dpy, root, 0, 0); | 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); | ||
| 265 | |||
| 266 | issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); | ||
| 258 | 267 | ||
| 259 | wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ | 268 | wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ |
| 260 | | LeaveWindowMask; | 269 | | LeaveWindowMask; |
| 261 | wa.cursor = cursor[CurNormal]; | 270 | wa.cursor = cursor[CurNormal]; |
| 271 | |||
| 262 | XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); | 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 | scan_wins(); | 278 | scan_wins(); |
| 279 | draw_bar(); | ||
| 265 | 280 | ||
| 266 | while(running) { | 281 | while(running) { |
| 267 | XNextEvent(dpy, &ev); | 282 | XNextEvent(dpy, &ev); |
