aewl
changeset 57:f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Fri, 14 Jul 2006 10:07:38 +0200 |
parents | b72b7086c385 |
children | 1269bd127551 |
files | Makefile bar.c client.c draw.c dwm.h main.c |
diffstat | 6 files changed, 95 insertions(+), 31 deletions(-) [+] |
line diff
1.1 --- a/Makefile Fri Jul 14 08:45:30 2006 +0200 1.2 +++ b/Makefile Fri Jul 14 10:07:38 2006 +0200 1.3 @@ -3,7 +3,7 @@ 1.4 1.5 include config.mk 1.6 1.7 -SRC = client.c dev.c draw.c event.c main.c util.c 1.8 +SRC = bar.c client.c dev.c draw.c event.c main.c util.c 1.9 OBJ = ${SRC:.c=.o} 1.10 MAN1 = dwm.1 1.11 BIN = dwm
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/bar.c Fri Jul 14 10:07:38 2006 +0200 2.3 @@ -0,0 +1,40 @@ 2.4 +/* 2.5 + * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> 2.6 + * See LICENSE file for license details. 2.7 + */ 2.8 + 2.9 +#include "dwm.h" 2.10 + 2.11 +void 2.12 +draw_bar() 2.13 +{ 2.14 + int i; 2.15 + dc.x = dc.y = 0; 2.16 + dc.w = bw; 2.17 + drawtext(NULL, False); 2.18 + 2.19 + dc.w = 0; 2.20 + for(i = 0; i < TLast; i++) { 2.21 + dc.x += dc.w; 2.22 + dc.w = textw(tags[i]) + dc.font.height; 2.23 + if(i == tsel) { 2.24 + swap((void **)&dc.fg, (void **)&dc.bg); 2.25 + drawtext(tags[i], True); 2.26 + swap((void **)&dc.fg, (void **)&dc.bg); 2.27 + } 2.28 + else 2.29 + drawtext(tags[i], True); 2.30 + } 2.31 + if(sel) { 2.32 + swap((void **)&dc.fg, (void **)&dc.bg); 2.33 + dc.x += dc.w; 2.34 + dc.w = textw(sel->name) + dc.font.height; 2.35 + drawtext(sel->name, True); 2.36 + swap((void **)&dc.fg, (void **)&dc.bg); 2.37 + } 2.38 + dc.w = textw(stext) + dc.font.height; 2.39 + dc.x = bx + bw - dc.w; 2.40 + drawtext(stext, False); 2.41 + XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0); 2.42 + XFlush(dpy); 2.43 +}
3.1 --- a/client.c Fri Jul 14 08:45:30 2006 +0200 3.2 +++ b/client.c Fri Jul 14 10:07:38 2006 +0200 3.3 @@ -49,9 +49,9 @@ 3.4 if(!sel) 3.5 return; 3.6 sel->x = sx; 3.7 - sel->y = sy; 3.8 + sel->y = sy + bh; 3.9 sel->w = sw - 2 * sel->border; 3.10 - sel->h = sh - 2 * sel->border; 3.11 + sel->h = sh - 2 * sel->border - bh; 3.12 craise(sel); 3.13 resize(sel, False); 3.14 discard_events(EnterWindowMask); 3.15 @@ -67,6 +67,7 @@ 3.16 3.17 for(c = clients; c; c = next(c->next)) 3.18 draw_client(c); 3.19 + draw_bar(); 3.20 } 3.21 3.22 void 3.23 @@ -131,7 +132,10 @@ 3.24 if(c->tags[tsel] && !c->floating) 3.25 n++; 3.26 3.27 - h = (n > 1) ? sh / (n - 1) : sh; 3.28 + if(n > 1) 3.29 + h = (sh - bh) / (n - 1); 3.30 + else 3.31 + h = sh - bh; 3.32 3.33 for(i = 0, c = clients; c; c = c->next) { 3.34 if(c->tags[tsel]) { 3.35 @@ -142,19 +146,19 @@ 3.36 } 3.37 if(n == 1) { 3.38 c->x = sx; 3.39 - c->y = sy; 3.40 + c->y = sy + bh; 3.41 c->w = sw - 2 * c->border; 3.42 - c->h = sh - 2 * c->border; 3.43 + c->h = sh - 2 * c->border - bh; 3.44 } 3.45 else if(i == 0) { 3.46 c->x = sx; 3.47 - c->y = sy; 3.48 + c->y = sy + bh; 3.49 c->w = mw - 2 * c->border; 3.50 - c->h = sh - 2 * c->border; 3.51 + c->h = sh - 2 * c->border - bh; 3.52 } 3.53 else { 3.54 c->x = sx + mw; 3.55 - c->y = sy + (i - 1) * h; 3.56 + c->y = sy + (i - 1) * h + bh; 3.57 c->w = w - 2 * c->border; 3.58 c->h = h - 2 * c->border; 3.59 } 3.60 @@ -373,9 +377,11 @@ 3.61 c->win = w; 3.62 c->tx = c->x = wa->x; 3.63 c->ty = c->y = wa->y; 3.64 + if(c->y < bh) 3.65 + c->ty = c->y += bh; 3.66 c->tw = c->w = wa->width; 3.67 c->h = wa->height; 3.68 - c->th = th; 3.69 + c->th = bh; 3.70 c->border = 1; 3.71 c->proto = win_proto(c->win); 3.72 update_size(c); 3.73 @@ -570,6 +576,7 @@ 3.74 { 3.75 int i; 3.76 if(c == sel) { 3.77 + draw_bar(); 3.78 XUnmapWindow(dpy, c->title); 3.79 XSetWindowBorder(dpy, c->win, dc.fg); 3.80 return; 3.81 @@ -579,19 +586,18 @@ 3.82 XMapWindow(dpy, c->title); 3.83 3.84 dc.x = dc.y = 0; 3.85 - dc.h = c->th; 3.86 3.87 dc.w = 0; 3.88 for(i = 0; i < TLast; i++) { 3.89 if(c->tags[i]) { 3.90 dc.x += dc.w; 3.91 dc.w = textw(c->tags[i]) + dc.font.height; 3.92 - draw(True, c->tags[i]); 3.93 + drawtext(c->tags[i], True); 3.94 } 3.95 } 3.96 dc.x += dc.w; 3.97 dc.w = textw(c->name) + dc.font.height; 3.98 - draw(True, c->name); 3.99 + drawtext(c->name, True); 3.100 XCopyArea(dpy, dc.drawable, c->title, dc.gc, 3.101 0, 0, c->tw, c->th, 0, 0); 3.102 XFlush(dpy);
4.1 --- a/draw.c Fri Jul 14 08:45:30 2006 +0200 4.2 +++ b/draw.c Fri Jul 14 10:07:38 2006 +0200 4.3 @@ -30,7 +30,7 @@ 4.4 } 4.5 4.6 void 4.7 -draw(Bool border, const char *text) 4.8 +drawtext(const char *text, Bool border) 4.9 { 4.10 int x, y, w, h; 4.11 unsigned int len;
5.1 --- a/dwm.h Fri Jul 14 08:45:30 2006 +0200 5.2 +++ b/dwm.h Fri Jul 14 10:07:38 2006 +0200 5.3 @@ -88,19 +88,22 @@ 5.4 }; 5.5 5.6 extern Display *dpy; 5.7 -extern Window root; 5.8 +extern Window root, barwin; 5.9 extern Atom wm_atom[WMLast], net_atom[NetLast]; 5.10 extern Cursor cursor[CurLast]; 5.11 extern Bool running, issel; 5.12 extern void (*handler[LASTEvent])(XEvent *); 5.13 extern void (*arrange)(Arg *); 5.14 5.15 -extern int tsel, screen, sx, sy, sw, sh, mw, th; 5.16 -extern char *tags[TLast]; 5.17 +extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw; 5.18 +extern char *tags[TLast], stext[1024]; 5.19 5.20 extern DC dc; 5.21 extern Client *clients, *sel; 5.22 5.23 +/* bar.c */ 5.24 +extern void draw_bar(); 5.25 + 5.26 /* client.c */ 5.27 extern void manage(Window w, XWindowAttributes *wa); 5.28 extern void unmanage(Client *c); 5.29 @@ -126,7 +129,7 @@ 5.30 extern void gravitate(Client *c, Bool invert); 5.31 5.32 /* draw.c */ 5.33 -extern void draw(Bool border, const char *text); 5.34 +extern void drawtext(const char *text, Bool border); 5.35 extern unsigned long initcolor(const char *colstr); 5.36 extern void initfont(const char *fontstr); 5.37 extern unsigned int textnw(char *text, unsigned int len);
6.1 --- a/main.c Fri Jul 14 08:45:30 2006 +0200 6.2 +++ b/main.c Fri Jul 14 10:07:38 2006 +0200 6.3 @@ -6,6 +6,7 @@ 6.4 #include <stdarg.h> 6.5 #include <stdio.h> 6.6 #include <stdlib.h> 6.7 +#include <string.h> 6.8 6.9 #include <X11/cursorfont.h> 6.10 #include <X11/Xatom.h> 6.11 @@ -34,7 +35,8 @@ 6.12 Bool issel; 6.13 6.14 int tsel = Tdev; /* default tag */ 6.15 -int screen, sx, sy, sw, sh, mw, th; 6.16 +int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; 6.17 +char stext[1024]; 6.18 6.19 DC dc = {0}; 6.20 Client *clients = NULL; 6.21 @@ -42,7 +44,7 @@ 6.22 6.23 static Bool other_wm_running; 6.24 static const char version[] = 6.25 - "dwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; 6.26 + "dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; 6.27 static int (*x_error_handler) (Display *, XErrorEvent *); 6.28 6.29 static void 6.30 @@ -219,12 +221,6 @@ 6.31 if(other_wm_running) 6.32 error("dwm: another window manager is already running\n"); 6.33 6.34 - sx = sy = 0; 6.35 - sw = DisplayWidth(dpy, screen); 6.36 - sh = DisplayHeight(dpy, screen); 6.37 - mw = (sw * MASTERW) / 100; 6.38 - issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 6.39 - 6.40 XSetErrorHandler(0); 6.41 x_error_handler = XSetErrorHandler(error_handler); 6.42 6.43 @@ -233,11 +229,9 @@ 6.44 wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); 6.45 net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); 6.46 net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); 6.47 - 6.48 XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32, 6.49 PropModeReplace, (unsigned char *) net_atom, NetLast); 6.50 6.51 - 6.52 /* init cursors */ 6.53 cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); 6.54 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); 6.55 @@ -251,17 +245,38 @@ 6.56 dc.border = initcolor(BORDERCOLOR); 6.57 initfont(FONT); 6.58 6.59 - th = dc.font.height + 4; 6.60 + sx = sy = 0; 6.61 + sw = DisplayWidth(dpy, screen); 6.62 + sh = DisplayHeight(dpy, screen); 6.63 + mw = (sw * MASTERW) / 100; 6.64 6.65 - dc.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen)); 6.66 - dc.gc = XCreateGC(dpy, root, 0, 0); 6.67 + wa.override_redirect = 1; 6.68 + wa.background_pixmap = ParentRelative; 6.69 + wa.event_mask = ExposureMask; 6.70 + 6.71 + bx = by = 0; 6.72 + bw = sw; 6.73 + dc.h = bh = dc.font.height + 4; 6.74 + barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen), 6.75 + CopyFromParent, DefaultVisual(dpy, screen), 6.76 + CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); 6.77 + XDefineCursor(dpy, barwin, cursor[CurNormal]); 6.78 + XMapRaised(dpy, barwin); 6.79 + 6.80 + issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 6.81 6.82 wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ 6.83 | LeaveWindowMask; 6.84 wa.cursor = cursor[CurNormal]; 6.85 + 6.86 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); 6.87 6.88 + dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); 6.89 + dc.gc = XCreateGC(dpy, root, 0, 0); 6.90 + 6.91 + strcpy(stext, "dwm-"VERSION); 6.92 scan_wins(); 6.93 + draw_bar(); 6.94 6.95 while(running) { 6.96 XNextEvent(dpy, &ev);