diff options
| author | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-15 17:19:19 +0200 |
|---|---|---|
| committer | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-15 17:19:19 +0200 |
| commit | c09bf8da071e05e2c1d714f0d31d41fe944bc11b (patch) | |
| tree | 4c9a8ff881b8102f2700b48a47a2121a29b1fadd | |
| parent | proceeded with cleaning up, sorting functions, etc (diff) | |
| download | dwm-c09bf8da071e05e2c1d714f0d31d41fe944bc11b.tar.gz dwm-c09bf8da071e05e2c1d714f0d31d41fe944bc11b.zip | |
sanitized other stuff
| -rw-r--r-- | client.c | 4 | ||||
| -rw-r--r-- | draw.c | 104 | ||||
| -rw-r--r-- | dwm.h | 4 | ||||
| -rw-r--r-- | event.c | 141 | ||||
| -rw-r--r-- | main.c | 25 |
5 files changed, 136 insertions, 142 deletions
| @@ -178,7 +178,7 @@ killclient(Arg *arg) | |||
| 178 | if(!sel) | 178 | if(!sel) |
| 179 | return; | 179 | return; |
| 180 | if(sel->proto & WM_PROTOCOL_DELWIN) | 180 | if(sel->proto & WM_PROTOCOL_DELWIN) |
| 181 | sendevent(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]); | 181 | sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]); |
| 182 | else | 182 | else |
| 183 | XKillClient(dpy, sel->win); | 183 | XKillClient(dpy, sel->win); |
| 184 | } | 184 | } |
| @@ -353,7 +353,7 @@ settitle(Client *c) | |||
| 353 | 353 | ||
| 354 | name.nitems = 0; | 354 | name.nitems = 0; |
| 355 | c->name[0] = 0; | 355 | c->name[0] = 0; |
| 356 | XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]); | 356 | XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]); |
| 357 | if(!name.nitems) | 357 | if(!name.nitems) |
| 358 | XGetWMName(dpy, c->win, &name); | 358 | XGetWMName(dpy, c->win, &name); |
| 359 | if(!name.nitems) | 359 | if(!name.nitems) |
| @@ -29,51 +29,18 @@ drawborder(void) | |||
| 29 | XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); | 29 | XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | /* extern functions */ | 32 | static unsigned int |
| 33 | 33 | textnw(char *text, unsigned int len) | |
| 34 | void | ||
| 35 | drawall() | ||
| 36 | { | ||
| 37 | Client *c; | ||
| 38 | |||
| 39 | for(c = clients; c; c = getnext(c->next)) | ||
| 40 | drawtitle(c); | ||
| 41 | drawstatus(); | ||
| 42 | } | ||
| 43 | |||
| 44 | void | ||
| 45 | drawstatus() | ||
| 46 | { | 34 | { |
| 47 | int i; | 35 | XRectangle r; |
| 48 | Bool istile = arrange == dotile; | 36 | if(dc.font.set) { |
| 49 | 37 | XmbTextExtents(dc.font.set, text, len, NULL, &r); | |
| 50 | dc.x = dc.y = 0; | 38 | return r.width; |
| 51 | dc.w = bw; | ||
| 52 | drawtext(NULL, !istile, False); | ||
| 53 | |||
| 54 | dc.w = 0; | ||
| 55 | for(i = 0; i < TLast; i++) { | ||
| 56 | dc.x += dc.w; | ||
| 57 | dc.w = textw(tags[i]); | ||
| 58 | if(istile) | ||
| 59 | drawtext(tags[i], (i == tsel), True); | ||
| 60 | else | ||
| 61 | drawtext(tags[i], (i != tsel), True); | ||
| 62 | } | ||
| 63 | if(sel) { | ||
| 64 | dc.x += dc.w; | ||
| 65 | dc.w = textw(sel->name); | ||
| 66 | drawtext(sel->name, istile, True); | ||
| 67 | } | 39 | } |
| 68 | dc.w = textw(stext); | 40 | return XTextWidth(dc.font.xfont, text, len); |
| 69 | dc.x = bx + bw - dc.w; | ||
| 70 | drawtext(stext, !istile, False); | ||
| 71 | |||
| 72 | XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0); | ||
| 73 | XFlush(dpy); | ||
| 74 | } | 41 | } |
| 75 | 42 | ||
| 76 | void | 43 | static void |
| 77 | drawtext(const char *text, Bool invert, Bool border) | 44 | drawtext(const char *text, Bool invert, Bool border) |
| 78 | { | 45 | { |
| 79 | int x, y, w, h; | 46 | int x, y, w, h; |
| @@ -123,6 +90,50 @@ drawtext(const char *text, Bool invert, Bool border) | |||
| 123 | } | 90 | } |
| 124 | } | 91 | } |
| 125 | 92 | ||
| 93 | /* extern functions */ | ||
| 94 | |||
| 95 | void | ||
| 96 | drawall() | ||
| 97 | { | ||
| 98 | Client *c; | ||
| 99 | |||
| 100 | for(c = clients; c; c = getnext(c->next)) | ||
| 101 | drawtitle(c); | ||
| 102 | drawstatus(); | ||
| 103 | } | ||
| 104 | |||
| 105 | void | ||
| 106 | drawstatus() | ||
| 107 | { | ||
| 108 | int i; | ||
| 109 | Bool istile = arrange == dotile; | ||
| 110 | |||
| 111 | dc.x = dc.y = 0; | ||
| 112 | dc.w = bw; | ||
| 113 | drawtext(NULL, !istile, False); | ||
| 114 | |||
| 115 | dc.w = 0; | ||
| 116 | for(i = 0; i < TLast; i++) { | ||
| 117 | dc.x += dc.w; | ||
| 118 | dc.w = textw(tags[i]); | ||
| 119 | if(istile) | ||
| 120 | drawtext(tags[i], (i == tsel), True); | ||
| 121 | else | ||
| 122 | drawtext(tags[i], (i != tsel), True); | ||
| 123 | } | ||
| 124 | if(sel) { | ||
| 125 | dc.x += dc.w; | ||
| 126 | dc.w = textw(sel->name); | ||
| 127 | drawtext(sel->name, istile, True); | ||
| 128 | } | ||
| 129 | dc.w = textw(stext); | ||
| 130 | dc.x = bx + bw - dc.w; | ||
| 131 | drawtext(stext, !istile, False); | ||
| 132 | |||
| 133 | XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0); | ||
| 134 | XFlush(dpy); | ||
| 135 | } | ||
| 136 | |||
| 126 | void | 137 | void |
| 127 | drawtitle(Client *c) | 138 | drawtitle(Client *c) |
| 128 | { | 139 | { |
| @@ -219,17 +230,6 @@ setfont(const char *fontstr) | |||
| 219 | } | 230 | } |
| 220 | 231 | ||
| 221 | unsigned int | 232 | unsigned int |
| 222 | textnw(char *text, unsigned int len) | ||
| 223 | { | ||
| 224 | XRectangle r; | ||
| 225 | if(dc.font.set) { | ||
| 226 | XmbTextExtents(dc.font.set, text, len, NULL, &r); | ||
| 227 | return r.width; | ||
| 228 | } | ||
| 229 | return XTextWidth(dc.font.xfont, text, len); | ||
| 230 | } | ||
| 231 | |||
| 232 | unsigned int | ||
| 233 | textw(char *text) | 233 | textw(char *text) |
| 234 | { | 234 | { |
| 235 | return textnw(text, strlen(text)) + dc.font.height; | 235 | return textnw(text, strlen(text)) + dc.font.height; |
| @@ -89,7 +89,7 @@ struct Key { | |||
| 89 | 89 | ||
| 90 | extern Display *dpy; | 90 | extern Display *dpy; |
| 91 | extern Window root, barwin; | 91 | extern Window root, barwin; |
| 92 | extern Atom wm_atom[WMLast], net_atom[NetLast]; | 92 | extern Atom wmatom[WMLast], netatom[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 *); |
| @@ -124,11 +124,9 @@ extern void zoom(Arg *arg); | |||
| 124 | /* draw.c */ | 124 | /* draw.c */ |
| 125 | extern void drawall(); | 125 | extern void drawall(); |
| 126 | extern void drawstatus(); | 126 | extern void drawstatus(); |
| 127 | extern void drawtext(const char *text, Bool invert, Bool border); | ||
| 128 | extern void drawtitle(Client *c); | 127 | extern void drawtitle(Client *c); |
| 129 | extern unsigned long getcolor(const char *colstr); | 128 | extern unsigned long getcolor(const char *colstr); |
| 130 | extern void setfont(const char *fontstr); | 129 | extern void setfont(const char *fontstr); |
| 131 | extern unsigned int textnw(char *text, unsigned int len); | ||
| 132 | extern unsigned int textw(char *text); | 130 | extern unsigned int textw(char *text); |
| 133 | 131 | ||
| 134 | /* event.c */ | 132 | /* event.c */ |
| @@ -51,8 +51,73 @@ Key key[] = { | |||
| 51 | 51 | ||
| 52 | /* static functions */ | 52 | /* static functions */ |
| 53 | 53 | ||
| 54 | static void movemouse(Client *c); | 54 | static void |
| 55 | static void resizemouse(Client *c); | 55 | movemouse(Client *c) |
| 56 | { | ||
| 57 | XEvent ev; | ||
| 58 | int x1, y1, ocx, ocy, di; | ||
| 59 | unsigned int dui; | ||
| 60 | Window dummy; | ||
| 61 | |||
| 62 | ocx = c->x; | ||
| 63 | ocy = c->y; | ||
| 64 | if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, | ||
| 65 | None, cursor[CurMove], CurrentTime) != GrabSuccess) | ||
| 66 | return; | ||
| 67 | XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); | ||
| 68 | for(;;) { | ||
| 69 | XMaskEvent(dpy, MouseMask | ExposureMask, &ev); | ||
| 70 | switch (ev.type) { | ||
| 71 | default: break; | ||
| 72 | case Expose: | ||
| 73 | handler[Expose](&ev); | ||
| 74 | break; | ||
| 75 | case MotionNotify: | ||
| 76 | XFlush(dpy); | ||
| 77 | c->x = ocx + (ev.xmotion.x - x1); | ||
| 78 | c->y = ocy + (ev.xmotion.y - y1); | ||
| 79 | resize(c, False); | ||
| 80 | break; | ||
| 81 | case ButtonRelease: | ||
| 82 | XUngrabPointer(dpy, CurrentTime); | ||
| 83 | return; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | static void | ||
| 89 | resizemouse(Client *c) | ||
| 90 | { | ||
| 91 | XEvent ev; | ||
| 92 | int ocx, ocy; | ||
| 93 | |||
| 94 | ocx = c->x; | ||
| 95 | ocy = c->y; | ||
| 96 | if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, | ||
| 97 | None, cursor[CurResize], CurrentTime) != GrabSuccess) | ||
| 98 | return; | ||
| 99 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); | ||
| 100 | for(;;) { | ||
| 101 | XMaskEvent(dpy, MouseMask | ExposureMask, &ev); | ||
| 102 | switch(ev.type) { | ||
| 103 | default: break; | ||
| 104 | case Expose: | ||
| 105 | handler[Expose](&ev); | ||
| 106 | break; | ||
| 107 | case MotionNotify: | ||
| 108 | XFlush(dpy); | ||
| 109 | c->w = abs(ocx - ev.xmotion.x); | ||
| 110 | c->h = abs(ocy - ev.xmotion.y); | ||
| 111 | c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w; | ||
| 112 | c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h; | ||
| 113 | resize(c, True); | ||
| 114 | break; | ||
| 115 | case ButtonRelease: | ||
| 116 | XUngrabPointer(dpy, CurrentTime); | ||
| 117 | return; | ||
| 118 | } | ||
| 119 | } | ||
| 120 | } | ||
| 56 | 121 | ||
| 57 | static void | 122 | static void |
| 58 | buttonpress(XEvent *e) | 123 | buttonpress(XEvent *e) |
| @@ -214,40 +279,6 @@ maprequest(XEvent *e) | |||
| 214 | } | 279 | } |
| 215 | 280 | ||
| 216 | static void | 281 | static void |
| 217 | movemouse(Client *c) | ||
| 218 | { | ||
| 219 | XEvent ev; | ||
| 220 | int x1, y1, ocx, ocy, di; | ||
| 221 | unsigned int dui; | ||
| 222 | Window dummy; | ||
| 223 | |||
| 224 | ocx = c->x; | ||
| 225 | ocy = c->y; | ||
| 226 | if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, | ||
| 227 | None, cursor[CurMove], CurrentTime) != GrabSuccess) | ||
| 228 | return; | ||
| 229 | XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); | ||
| 230 | for(;;) { | ||
| 231 | XMaskEvent(dpy, MouseMask | ExposureMask, &ev); | ||
| 232 | switch (ev.type) { | ||
| 233 | default: break; | ||
| 234 | case Expose: | ||
| 235 | handler[Expose](&ev); | ||
| 236 | break; | ||
| 237 | case MotionNotify: | ||
| 238 | XFlush(dpy); | ||
| 239 | c->x = ocx + (ev.xmotion.x - x1); | ||
| 240 | c->y = ocy + (ev.xmotion.y - y1); | ||
| 241 | resize(c, False); | ||
| 242 | break; | ||
| 243 | case ButtonRelease: | ||
| 244 | XUngrabPointer(dpy, CurrentTime); | ||
| 245 | return; | ||
| 246 | } | ||
| 247 | } | ||
| 248 | } | ||
| 249 | |||
| 250 | static void | ||
| 251 | propertynotify(XEvent *e) | 282 | propertynotify(XEvent *e) |
| 252 | { | 283 | { |
| 253 | XPropertyEvent *ev = &e->xproperty; | 284 | XPropertyEvent *ev = &e->xproperty; |
| @@ -258,7 +289,7 @@ propertynotify(XEvent *e) | |||
| 258 | return; /* ignore */ | 289 | return; /* ignore */ |
| 259 | 290 | ||
| 260 | if((c = getclient(ev->window))) { | 291 | if((c = getclient(ev->window))) { |
| 261 | if(ev->atom == wm_atom[WMProtocols]) { | 292 | if(ev->atom == wmatom[WMProtocols]) { |
| 262 | c->proto = getproto(c->win); | 293 | c->proto = getproto(c->win); |
| 263 | return; | 294 | return; |
| 264 | } | 295 | } |
| @@ -273,7 +304,7 @@ propertynotify(XEvent *e) | |||
| 273 | setsize(c); | 304 | setsize(c); |
| 274 | break; | 305 | break; |
| 275 | } | 306 | } |
| 276 | if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) { | 307 | if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { |
| 277 | settitle(c); | 308 | settitle(c); |
| 278 | drawtitle(c); | 309 | drawtitle(c); |
| 279 | } | 310 | } |
| @@ -281,40 +312,6 @@ propertynotify(XEvent *e) | |||
| 281 | } | 312 | } |
| 282 | 313 | ||
| 283 | static void | 314 | static void |
| 284 | resizemouse(Client *c) | ||
| 285 | { | ||
| 286 | XEvent ev; | ||
| 287 | int ocx, ocy; | ||
| 288 | |||
| 289 | ocx = c->x; | ||
| 290 | ocy = c->y; | ||
| 291 | if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, | ||
| 292 | None, cursor[CurResize], CurrentTime) != GrabSuccess) | ||
| 293 | return; | ||
| 294 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); | ||
| 295 | for(;;) { | ||
| 296 | XMaskEvent(dpy, MouseMask | ExposureMask, &ev); | ||
| 297 | switch(ev.type) { | ||
| 298 | default: break; | ||
| 299 | case Expose: | ||
| 300 | handler[Expose](&ev); | ||
| 301 | break; | ||
| 302 | case MotionNotify: | ||
| 303 | XFlush(dpy); | ||
| 304 | c->w = abs(ocx - ev.xmotion.x); | ||
| 305 | c->h = abs(ocy - ev.xmotion.y); | ||
| 306 | c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w; | ||
| 307 | c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h; | ||
| 308 | resize(c, True); | ||
| 309 | break; | ||
| 310 | case ButtonRelease: | ||
| 311 | XUngrabPointer(dpy, CurrentTime); | ||
| 312 | return; | ||
| 313 | } | ||
| 314 | } | ||
| 315 | } | ||
| 316 | |||
| 317 | static void | ||
| 318 | unmapnotify(XEvent *e) | 315 | unmapnotify(XEvent *e) |
| 319 | { | 316 | { |
| 320 | Client *c; | 317 | Client *c; |
| @@ -16,10 +16,10 @@ | |||
| 16 | 16 | ||
| 17 | Display *dpy; | 17 | Display *dpy; |
| 18 | Window root, barwin; | 18 | Window root, barwin; |
| 19 | Atom wm_atom[WMLast], net_atom[NetLast]; | 19 | Atom wmatom[WMLast], netatom[NetLast]; |
| 20 | Cursor cursor[CurLast]; | 20 | Cursor cursor[CurLast]; |
| 21 | Bool running = True; | 21 | Bool running = True; |
| 22 | Bool issel; | 22 | Bool issel = True; |
| 23 | 23 | ||
| 24 | int tsel = Tdev; /* default tag */ | 24 | int tsel = Tdev; /* default tag */ |
| 25 | int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; | 25 | int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; |
| @@ -30,8 +30,6 @@ Client *clients = NULL; | |||
| 30 | Client *sel = NULL; | 30 | Client *sel = NULL; |
| 31 | 31 | ||
| 32 | static Bool otherwm; | 32 | static Bool otherwm; |
| 33 | static const char version[] = | ||
| 34 | "dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; | ||
| 35 | static int (*xerrorxlib)(Display *, XErrorEvent *); | 33 | static int (*xerrorxlib)(Display *, XErrorEvent *); |
| 36 | 34 | ||
| 37 | /* static functions */ | 35 | /* static functions */ |
| @@ -109,12 +107,12 @@ getproto(Window w) | |||
| 109 | int protos = 0; | 107 | int protos = 0; |
| 110 | int i; | 108 | int i; |
| 111 | 109 | ||
| 112 | res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, &protocols); | 110 | res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L, &protocols); |
| 113 | if(res <= 0) { | 111 | if(res <= 0) { |
| 114 | return protos; | 112 | return protos; |
| 115 | } | 113 | } |
| 116 | for(i = 0; i < res; i++) { | 114 | for(i = 0; i < res; i++) { |
| 117 | if(protocols[i] == wm_atom[WMDelete]) | 115 | if(protocols[i] == wmatom[WMDelete]) |
| 118 | protos |= WM_PROTOCOL_DELWIN; | 116 | protos |= WM_PROTOCOL_DELWIN; |
| 119 | } | 117 | } |
| 120 | free((char *) protocols); | 118 | free((char *) protocols); |
| @@ -184,7 +182,8 @@ main(int argc, char *argv[]) | |||
| 184 | for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { | 182 | for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { |
| 185 | switch (argv[i][1]) { | 183 | switch (argv[i][1]) { |
| 186 | case 'v': | 184 | case 'v': |
| 187 | fprintf(stdout, "%s", version); | 185 | fprintf(stdout, "%s", |
| 186 | "dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n"); | ||
| 188 | exit(0); | 187 | exit(0); |
| 189 | break; | 188 | break; |
| 190 | default: | 189 | default: |
| @@ -214,12 +213,12 @@ main(int argc, char *argv[]) | |||
| 214 | xerrorxlib = XSetErrorHandler(xerror); | 213 | xerrorxlib = XSetErrorHandler(xerror); |
| 215 | 214 | ||
| 216 | /* init atoms */ | 215 | /* init atoms */ |
| 217 | wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); | 216 | wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); |
| 218 | wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); | 217 | wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
| 219 | net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); | 218 | netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); |
| 220 | net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); | 219 | netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); |
| 221 | XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32, | 220 | XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, |
| 222 | PropModeReplace, (unsigned char *) net_atom, NetLast); | 221 | PropModeReplace, (unsigned char *) netatom, NetLast); |
| 223 | 222 | ||
| 224 | /* init cursors */ | 223 | /* init cursors */ |
| 225 | cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); | 224 | cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); |
