diff options
| author | Anselm R. Garbe <garbeam@gmail.com> | 2007-09-15 13:16:54 +0200 |
|---|---|---|
| committer | Anselm R. Garbe <garbeam@gmail.com> | 2007-09-15 13:16:54 +0200 |
| commit | 7e476fb86ba254e6fe3a916ed7b5298e432a469c (patch) | |
| tree | cc8ce1467345a1643cd172b478a38e472bfcc3ec | |
| parent | renamed drawstatus into drawbar (diff) | |
| download | dwm-7e476fb86ba254e6fe3a916ed7b5298e432a469c.tar.gz dwm-7e476fb86ba254e6fe3a916ed7b5298e432a469c.zip | |
moved bar-related stuff to bar.c (merged draw.c into that)
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | bar.c | 258 | ||||
| -rw-r--r-- | draw.c | 134 | ||||
| -rw-r--r-- | dwm.h | 14 | ||||
| -rw-r--r-- | main.c | 84 | ||||
| -rw-r--r-- | screen.c | 36 |
6 files changed, 269 insertions, 259 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | include config.mk | 4 | include config.mk |
| 5 | 5 | ||
| 6 | SRC += client.c draw.c event.c main.c screen.c util.c | 6 | SRC += bar.c client.c event.c main.c screen.c util.c |
| 7 | OBJ = ${SRC:.c=.o} | 7 | OBJ = ${SRC:.c=.o} |
| 8 | 8 | ||
| 9 | all: options dwm | 9 | all: options dwm |
| @@ -0,0 +1,258 @@ | |||
| 1 | /* See LICENSE file for copyright and license details. */ | ||
| 2 | #include "dwm.h" | ||
| 3 | #include <string.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | |||
| 6 | /* static */ | ||
| 7 | |||
| 8 | static void | ||
| 9 | drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) { | ||
| 10 | int x; | ||
| 11 | XGCValues gcv; | ||
| 12 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; | ||
| 13 | |||
| 14 | gcv.foreground = col[ColFG]; | ||
| 15 | XChangeGC(dpy, dc.gc, GCForeground, &gcv); | ||
| 16 | x = (dc.font.ascent + dc.font.descent + 2) / 4; | ||
| 17 | r.x = dc.x + 1; | ||
| 18 | r.y = dc.y + 1; | ||
| 19 | if(filled) { | ||
| 20 | r.width = r.height = x + 1; | ||
| 21 | XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); | ||
| 22 | } | ||
| 23 | else if(empty) { | ||
| 24 | r.width = r.height = x; | ||
| 25 | XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | static unsigned long | ||
| 30 | initcolor(const char *colstr) { | ||
| 31 | Colormap cmap = DefaultColormap(dpy, screen); | ||
| 32 | XColor color; | ||
| 33 | |||
| 34 | if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) | ||
| 35 | eprint("error, cannot allocate color '%s'\n", colstr); | ||
| 36 | return color.pixel; | ||
| 37 | } | ||
| 38 | |||
| 39 | static void | ||
| 40 | initfont(const char *fontstr) { | ||
| 41 | char *def, **missing; | ||
| 42 | int i, n; | ||
| 43 | |||
| 44 | missing = NULL; | ||
| 45 | if(dc.font.set) | ||
| 46 | XFreeFontSet(dpy, dc.font.set); | ||
| 47 | dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); | ||
| 48 | if(missing) { | ||
| 49 | while(n--) | ||
| 50 | fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]); | ||
| 51 | XFreeStringList(missing); | ||
| 52 | } | ||
| 53 | if(dc.font.set) { | ||
| 54 | XFontSetExtents *font_extents; | ||
| 55 | XFontStruct **xfonts; | ||
| 56 | char **font_names; | ||
| 57 | dc.font.ascent = dc.font.descent = 0; | ||
| 58 | font_extents = XExtentsOfFontSet(dc.font.set); | ||
| 59 | n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); | ||
| 60 | for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { | ||
| 61 | if(dc.font.ascent < (*xfonts)->ascent) | ||
| 62 | dc.font.ascent = (*xfonts)->ascent; | ||
| 63 | if(dc.font.descent < (*xfonts)->descent) | ||
| 64 | dc.font.descent = (*xfonts)->descent; | ||
| 65 | xfonts++; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | else { | ||
| 69 | if(dc.font.xfont) | ||
| 70 | XFreeFont(dpy, dc.font.xfont); | ||
| 71 | dc.font.xfont = NULL; | ||
| 72 | if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))) | ||
| 73 | eprint("error, cannot load font: '%s'\n", fontstr); | ||
| 74 | dc.font.ascent = dc.font.xfont->ascent; | ||
| 75 | dc.font.descent = dc.font.xfont->descent; | ||
| 76 | } | ||
| 77 | dc.font.height = dc.font.ascent + dc.font.descent; | ||
| 78 | } | ||
| 79 | |||
| 80 | static Bool | ||
| 81 | isoccupied(unsigned int t) { | ||
| 82 | Client *c; | ||
| 83 | |||
| 84 | for(c = clients; c; c = c->next) | ||
| 85 | if(c->tags[t]) | ||
| 86 | return True; | ||
| 87 | return False; | ||
| 88 | } | ||
| 89 | |||
| 90 | static unsigned int | ||
| 91 | textnw(const char *text, unsigned int len) { | ||
| 92 | XRectangle r; | ||
| 93 | |||
| 94 | if(dc.font.set) { | ||
| 95 | XmbTextExtents(dc.font.set, text, len, NULL, &r); | ||
| 96 | return r.width; | ||
| 97 | } | ||
| 98 | return XTextWidth(dc.font.xfont, text, len); | ||
| 99 | } | ||
| 100 | |||
| 101 | static void | ||
| 102 | drawtext(const char *text, unsigned long col[ColLast]) { | ||
| 103 | int x, y, w, h; | ||
| 104 | static char buf[256]; | ||
| 105 | unsigned int len, olen; | ||
| 106 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; | ||
| 107 | |||
| 108 | XSetForeground(dpy, dc.gc, col[ColBG]); | ||
| 109 | XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); | ||
| 110 | if(!text) | ||
| 111 | return; | ||
| 112 | w = 0; | ||
| 113 | olen = len = strlen(text); | ||
| 114 | if(len >= sizeof buf) | ||
| 115 | len = sizeof buf - 1; | ||
| 116 | memcpy(buf, text, len); | ||
| 117 | buf[len] = 0; | ||
| 118 | h = dc.font.ascent + dc.font.descent; | ||
| 119 | y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; | ||
| 120 | x = dc.x + (h / 2); | ||
| 121 | /* shorten text if necessary */ | ||
| 122 | while(len && (w = textnw(buf, len)) > dc.w - h) | ||
| 123 | buf[--len] = 0; | ||
| 124 | if(len < olen) { | ||
| 125 | if(len > 1) | ||
| 126 | buf[len - 1] = '.'; | ||
| 127 | if(len > 2) | ||
| 128 | buf[len - 2] = '.'; | ||
| 129 | if(len > 3) | ||
| 130 | buf[len - 3] = '.'; | ||
| 131 | } | ||
| 132 | if(w > dc.w) | ||
| 133 | return; /* too long */ | ||
| 134 | XSetForeground(dpy, dc.gc, col[ColFG]); | ||
| 135 | if(dc.font.set) | ||
| 136 | XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); | ||
| 137 | else | ||
| 138 | XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); | ||
| 139 | } | ||
| 140 | |||
| 141 | /* extern */ | ||
| 142 | |||
| 143 | unsigned int bh; | ||
| 144 | unsigned int bpos = BARPOS; | ||
| 145 | DC dc = {0}; | ||
| 146 | Window barwin; | ||
| 147 | |||
| 148 | void | ||
| 149 | drawbar(void) { | ||
| 150 | int i, x; | ||
| 151 | |||
| 152 | dc.x = dc.y = 0; | ||
| 153 | for(i = 0; i < ntags; i++) { | ||
| 154 | dc.w = textw(tags[i]); | ||
| 155 | if(seltags[i]) { | ||
| 156 | drawtext(tags[i], dc.sel); | ||
| 157 | drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel); | ||
| 158 | } | ||
| 159 | else { | ||
| 160 | drawtext(tags[i], dc.norm); | ||
| 161 | drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm); | ||
| 162 | } | ||
| 163 | dc.x += dc.w; | ||
| 164 | } | ||
| 165 | dc.w = blw; | ||
| 166 | drawtext(getsymbol(), dc.norm); | ||
| 167 | x = dc.x + dc.w; | ||
| 168 | dc.w = textw(stext); | ||
| 169 | dc.x = sw - dc.w; | ||
| 170 | if(dc.x < x) { | ||
| 171 | dc.x = x; | ||
| 172 | dc.w = sw - x; | ||
| 173 | } | ||
| 174 | drawtext(stext, dc.norm); | ||
| 175 | if((dc.w = dc.x - x) > bh) { | ||
| 176 | dc.x = x; | ||
| 177 | if(sel) { | ||
| 178 | drawtext(sel->name, dc.sel); | ||
| 179 | drawsquare(sel->ismax, sel->isfloating, dc.sel); | ||
| 180 | } | ||
| 181 | else | ||
| 182 | drawtext(NULL, dc.norm); | ||
| 183 | } | ||
| 184 | XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0); | ||
| 185 | XSync(dpy, False); | ||
| 186 | } | ||
| 187 | |||
| 188 | void | ||
| 189 | initbar(void) { | ||
| 190 | XSetWindowAttributes wa; | ||
| 191 | |||
| 192 | dc.norm[ColBorder] = initcolor(NORMBORDERCOLOR); | ||
| 193 | dc.norm[ColBG] = initcolor(NORMBGCOLOR); | ||
| 194 | dc.norm[ColFG] = initcolor(NORMFGCOLOR); | ||
| 195 | dc.sel[ColBorder] = initcolor(SELBORDERCOLOR); | ||
| 196 | dc.sel[ColBG] = initcolor(SELBGCOLOR); | ||
| 197 | dc.sel[ColFG] = initcolor(SELFGCOLOR); | ||
| 198 | initfont(FONT); | ||
| 199 | dc.h = bh = dc.font.height + 2; | ||
| 200 | wa.override_redirect = 1; | ||
| 201 | wa.background_pixmap = ParentRelative; | ||
| 202 | wa.event_mask = ButtonPressMask | ExposureMask; | ||
| 203 | barwin = XCreateWindow(dpy, root, sx, sy, sw, bh, 0, | ||
| 204 | DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), | ||
| 205 | CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); | ||
| 206 | XDefineCursor(dpy, barwin, cursor[CurNormal]); | ||
| 207 | updatebarpos(); | ||
| 208 | XMapRaised(dpy, barwin); | ||
| 209 | strcpy(stext, "dwm-"VERSION); | ||
| 210 | dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); | ||
| 211 | dc.gc = XCreateGC(dpy, root, 0, 0); | ||
| 212 | XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); | ||
| 213 | if(!dc.font.set) | ||
| 214 | XSetFont(dpy, dc.gc, dc.font.xfont->fid); | ||
| 215 | } | ||
| 216 | |||
| 217 | unsigned int | ||
| 218 | textw(const char *text) { | ||
| 219 | return textnw(text, strlen(text)) + dc.font.height; | ||
| 220 | } | ||
| 221 | |||
| 222 | void | ||
| 223 | togglebar(const char *arg) { | ||
| 224 | if(bpos == BarOff) | ||
| 225 | bpos = (BARPOS == BarOff) ? BarTop : BARPOS; | ||
| 226 | else | ||
| 227 | bpos = BarOff; | ||
| 228 | updatebarpos(); | ||
| 229 | arrange(); | ||
| 230 | } | ||
| 231 | |||
| 232 | void | ||
| 233 | updatebarpos(void) { | ||
| 234 | XEvent ev; | ||
| 235 | |||
| 236 | wax = sx; | ||
| 237 | way = sy; | ||
| 238 | wah = sh; | ||
| 239 | waw = sw; | ||
| 240 | switch(bpos) { | ||
| 241 | default: | ||
| 242 | wah -= bh; | ||
| 243 | way += bh; | ||
| 244 | XMoveWindow(dpy, barwin, sx, sy); | ||
| 245 | break; | ||
| 246 | case BarBot: | ||
| 247 | wah -= bh; | ||
| 248 | XMoveWindow(dpy, barwin, sx, sy + wah); | ||
| 249 | break; | ||
| 250 | case BarOff: | ||
| 251 | XMoveWindow(dpy, barwin, sx, sy - bh); | ||
| 252 | break; | ||
| 253 | } | ||
| 254 | XSync(dpy, False); | ||
| 255 | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | ||
| 256 | } | ||
| 257 | |||
| 258 | |||
| @@ -1,134 +0,0 @@ | |||
| 1 | /* See LICENSE file for copyright and license details. */ | ||
| 2 | #include "dwm.h" | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | /* static */ | ||
| 6 | |||
| 7 | static void | ||
| 8 | drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) { | ||
| 9 | int x; | ||
| 10 | XGCValues gcv; | ||
| 11 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; | ||
| 12 | |||
| 13 | gcv.foreground = col[ColFG]; | ||
| 14 | XChangeGC(dpy, dc.gc, GCForeground, &gcv); | ||
| 15 | x = (dc.font.ascent + dc.font.descent + 2) / 4; | ||
| 16 | r.x = dc.x + 1; | ||
| 17 | r.y = dc.y + 1; | ||
| 18 | if(filled) { | ||
| 19 | r.width = r.height = x + 1; | ||
| 20 | XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); | ||
| 21 | } | ||
| 22 | else if(empty) { | ||
| 23 | r.width = r.height = x; | ||
| 24 | XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1); | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | static Bool | ||
| 29 | isoccupied(unsigned int t) { | ||
| 30 | Client *c; | ||
| 31 | |||
| 32 | for(c = clients; c; c = c->next) | ||
| 33 | if(c->tags[t]) | ||
| 34 | return True; | ||
| 35 | return False; | ||
| 36 | } | ||
| 37 | |||
| 38 | static unsigned int | ||
| 39 | textnw(const char *text, unsigned int len) { | ||
| 40 | XRectangle r; | ||
| 41 | |||
| 42 | if(dc.font.set) { | ||
| 43 | XmbTextExtents(dc.font.set, text, len, NULL, &r); | ||
| 44 | return r.width; | ||
| 45 | } | ||
| 46 | return XTextWidth(dc.font.xfont, text, len); | ||
| 47 | } | ||
| 48 | |||
| 49 | /* extern */ | ||
| 50 | |||
| 51 | void | ||
| 52 | drawbar(void) { | ||
| 53 | int i, x; | ||
| 54 | |||
| 55 | dc.x = dc.y = 0; | ||
| 56 | for(i = 0; i < ntags; i++) { | ||
| 57 | dc.w = textw(tags[i]); | ||
| 58 | if(seltags[i]) { | ||
| 59 | drawtext(tags[i], dc.sel); | ||
| 60 | drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel); | ||
| 61 | } | ||
| 62 | else { | ||
| 63 | drawtext(tags[i], dc.norm); | ||
| 64 | drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm); | ||
| 65 | } | ||
| 66 | dc.x += dc.w; | ||
| 67 | } | ||
| 68 | dc.w = blw; | ||
| 69 | drawtext(getsymbol(), dc.norm); | ||
| 70 | x = dc.x + dc.w; | ||
| 71 | dc.w = textw(stext); | ||
| 72 | dc.x = sw - dc.w; | ||
| 73 | if(dc.x < x) { | ||
| 74 | dc.x = x; | ||
| 75 | dc.w = sw - x; | ||
| 76 | } | ||
| 77 | drawtext(stext, dc.norm); | ||
| 78 | if((dc.w = dc.x - x) > bh) { | ||
| 79 | dc.x = x; | ||
| 80 | if(sel) { | ||
| 81 | drawtext(sel->name, dc.sel); | ||
| 82 | drawsquare(sel->ismax, sel->isfloating, dc.sel); | ||
| 83 | } | ||
| 84 | else | ||
| 85 | drawtext(NULL, dc.norm); | ||
| 86 | } | ||
| 87 | XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0); | ||
| 88 | XSync(dpy, False); | ||
| 89 | } | ||
| 90 | |||
| 91 | void | ||
| 92 | drawtext(const char *text, unsigned long col[ColLast]) { | ||
| 93 | int x, y, w, h; | ||
| 94 | static char buf[256]; | ||
| 95 | unsigned int len, olen; | ||
| 96 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; | ||
| 97 | |||
| 98 | XSetForeground(dpy, dc.gc, col[ColBG]); | ||
| 99 | XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); | ||
| 100 | if(!text) | ||
| 101 | return; | ||
| 102 | w = 0; | ||
| 103 | olen = len = strlen(text); | ||
| 104 | if(len >= sizeof buf) | ||
| 105 | len = sizeof buf - 1; | ||
| 106 | memcpy(buf, text, len); | ||
| 107 | buf[len] = 0; | ||
| 108 | h = dc.font.ascent + dc.font.descent; | ||
| 109 | y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; | ||
| 110 | x = dc.x + (h / 2); | ||
| 111 | /* shorten text if necessary */ | ||
| 112 | while(len && (w = textnw(buf, len)) > dc.w - h) | ||
| 113 | buf[--len] = 0; | ||
| 114 | if(len < olen) { | ||
| 115 | if(len > 1) | ||
| 116 | buf[len - 1] = '.'; | ||
| 117 | if(len > 2) | ||
| 118 | buf[len - 2] = '.'; | ||
| 119 | if(len > 3) | ||
| 120 | buf[len - 3] = '.'; | ||
| 121 | } | ||
| 122 | if(w > dc.w) | ||
| 123 | return; /* too long */ | ||
| 124 | XSetForeground(dpy, dc.gc, col[ColFG]); | ||
| 125 | if(dc.font.set) | ||
| 126 | XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); | ||
| 127 | else | ||
| 128 | XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); | ||
| 129 | } | ||
| 130 | |||
| 131 | unsigned int | ||
| 132 | textw(const char *text) { | ||
| 133 | return textnw(text, strlen(text)) + dc.font.height; | ||
| 134 | } | ||
| @@ -88,6 +88,13 @@ extern DC dc; /* global draw context */ | |||
| 88 | extern Display *dpy; | 88 | extern Display *dpy; |
| 89 | extern Window root, barwin; | 89 | extern Window root, barwin; |
| 90 | 90 | ||
| 91 | /* bar.c */ | ||
| 92 | void drawbar(void); /* draw the bar */ | ||
| 93 | void initbar(void); /* initializes the bar */ | ||
| 94 | unsigned int textw(const char *text); /* return the width of text in px*/ | ||
| 95 | void togglebar(const char *arg); /* shows/hides the bar */ | ||
| 96 | void updatebarpos(void); /* updates the bar position */ | ||
| 97 | |||
| 91 | /* client.c */ | 98 | /* client.c */ |
| 92 | void attach(Client *c); /* attaches c to global client list */ | 99 | void attach(Client *c); /* attaches c to global client list */ |
| 93 | void ban(Client *c); /* bans c */ | 100 | void ban(Client *c); /* bans c */ |
| @@ -103,11 +110,6 @@ void unmanage(Client *c); /* unmanage c */ | |||
| 103 | void updatesizehints(Client *c); /* update the size hint variables of c */ | 110 | void updatesizehints(Client *c); /* update the size hint variables of c */ |
| 104 | void updatetitle(Client *c); /* update the name of c */ | 111 | void updatetitle(Client *c); /* update the name of c */ |
| 105 | 112 | ||
| 106 | /* draw.c */ | ||
| 107 | void drawbar(void); /* draw the bar */ | ||
| 108 | void drawtext(const char *text, unsigned long col[ColLast]); /* draw text */ | ||
| 109 | unsigned int textw(const char *text); /* return the width of text in px*/ | ||
| 110 | |||
| 111 | /* event.c */ | 113 | /* event.c */ |
| 112 | void grabkeys(void); /* grab all keys defined in config.h */ | 114 | void grabkeys(void); /* grab all keys defined in config.h */ |
| 113 | 115 | ||
| @@ -132,12 +134,10 @@ Client *nexttiled(Client *c); /* returns tiled successor of c */ | |||
| 132 | void restack(void); /* restores z layers of all clients */ | 134 | void restack(void); /* restores z layers of all clients */ |
| 133 | void setlayout(const char *arg); /* sets layout, NULL means next layout */ | 135 | void setlayout(const char *arg); /* sets layout, NULL means next layout */ |
| 134 | void tag(const char *arg); /* tags sel with arg's index */ | 136 | void tag(const char *arg); /* tags sel with arg's index */ |
| 135 | void togglebar(const char *arg); /* shows/hides the bar */ | ||
| 136 | void togglefloating(const char *arg); /* toggles sel between floating/tiled state */ | 137 | void togglefloating(const char *arg); /* toggles sel between floating/tiled state */ |
| 137 | void togglemax(const char *arg); /* toggles maximization of floating client */ | 138 | void togglemax(const char *arg); /* toggles maximization of floating client */ |
| 138 | void toggletag(const char *arg); /* toggles sel tags with arg's index */ | 139 | void toggletag(const char *arg); /* toggles sel tags with arg's index */ |
| 139 | void toggleview(const char *arg); /* toggles the tag with arg's index (in)visible */ | 140 | void toggleview(const char *arg); /* toggles the tag with arg's index (in)visible */ |
| 140 | void updatebarpos(void); /* updates the bar position */ | ||
| 141 | void view(const char *arg); /* views the tag with arg's index */ | 141 | void view(const char *arg); /* views the tag with arg's index */ |
| 142 | 142 | ||
| 143 | /* util.c */ | 143 | /* util.c */ |
| @@ -17,8 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | char stext[256]; | 18 | char stext[256]; |
| 19 | int screen, sx, sy, sw, sh, wax, way, waw, wah; | 19 | int screen, sx, sy, sw, sh, wax, way, waw, wah; |
| 20 | unsigned int bh, ntags; | 20 | unsigned int ntags; |
| 21 | unsigned int bpos = BARPOS; | ||
| 22 | unsigned int numlockmask = 0; | 21 | unsigned int numlockmask = 0; |
| 23 | Atom wmatom[WMLast], netatom[NetLast]; | 22 | Atom wmatom[WMLast], netatom[NetLast]; |
| 24 | Bool *seltags; | 23 | Bool *seltags; |
| @@ -28,8 +27,7 @@ Client *sel = NULL; | |||
| 28 | Client *stack = NULL; | 27 | Client *stack = NULL; |
| 29 | Cursor cursor[CurLast]; | 28 | Cursor cursor[CurLast]; |
| 30 | Display *dpy; | 29 | Display *dpy; |
| 31 | DC dc = {0}; | 30 | Window root; |
| 32 | Window root, barwin; | ||
| 33 | 31 | ||
| 34 | /* static */ | 32 | /* static */ |
| 35 | 33 | ||
| @@ -60,57 +58,6 @@ cleanup(void) { | |||
| 60 | free(seltags); | 58 | free(seltags); |
| 61 | } | 59 | } |
| 62 | 60 | ||
| 63 | static unsigned long | ||
| 64 | initcolor(const char *colstr) { | ||
| 65 | Colormap cmap = DefaultColormap(dpy, screen); | ||
| 66 | XColor color; | ||
| 67 | |||
| 68 | if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) | ||
| 69 | eprint("error, cannot allocate color '%s'\n", colstr); | ||
| 70 | return color.pixel; | ||
| 71 | } | ||
| 72 | |||
| 73 | static void | ||
| 74 | initfont(const char *fontstr) { | ||
| 75 | char *def, **missing; | ||
| 76 | int i, n; | ||
| 77 | |||
| 78 | missing = NULL; | ||
| 79 | if(dc.font.set) | ||
| 80 | XFreeFontSet(dpy, dc.font.set); | ||
| 81 | dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); | ||
| 82 | if(missing) { | ||
| 83 | while(n--) | ||
| 84 | fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]); | ||
| 85 | XFreeStringList(missing); | ||
| 86 | } | ||
| 87 | if(dc.font.set) { | ||
| 88 | XFontSetExtents *font_extents; | ||
| 89 | XFontStruct **xfonts; | ||
| 90 | char **font_names; | ||
| 91 | dc.font.ascent = dc.font.descent = 0; | ||
| 92 | font_extents = XExtentsOfFontSet(dc.font.set); | ||
| 93 | n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); | ||
| 94 | for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { | ||
| 95 | if(dc.font.ascent < (*xfonts)->ascent) | ||
| 96 | dc.font.ascent = (*xfonts)->ascent; | ||
| 97 | if(dc.font.descent < (*xfonts)->descent) | ||
| 98 | dc.font.descent = (*xfonts)->descent; | ||
| 99 | xfonts++; | ||
| 100 | } | ||
| 101 | } | ||
| 102 | else { | ||
| 103 | if(dc.font.xfont) | ||
| 104 | XFreeFont(dpy, dc.font.xfont); | ||
| 105 | dc.font.xfont = NULL; | ||
| 106 | if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))) | ||
| 107 | eprint("error, cannot load font: '%s'\n", fontstr); | ||
| 108 | dc.font.ascent = dc.font.xfont->ascent; | ||
| 109 | dc.font.descent = dc.font.xfont->descent; | ||
| 110 | } | ||
| 111 | dc.font.height = dc.font.ascent + dc.font.descent; | ||
| 112 | } | ||
| 113 | |||
| 114 | static long | 61 | static long |
| 115 | getstate(Window w) { | 62 | getstate(Window w) { |
| 116 | int format, status; | 63 | int format, status; |
| @@ -197,37 +144,12 @@ setup(void) { | |||
| 197 | for(ntags = 0; tags[ntags]; ntags++); | 144 | for(ntags = 0; tags[ntags]; ntags++); |
| 198 | seltags = emallocz(sizeof(Bool) * ntags); | 145 | seltags = emallocz(sizeof(Bool) * ntags); |
| 199 | seltags[0] = True; | 146 | seltags[0] = True; |
| 200 | /* style */ | ||
| 201 | dc.norm[ColBorder] = initcolor(NORMBORDERCOLOR); | ||
| 202 | dc.norm[ColBG] = initcolor(NORMBGCOLOR); | ||
| 203 | dc.norm[ColFG] = initcolor(NORMFGCOLOR); | ||
| 204 | dc.sel[ColBorder] = initcolor(SELBORDERCOLOR); | ||
| 205 | dc.sel[ColBG] = initcolor(SELBGCOLOR); | ||
| 206 | dc.sel[ColFG] = initcolor(SELFGCOLOR); | ||
| 207 | initfont(FONT); | ||
| 208 | /* geometry */ | 147 | /* geometry */ |
| 209 | sx = sy = 0; | 148 | sx = sy = 0; |
| 210 | sw = DisplayWidth(dpy, screen); | 149 | sw = DisplayWidth(dpy, screen); |
| 211 | sh = DisplayHeight(dpy, screen); | 150 | sh = DisplayHeight(dpy, screen); |
| 212 | initlayouts(); | 151 | initlayouts(); |
| 213 | /* bar */ | 152 | initbar(); |
| 214 | dc.h = bh = dc.font.height + 2; | ||
| 215 | wa.override_redirect = 1; | ||
| 216 | wa.background_pixmap = ParentRelative; | ||
| 217 | wa.event_mask = ButtonPressMask | ExposureMask; | ||
| 218 | barwin = XCreateWindow(dpy, root, sx, sy, sw, bh, 0, | ||
| 219 | DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), | ||
| 220 | CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); | ||
| 221 | XDefineCursor(dpy, barwin, cursor[CurNormal]); | ||
| 222 | updatebarpos(); | ||
| 223 | XMapRaised(dpy, barwin); | ||
| 224 | strcpy(stext, "dwm-"VERSION); | ||
| 225 | /* pixmap for everything */ | ||
| 226 | dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); | ||
| 227 | dc.gc = XCreateGC(dpy, root, 0, 0); | ||
| 228 | XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); | ||
| 229 | if(!dc.font.set) | ||
| 230 | XSetFont(dpy, dc.gc, dc.font.xfont->fid); | ||
| 231 | /* multihead support */ | 153 | /* multihead support */ |
| 232 | selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); | 154 | selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); |
| 233 | } | 155 | } |
| @@ -273,16 +273,6 @@ tag(const char *arg) { | |||
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | void | 275 | void |
| 276 | togglebar(const char *arg) { | ||
| 277 | if(bpos == BarOff) | ||
| 278 | bpos = (BARPOS == BarOff) ? BarTop : BARPOS; | ||
| 279 | else | ||
| 280 | bpos = BarOff; | ||
| 281 | updatebarpos(); | ||
| 282 | arrange(); | ||
| 283 | } | ||
| 284 | |||
| 285 | void | ||
| 286 | togglefloating(const char *arg) { | 276 | togglefloating(const char *arg) { |
| 287 | if(!sel) | 277 | if(!sel) |
| 288 | return; | 278 | return; |
| @@ -338,32 +328,6 @@ toggleview(const char *arg) { | |||
| 338 | } | 328 | } |
| 339 | 329 | ||
| 340 | void | 330 | void |
| 341 | updatebarpos(void) { | ||
| 342 | XEvent ev; | ||
| 343 | |||
| 344 | wax = sx; | ||
| 345 | way = sy; | ||
| 346 | wah = sh; | ||
| 347 | waw = sw; | ||
| 348 | switch(bpos) { | ||
| 349 | default: | ||
| 350 | wah -= bh; | ||
| 351 | way += bh; | ||
| 352 | XMoveWindow(dpy, barwin, sx, sy); | ||
| 353 | break; | ||
| 354 | case BarBot: | ||
| 355 | wah -= bh; | ||
| 356 | XMoveWindow(dpy, barwin, sx, sy + wah); | ||
| 357 | break; | ||
| 358 | case BarOff: | ||
| 359 | XMoveWindow(dpy, barwin, sx, sy - bh); | ||
| 360 | break; | ||
| 361 | } | ||
| 362 | XSync(dpy, False); | ||
| 363 | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | ||
| 364 | } | ||
| 365 | |||
| 366 | void | ||
| 367 | view(const char *arg) { | 331 | view(const char *arg) { |
| 368 | unsigned int i; | 332 | unsigned int i; |
| 369 | 333 | ||
