diff options
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | client.c | 15 | ||||
| -rw-r--r-- | dev.c | 2 | ||||
| -rw-r--r-- | draw.c | 89 | ||||
| -rw-r--r-- | dwm.h (renamed from wm.h) | 29 | ||||
| -rw-r--r-- | event.c | 2 | ||||
| -rw-r--r-- | main.c (renamed from wm.c) | 10 | ||||
| -rw-r--r-- | util.c | 2 |
8 files changed, 71 insertions, 82 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 util.c wm.c | 6 | SRC = 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 |
| @@ -22,7 +22,7 @@ config: | |||
| 22 | @echo CC $< | 22 | @echo CC $< |
| 23 | @${CC} -c ${CFLAGS} $< | 23 | @${CC} -c ${CFLAGS} $< |
| 24 | 24 | ||
| 25 | ${OBJ}: wm.h | 25 | ${OBJ}: dwm.h |
| 26 | 26 | ||
| 27 | dwm: ${OBJ} | 27 | dwm: ${OBJ} |
| 28 | @echo LD $@ | 28 | @echo LD $@ |
| @@ -9,7 +9,7 @@ | |||
| 9 | #include <X11/Xatom.h> | 9 | #include <X11/Xatom.h> |
| 10 | #include <X11/Xutil.h> | 10 | #include <X11/Xutil.h> |
| 11 | 11 | ||
| 12 | #include "wm.h" | 12 | #include "dwm.h" |
| 13 | 13 | ||
| 14 | static void floating(void); | 14 | static void floating(void); |
| 15 | static void tiling(void); | 15 | static void tiling(void); |
| @@ -125,8 +125,8 @@ resize_title(Client *c) | |||
| 125 | c->tw = 0; | 125 | c->tw = 0; |
| 126 | for(i = 0; i < TLast; i++) | 126 | for(i = 0; i < TLast; i++) |
| 127 | if(c->tags[i]) | 127 | if(c->tags[i]) |
| 128 | c->tw += textw(&dc.font, c->tags[i]) + dc.font.height; | 128 | c->tw += textw(c->tags[i]) + dc.font.height; |
| 129 | c->tw += textw(&dc.font, c->name) + dc.font.height; | 129 | c->tw += textw(c->name) + dc.font.height; |
| 130 | if(c->tw > c->w) | 130 | if(c->tw > c->w) |
| 131 | c->tw = c->w + 2; | 131 | c->tw = c->w + 2; |
| 132 | c->tx = c->x + c->w - c->tw + 2; | 132 | c->tx = c->x + c->w - c->tw + 2; |
| @@ -226,10 +226,12 @@ focus(Client *c) | |||
| 226 | c->snext = stack; | 226 | c->snext = stack; |
| 227 | stack = c; | 227 | stack = c; |
| 228 | if(old && old != c) { | 228 | if(old && old != c) { |
| 229 | XSetWindowBorder(dpy, old->win, dc.bg); | ||
| 229 | XMapWindow(dpy, old->title); | 230 | XMapWindow(dpy, old->title); |
| 230 | draw_client(old); | 231 | draw_client(old); |
| 231 | } | 232 | } |
| 232 | XUnmapWindow(dpy, c->title); | 233 | XUnmapWindow(dpy, c->title); |
| 234 | XSetWindowBorder(dpy, c->win, dc.fg); | ||
| 233 | draw_client(c); | 235 | draw_client(c); |
| 234 | XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); | 236 | XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); |
| 235 | XFlush(dpy); | 237 | XFlush(dpy); |
| @@ -250,8 +252,6 @@ manage(Window w, XWindowAttributes *wa) | |||
| 250 | c->th = th; | 252 | c->th = th; |
| 251 | c->border = 1; | 253 | c->border = 1; |
| 252 | update_size(c); | 254 | update_size(c); |
| 253 | XSetWindowBorderWidth(dpy, c->win, 1); | ||
| 254 | XSetWindowBorder(dpy, c->win, dc.border); | ||
| 255 | XSelectInput(dpy, c->win, | 255 | XSelectInput(dpy, c->win, |
| 256 | StructureNotifyMask | PropertyChangeMask | EnterWindowMask); | 256 | StructureNotifyMask | PropertyChangeMask | EnterWindowMask); |
| 257 | XGetTransientForHint(dpy, c->win, &c->trans); | 257 | XGetTransientForHint(dpy, c->win, &c->trans); |
| @@ -269,6 +269,7 @@ manage(Window w, XWindowAttributes *wa) | |||
| 269 | for(l=&clients; *l; l=&(*l)->next); | 269 | for(l=&clients; *l; l=&(*l)->next); |
| 270 | c->next = *l; /* *l == nil */ | 270 | c->next = *l; /* *l == nil */ |
| 271 | *l = c; | 271 | *l = c; |
| 272 | XSetWindowBorderWidth(dpy, c->win, 1); | ||
| 272 | XMapRaised(dpy, c->win); | 273 | XMapRaised(dpy, c->win); |
| 273 | XMapRaised(dpy, c->title); | 274 | XMapRaised(dpy, c->title); |
| 274 | XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask, | 275 | XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask, |
| @@ -435,12 +436,12 @@ draw_client(Client *c) | |||
| 435 | for(i = 0; i < TLast; i++) { | 436 | for(i = 0; i < TLast; i++) { |
| 436 | if(c->tags[i]) { | 437 | if(c->tags[i]) { |
| 437 | dc.x += dc.w; | 438 | dc.x += dc.w; |
| 438 | dc.w = textw(&dc.font, c->tags[i]) + dc.font.height; | 439 | dc.w = textw(c->tags[i]) + dc.font.height; |
| 439 | draw(True, c->tags[i]); | 440 | draw(True, c->tags[i]); |
| 440 | } | 441 | } |
| 441 | } | 442 | } |
| 442 | dc.x += dc.w; | 443 | dc.x += dc.w; |
| 443 | dc.w = textw(&dc.font, c->name) + dc.font.height; | 444 | dc.w = textw(c->name) + dc.font.height; |
| 444 | draw(True, c->name); | 445 | draw(True, c->name); |
| 445 | XCopyArea(dpy, dc.drawable, c->title, dc.gc, | 446 | XCopyArea(dpy, dc.drawable, c->title, dc.gc, |
| 446 | 0, 0, c->tw, c->th, 0, 0); | 447 | 0, 0, c->tw, c->th, 0, 0); |
| @@ -3,7 +3,7 @@ | |||
| 3 | * See LICENSE file for license details. | 3 | * See LICENSE file for license details. |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #include "wm.h" | 6 | #include "dwm.h" |
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| @@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | #include <X11/Xlocale.h> | 9 | #include <X11/Xlocale.h> |
| 10 | 10 | ||
| 11 | #include "wm.h" | 11 | #include "dwm.h" |
| 12 | 12 | ||
| 13 | static void | 13 | static void |
| 14 | drawborder(void) | 14 | drawborder(void) |
| @@ -59,7 +59,7 @@ draw(Bool border, const char *text) | |||
| 59 | x = dc.x + (h / 2); | 59 | x = dc.x + (h / 2); |
| 60 | 60 | ||
| 61 | /* shorten text if necessary */ | 61 | /* shorten text if necessary */ |
| 62 | while(len && (w = textnw(&dc.font, buf, len)) > dc.w - h) | 62 | while(len && (w = textnw(buf, len)) > dc.w - h) |
| 63 | buf[--len] = 0; | 63 | buf[--len] = 0; |
| 64 | 64 | ||
| 65 | if(w > dc.w) | 65 | if(w > dc.w) |
| @@ -79,93 +79,80 @@ draw(Bool border, const char *text) | |||
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | static unsigned long | 82 | unsigned long |
| 83 | xinitcolors(Colormap cmap, const char *colstr) | 83 | initcolor(const char *colstr) |
| 84 | { | 84 | { |
| 85 | XColor color; | 85 | XColor color; |
| 86 | Colormap cmap = DefaultColormap(dpy, screen); | ||
| 87 | |||
| 86 | XAllocNamedColor(dpy, cmap, colstr, &color, &color); | 88 | XAllocNamedColor(dpy, cmap, colstr, &color, &color); |
| 87 | return color.pixel; | 89 | return color.pixel; |
| 88 | } | 90 | } |
| 89 | 91 | ||
| 90 | void | ||
| 91 | initcolors(const char *bg, const char *fg, const char *border) | ||
| 92 | { | ||
| 93 | Colormap cmap = DefaultColormap(dpy, screen); | ||
| 94 | dc.bg = xinitcolors(cmap, bg); | ||
| 95 | dc.fg = xinitcolors(cmap, fg); | ||
| 96 | dc.border = xinitcolors(cmap, border); | ||
| 97 | } | ||
| 98 | |||
| 99 | unsigned int | 92 | unsigned int |
| 100 | textnw(Fnt *font, char *text, unsigned int len) | 93 | textnw(char *text, unsigned int len) |
| 101 | { | 94 | { |
| 102 | XRectangle r; | 95 | XRectangle r; |
| 103 | if(font->set) { | 96 | if(dc.font.set) { |
| 104 | XmbTextExtents(font->set, text, len, NULL, &r); | 97 | XmbTextExtents(dc.font.set, text, len, NULL, &r); |
| 105 | return r.width; | 98 | return r.width; |
| 106 | } | 99 | } |
| 107 | return XTextWidth(font->xfont, text, len); | 100 | return XTextWidth(dc.font.xfont, text, len); |
| 108 | } | ||
| 109 | |||
| 110 | unsigned int | ||
| 111 | textw(Fnt *font, char *text) | ||
| 112 | { | ||
| 113 | return textnw(font, text, strlen(text)); | ||
| 114 | } | 101 | } |
| 115 | 102 | ||
| 116 | unsigned int | 103 | unsigned int |
| 117 | texth(Fnt *font) | 104 | textw(char *text) |
| 118 | { | 105 | { |
| 119 | return font->height + 4; | 106 | return textnw(text, strlen(text)); |
| 120 | } | 107 | } |
| 121 | 108 | ||
| 122 | void | 109 | void |
| 123 | initfont(Fnt *font, const char *fontstr) | 110 | initfont(const char *fontstr) |
| 124 | { | 111 | { |
| 125 | char **missing, *def; | 112 | char **missing, *def; |
| 126 | int i, n; | 113 | int i, n; |
| 127 | 114 | ||
| 128 | missing = NULL; | 115 | missing = NULL; |
| 129 | setlocale(LC_ALL, ""); | 116 | setlocale(LC_ALL, ""); |
| 130 | if(font->set) | 117 | if(dc.font.set) |
| 131 | XFreeFontSet(dpy, font->set); | 118 | XFreeFontSet(dpy, dc.font.set); |
| 132 | font->set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); | 119 | dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); |
| 133 | if(missing) { | 120 | if(missing) { |
| 134 | while(n--) | 121 | while(n--) |
| 135 | fprintf(stderr, "missing fontset: %s\n", missing[n]); | 122 | fprintf(stderr, "missing fontset: %s\n", missing[n]); |
| 136 | XFreeStringList(missing); | 123 | XFreeStringList(missing); |
| 137 | if(font->set) { | 124 | if(dc.font.set) { |
| 138 | XFreeFontSet(dpy, font->set); | 125 | XFreeFontSet(dpy, dc.font.set); |
| 139 | font->set = NULL; | 126 | dc.font.set = NULL; |
| 140 | } | 127 | } |
| 141 | } | 128 | } |
| 142 | if(font->set) { | 129 | if(dc.font.set) { |
| 143 | XFontSetExtents *font_extents; | 130 | XFontSetExtents *font_extents; |
| 144 | XFontStruct **xfonts; | 131 | XFontStruct **xfonts; |
| 145 | char **font_names; | 132 | char **font_names; |
| 146 | 133 | ||
| 147 | font->ascent = font->descent = 0; | 134 | dc.font.ascent = dc.font.descent = 0; |
| 148 | font_extents = XExtentsOfFontSet(font->set); | 135 | font_extents = XExtentsOfFontSet(dc.font.set); |
| 149 | n = XFontsOfFontSet(font->set, &xfonts, &font_names); | 136 | n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); |
| 150 | for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) { | 137 | for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { |
| 151 | if(font->ascent < (*xfonts)->ascent) | 138 | if(dc.font.ascent < (*xfonts)->ascent) |
| 152 | font->ascent = (*xfonts)->ascent; | 139 | dc.font.ascent = (*xfonts)->ascent; |
| 153 | if(font->descent < (*xfonts)->descent) | 140 | if(dc.font.descent < (*xfonts)->descent) |
| 154 | font->descent = (*xfonts)->descent; | 141 | dc.font.descent = (*xfonts)->descent; |
| 155 | xfonts++; | 142 | xfonts++; |
| 156 | } | 143 | } |
| 157 | } | 144 | } |
| 158 | else { | 145 | else { |
| 159 | if(font->xfont) | 146 | if(dc.font.xfont) |
| 160 | XFreeFont(dpy, font->xfont); | 147 | XFreeFont(dpy, dc.font.xfont); |
| 161 | font->xfont = NULL; | 148 | dc.font.xfont = NULL; |
| 162 | font->xfont = XLoadQueryFont(dpy, fontstr); | 149 | dc.font.xfont = XLoadQueryFont(dpy, fontstr); |
| 163 | if (!font->xfont) | 150 | if (!dc.font.xfont) |
| 164 | font->xfont = XLoadQueryFont(dpy, "fixed"); | 151 | dc.font.xfont = XLoadQueryFont(dpy, "fixed"); |
| 165 | if (!font->xfont) | 152 | if (!dc.font.xfont) |
| 166 | error("error, cannot init 'fixed' font\n"); | 153 | error("error, cannot init 'fixed' font\n"); |
| 167 | font->ascent = font->xfont->ascent; | 154 | dc.font.ascent = dc.font.xfont->ascent; |
| 168 | font->descent = font->xfont->descent; | 155 | dc.font.descent = dc.font.xfont->descent; |
| 169 | } | 156 | } |
| 170 | font->height = font->ascent + font->descent; | 157 | dc.font.height = dc.font.ascent + dc.font.descent; |
| 171 | } | 158 | } |
| @@ -8,10 +8,9 @@ | |||
| 8 | /********** CUSTOMIZE **********/ | 8 | /********** CUSTOMIZE **********/ |
| 9 | 9 | ||
| 10 | #define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*" | 10 | #define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*" |
| 11 | #define BGCOLOR "#666699" | 11 | #define BGCOLOR "DarkSlateGrey" |
| 12 | #define FGCOLOR "#ffffff" | 12 | #define FGCOLOR "LightSteelBlue" |
| 13 | #define BORDERCOLOR "#9999CC" | 13 | #define BORDERCOLOR "SlateGray" |
| 14 | #define STATUSDELAY 10 /* seconds */ | ||
| 15 | #define WM_PROTOCOL_DELWIN 1 | 14 | #define WM_PROTOCOL_DELWIN 1 |
| 16 | 15 | ||
| 17 | /* tags */ | 16 | /* tags */ |
| @@ -106,11 +105,11 @@ extern void gravitate(Client *c, Bool invert); | |||
| 106 | 105 | ||
| 107 | /* draw.c */ | 106 | /* draw.c */ |
| 108 | extern void draw(Bool border, const char *text); | 107 | extern void draw(Bool border, const char *text); |
| 109 | extern void initcolors(const char *bg, const char *fg, const char *bo); | 108 | extern unsigned long initcolor(const char *colstr); |
| 110 | extern void initfont(Fnt *font, const char *fontstr); | 109 | extern void initfont(const char *fontstr); |
| 111 | extern unsigned int textnw(Fnt *font, char *text, unsigned int len); | 110 | extern unsigned int textnw(char *text, unsigned int len); |
| 112 | extern unsigned int textw(Fnt *font, char *text); | 111 | extern unsigned int textw(char *text); |
| 113 | extern unsigned int texth(Fnt *font); | 112 | extern unsigned int texth(void); |
| 114 | 113 | ||
| 115 | /* event.c */ | 114 | /* event.c */ |
| 116 | extern void discard_events(long even_mask); | 115 | extern void discard_events(long even_mask); |
| @@ -121,6 +120,12 @@ extern void keypress(XEvent *e); | |||
| 121 | extern void mresize(Client *c); | 120 | extern void mresize(Client *c); |
| 122 | extern void mmove(Client *c); | 121 | extern void mmove(Client *c); |
| 123 | 122 | ||
| 123 | /* main.c */ | ||
| 124 | extern int error_handler(Display *dsply, XErrorEvent *e); | ||
| 125 | extern void send_message(Window w, Atom a, long value); | ||
| 126 | extern int win_proto(Window w); | ||
| 127 | extern void quit(void *aux); | ||
| 128 | |||
| 124 | /* util.c */ | 129 | /* util.c */ |
| 125 | extern void error(const char *errstr, ...); | 130 | extern void error(const char *errstr, ...); |
| 126 | extern void *emallocz(unsigned int size); | 131 | extern void *emallocz(unsigned int size); |
| @@ -129,9 +134,3 @@ extern void *erealloc(void *ptr, unsigned int size); | |||
| 129 | extern char *estrdup(const char *str); | 134 | extern char *estrdup(const char *str); |
| 130 | extern void spawn(char *argv[]); | 135 | extern void spawn(char *argv[]); |
| 131 | extern void swap(void **p1, void **p2); | 136 | extern void swap(void **p1, void **p2); |
| 132 | |||
| 133 | /* wm.c */ | ||
| 134 | extern int error_handler(Display *dsply, XErrorEvent *e); | ||
| 135 | extern void send_message(Window w, Atom a, long value); | ||
| 136 | extern int win_proto(Window w); | ||
| 137 | extern void quit(void *aux); | ||
| @@ -9,7 +9,7 @@ | |||
| 9 | #include <X11/keysym.h> | 9 | #include <X11/keysym.h> |
| 10 | #include <X11/Xatom.h> | 10 | #include <X11/Xatom.h> |
| 11 | 11 | ||
| 12 | #include "wm.h" | 12 | #include "dwm.h" |
| 13 | 13 | ||
| 14 | /* local functions */ | 14 | /* local functions */ |
| 15 | static void buttonpress(XEvent *e); | 15 | static void buttonpress(XEvent *e); |
| @@ -11,7 +11,7 @@ | |||
| 11 | #include <X11/Xatom.h> | 11 | #include <X11/Xatom.h> |
| 12 | #include <X11/Xproto.h> | 12 | #include <X11/Xproto.h> |
| 13 | 13 | ||
| 14 | #include "wm.h" | 14 | #include "dwm.h" |
| 15 | 15 | ||
| 16 | /********** CUSTOMIZE **********/ | 16 | /********** CUSTOMIZE **********/ |
| 17 | 17 | ||
| @@ -244,10 +244,12 @@ main(int argc, char *argv[]) | |||
| 244 | update_keys(); | 244 | update_keys(); |
| 245 | 245 | ||
| 246 | /* style */ | 246 | /* style */ |
| 247 | initcolors(BGCOLOR, FGCOLOR, BORDERCOLOR); | 247 | dc.bg = initcolor(BGCOLOR); |
| 248 | initfont(&dc.font, FONT); | 248 | dc.fg = initcolor(FGCOLOR); |
| 249 | dc.border = initcolor(BORDERCOLOR); | ||
| 250 | initfont(FONT); | ||
| 249 | 251 | ||
| 250 | th = texth(&dc.font); | 252 | th = dc.font.height + 4; |
| 251 | 253 | ||
| 252 | dc.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen)); | 254 | dc.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen)); |
| 253 | dc.gc = XCreateGC(dpy, root, 0, 0); | 255 | dc.gc = XCreateGC(dpy, root, 0, 0); |
| @@ -11,7 +11,7 @@ | |||
| 11 | #include <sys/wait.h> | 11 | #include <sys/wait.h> |
| 12 | #include <unistd.h> | 12 | #include <unistd.h> |
| 13 | 13 | ||
| 14 | #include "wm.h" | 14 | #include "dwm.h" |
| 15 | 15 | ||
| 16 | void | 16 | void |
| 17 | error(const char *errstr, ...) { | 17 | error(const char *errstr, ...) { |
