aewl
changeset 77:38c8f7f7d401
sanitized other stuff
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Sat, 15 Jul 2006 17:19:19 +0200 |
parents | 4bd49f404f10 |
children | 0d71fb80b592 |
files | client.c draw.c dwm.h event.c main.c |
diffstat | 5 files changed, 137 insertions(+), 143 deletions(-) [+] |
line diff
1.1 --- a/client.c Sat Jul 15 17:00:56 2006 +0200 1.2 +++ b/client.c Sat Jul 15 17:19:19 2006 +0200 1.3 @@ -178,7 +178,7 @@ 1.4 if(!sel) 1.5 return; 1.6 if(sel->proto & WM_PROTOCOL_DELWIN) 1.7 - sendevent(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]); 1.8 + sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]); 1.9 else 1.10 XKillClient(dpy, sel->win); 1.11 } 1.12 @@ -353,7 +353,7 @@ 1.13 1.14 name.nitems = 0; 1.15 c->name[0] = 0; 1.16 - XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]); 1.17 + XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]); 1.18 if(!name.nitems) 1.19 XGetWMName(dpy, c->win, &name); 1.20 if(!name.nitems)
2.1 --- a/draw.c Sat Jul 15 17:00:56 2006 +0200 2.2 +++ b/draw.c Sat Jul 15 17:19:19 2006 +0200 2.3 @@ -29,51 +29,18 @@ 2.4 XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); 2.5 } 2.6 2.7 -/* extern functions */ 2.8 - 2.9 -void 2.10 -drawall() 2.11 +static unsigned int 2.12 +textnw(char *text, unsigned int len) 2.13 { 2.14 - Client *c; 2.15 - 2.16 - for(c = clients; c; c = getnext(c->next)) 2.17 - drawtitle(c); 2.18 - drawstatus(); 2.19 + XRectangle r; 2.20 + if(dc.font.set) { 2.21 + XmbTextExtents(dc.font.set, text, len, NULL, &r); 2.22 + return r.width; 2.23 + } 2.24 + return XTextWidth(dc.font.xfont, text, len); 2.25 } 2.26 2.27 -void 2.28 -drawstatus() 2.29 -{ 2.30 - int i; 2.31 - Bool istile = arrange == dotile; 2.32 - 2.33 - dc.x = dc.y = 0; 2.34 - dc.w = bw; 2.35 - drawtext(NULL, !istile, False); 2.36 - 2.37 - dc.w = 0; 2.38 - for(i = 0; i < TLast; i++) { 2.39 - dc.x += dc.w; 2.40 - dc.w = textw(tags[i]); 2.41 - if(istile) 2.42 - drawtext(tags[i], (i == tsel), True); 2.43 - else 2.44 - drawtext(tags[i], (i != tsel), True); 2.45 - } 2.46 - if(sel) { 2.47 - dc.x += dc.w; 2.48 - dc.w = textw(sel->name); 2.49 - drawtext(sel->name, istile, True); 2.50 - } 2.51 - dc.w = textw(stext); 2.52 - dc.x = bx + bw - dc.w; 2.53 - drawtext(stext, !istile, False); 2.54 - 2.55 - XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0); 2.56 - XFlush(dpy); 2.57 -} 2.58 - 2.59 -void 2.60 +static void 2.61 drawtext(const char *text, Bool invert, Bool border) 2.62 { 2.63 int x, y, w, h; 2.64 @@ -123,6 +90,50 @@ 2.65 } 2.66 } 2.67 2.68 +/* extern functions */ 2.69 + 2.70 +void 2.71 +drawall() 2.72 +{ 2.73 + Client *c; 2.74 + 2.75 + for(c = clients; c; c = getnext(c->next)) 2.76 + drawtitle(c); 2.77 + drawstatus(); 2.78 +} 2.79 + 2.80 +void 2.81 +drawstatus() 2.82 +{ 2.83 + int i; 2.84 + Bool istile = arrange == dotile; 2.85 + 2.86 + dc.x = dc.y = 0; 2.87 + dc.w = bw; 2.88 + drawtext(NULL, !istile, False); 2.89 + 2.90 + dc.w = 0; 2.91 + for(i = 0; i < TLast; i++) { 2.92 + dc.x += dc.w; 2.93 + dc.w = textw(tags[i]); 2.94 + if(istile) 2.95 + drawtext(tags[i], (i == tsel), True); 2.96 + else 2.97 + drawtext(tags[i], (i != tsel), True); 2.98 + } 2.99 + if(sel) { 2.100 + dc.x += dc.w; 2.101 + dc.w = textw(sel->name); 2.102 + drawtext(sel->name, istile, True); 2.103 + } 2.104 + dc.w = textw(stext); 2.105 + dc.x = bx + bw - dc.w; 2.106 + drawtext(stext, !istile, False); 2.107 + 2.108 + XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0); 2.109 + XFlush(dpy); 2.110 +} 2.111 + 2.112 void 2.113 drawtitle(Client *c) 2.114 { 2.115 @@ -219,17 +230,6 @@ 2.116 } 2.117 2.118 unsigned int 2.119 -textnw(char *text, unsigned int len) 2.120 -{ 2.121 - XRectangle r; 2.122 - if(dc.font.set) { 2.123 - XmbTextExtents(dc.font.set, text, len, NULL, &r); 2.124 - return r.width; 2.125 - } 2.126 - return XTextWidth(dc.font.xfont, text, len); 2.127 -} 2.128 - 2.129 -unsigned int 2.130 textw(char *text) 2.131 { 2.132 return textnw(text, strlen(text)) + dc.font.height;
3.1 --- a/dwm.h Sat Jul 15 17:00:56 2006 +0200 3.2 +++ b/dwm.h Sat Jul 15 17:19:19 2006 +0200 3.3 @@ -89,7 +89,7 @@ 3.4 3.5 extern Display *dpy; 3.6 extern Window root, barwin; 3.7 -extern Atom wm_atom[WMLast], net_atom[NetLast]; 3.8 +extern Atom wmatom[WMLast], netatom[NetLast]; 3.9 extern Cursor cursor[CurLast]; 3.10 extern Bool running, issel; 3.11 extern void (*handler[LASTEvent])(XEvent *); 3.12 @@ -124,11 +124,9 @@ 3.13 /* draw.c */ 3.14 extern void drawall(); 3.15 extern void drawstatus(); 3.16 -extern void drawtext(const char *text, Bool invert, Bool border); 3.17 extern void drawtitle(Client *c); 3.18 extern unsigned long getcolor(const char *colstr); 3.19 extern void setfont(const char *fontstr); 3.20 -extern unsigned int textnw(char *text, unsigned int len); 3.21 extern unsigned int textw(char *text); 3.22 3.23 /* event.c */
4.1 --- a/event.c Sat Jul 15 17:00:56 2006 +0200 4.2 +++ b/event.c Sat Jul 15 17:19:19 2006 +0200 4.3 @@ -51,8 +51,73 @@ 4.4 4.5 /* static functions */ 4.6 4.7 -static void movemouse(Client *c); 4.8 -static void resizemouse(Client *c); 4.9 +static void 4.10 +movemouse(Client *c) 4.11 +{ 4.12 + XEvent ev; 4.13 + int x1, y1, ocx, ocy, di; 4.14 + unsigned int dui; 4.15 + Window dummy; 4.16 + 4.17 + ocx = c->x; 4.18 + ocy = c->y; 4.19 + if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 4.20 + None, cursor[CurMove], CurrentTime) != GrabSuccess) 4.21 + return; 4.22 + XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); 4.23 + for(;;) { 4.24 + XMaskEvent(dpy, MouseMask | ExposureMask, &ev); 4.25 + switch (ev.type) { 4.26 + default: break; 4.27 + case Expose: 4.28 + handler[Expose](&ev); 4.29 + break; 4.30 + case MotionNotify: 4.31 + XFlush(dpy); 4.32 + c->x = ocx + (ev.xmotion.x - x1); 4.33 + c->y = ocy + (ev.xmotion.y - y1); 4.34 + resize(c, False); 4.35 + break; 4.36 + case ButtonRelease: 4.37 + XUngrabPointer(dpy, CurrentTime); 4.38 + return; 4.39 + } 4.40 + } 4.41 +} 4.42 + 4.43 +static void 4.44 +resizemouse(Client *c) 4.45 +{ 4.46 + XEvent ev; 4.47 + int ocx, ocy; 4.48 + 4.49 + ocx = c->x; 4.50 + ocy = c->y; 4.51 + if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 4.52 + None, cursor[CurResize], CurrentTime) != GrabSuccess) 4.53 + return; 4.54 + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); 4.55 + for(;;) { 4.56 + XMaskEvent(dpy, MouseMask | ExposureMask, &ev); 4.57 + switch(ev.type) { 4.58 + default: break; 4.59 + case Expose: 4.60 + handler[Expose](&ev); 4.61 + break; 4.62 + case MotionNotify: 4.63 + XFlush(dpy); 4.64 + c->w = abs(ocx - ev.xmotion.x); 4.65 + c->h = abs(ocy - ev.xmotion.y); 4.66 + c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w; 4.67 + c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h; 4.68 + resize(c, True); 4.69 + break; 4.70 + case ButtonRelease: 4.71 + XUngrabPointer(dpy, CurrentTime); 4.72 + return; 4.73 + } 4.74 + } 4.75 +} 4.76 4.77 static void 4.78 buttonpress(XEvent *e) 4.79 @@ -214,40 +279,6 @@ 4.80 } 4.81 4.82 static void 4.83 -movemouse(Client *c) 4.84 -{ 4.85 - XEvent ev; 4.86 - int x1, y1, ocx, ocy, di; 4.87 - unsigned int dui; 4.88 - Window dummy; 4.89 - 4.90 - ocx = c->x; 4.91 - ocy = c->y; 4.92 - if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 4.93 - None, cursor[CurMove], CurrentTime) != GrabSuccess) 4.94 - return; 4.95 - XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); 4.96 - for(;;) { 4.97 - XMaskEvent(dpy, MouseMask | ExposureMask, &ev); 4.98 - switch (ev.type) { 4.99 - default: break; 4.100 - case Expose: 4.101 - handler[Expose](&ev); 4.102 - break; 4.103 - case MotionNotify: 4.104 - XFlush(dpy); 4.105 - c->x = ocx + (ev.xmotion.x - x1); 4.106 - c->y = ocy + (ev.xmotion.y - y1); 4.107 - resize(c, False); 4.108 - break; 4.109 - case ButtonRelease: 4.110 - XUngrabPointer(dpy, CurrentTime); 4.111 - return; 4.112 - } 4.113 - } 4.114 -} 4.115 - 4.116 -static void 4.117 propertynotify(XEvent *e) 4.118 { 4.119 XPropertyEvent *ev = &e->xproperty; 4.120 @@ -258,7 +289,7 @@ 4.121 return; /* ignore */ 4.122 4.123 if((c = getclient(ev->window))) { 4.124 - if(ev->atom == wm_atom[WMProtocols]) { 4.125 + if(ev->atom == wmatom[WMProtocols]) { 4.126 c->proto = getproto(c->win); 4.127 return; 4.128 } 4.129 @@ -273,7 +304,7 @@ 4.130 setsize(c); 4.131 break; 4.132 } 4.133 - if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) { 4.134 + if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { 4.135 settitle(c); 4.136 drawtitle(c); 4.137 } 4.138 @@ -281,40 +312,6 @@ 4.139 } 4.140 4.141 static void 4.142 -resizemouse(Client *c) 4.143 -{ 4.144 - XEvent ev; 4.145 - int ocx, ocy; 4.146 - 4.147 - ocx = c->x; 4.148 - ocy = c->y; 4.149 - if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 4.150 - None, cursor[CurResize], CurrentTime) != GrabSuccess) 4.151 - return; 4.152 - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); 4.153 - for(;;) { 4.154 - XMaskEvent(dpy, MouseMask | ExposureMask, &ev); 4.155 - switch(ev.type) { 4.156 - default: break; 4.157 - case Expose: 4.158 - handler[Expose](&ev); 4.159 - break; 4.160 - case MotionNotify: 4.161 - XFlush(dpy); 4.162 - c->w = abs(ocx - ev.xmotion.x); 4.163 - c->h = abs(ocy - ev.xmotion.y); 4.164 - c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w; 4.165 - c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h; 4.166 - resize(c, True); 4.167 - break; 4.168 - case ButtonRelease: 4.169 - XUngrabPointer(dpy, CurrentTime); 4.170 - return; 4.171 - } 4.172 - } 4.173 -} 4.174 - 4.175 -static void 4.176 unmapnotify(XEvent *e) 4.177 { 4.178 Client *c;
5.1 --- a/main.c Sat Jul 15 17:00:56 2006 +0200 5.2 +++ b/main.c Sat Jul 15 17:19:19 2006 +0200 5.3 @@ -16,10 +16,10 @@ 5.4 5.5 Display *dpy; 5.6 Window root, barwin; 5.7 -Atom wm_atom[WMLast], net_atom[NetLast]; 5.8 +Atom wmatom[WMLast], netatom[NetLast]; 5.9 Cursor cursor[CurLast]; 5.10 Bool running = True; 5.11 -Bool issel; 5.12 +Bool issel = True; 5.13 5.14 int tsel = Tdev; /* default tag */ 5.15 int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; 5.16 @@ -30,8 +30,6 @@ 5.17 Client *sel = NULL; 5.18 5.19 static Bool otherwm; 5.20 -static const char version[] = 5.21 - "dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; 5.22 static int (*xerrorxlib)(Display *, XErrorEvent *); 5.23 5.24 /* static functions */ 5.25 @@ -109,12 +107,12 @@ 5.26 int protos = 0; 5.27 int i; 5.28 5.29 - res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, &protocols); 5.30 + res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L, &protocols); 5.31 if(res <= 0) { 5.32 return protos; 5.33 } 5.34 for(i = 0; i < res; i++) { 5.35 - if(protocols[i] == wm_atom[WMDelete]) 5.36 + if(protocols[i] == wmatom[WMDelete]) 5.37 protos |= WM_PROTOCOL_DELWIN; 5.38 } 5.39 free((char *) protocols); 5.40 @@ -184,7 +182,8 @@ 5.41 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { 5.42 switch (argv[i][1]) { 5.43 case 'v': 5.44 - fprintf(stdout, "%s", version); 5.45 + fprintf(stdout, "%s", 5.46 + "dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n"); 5.47 exit(0); 5.48 break; 5.49 default: 5.50 @@ -214,12 +213,12 @@ 5.51 xerrorxlib = XSetErrorHandler(xerror); 5.52 5.53 /* init atoms */ 5.54 - wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); 5.55 - wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); 5.56 - net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); 5.57 - net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); 5.58 - XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32, 5.59 - PropModeReplace, (unsigned char *) net_atom, NetLast); 5.60 + wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); 5.61 + wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); 5.62 + netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); 5.63 + netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); 5.64 + XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, 5.65 + PropModeReplace, (unsigned char *) netatom, NetLast); 5.66 5.67 /* init cursors */ 5.68 cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);