JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
next version will contain updated copyright notice
[dwm.git] / main.c
diff --git a/main.c b/main.c
index 0f22c44..4406b88 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,9 +1,10 @@
-/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
+/* (C)opyright MMVII Anselm R. Garbe <garbeam at gmail dot com>
  * See LICENSE file for license details.
  */
 
 #include "dwm.h"
 #include <errno.h>
+#include <locale.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -39,9 +40,9 @@ static Bool otherwm, readin;
 static void
 cleanup(void) {
        close(STDIN_FILENO);
-       while(sel) {
-               resize(sel, True, TopLeft);
-               unmanage(sel);
+       while(clients) {
+               resize(clients, True, TopLeft);
+               unmanage(clients);
        }
        if(dc.font.set)
                XFreeFontSet(dpy, dc.font.set);
@@ -51,6 +52,9 @@ cleanup(void) {
        XFreePixmap(dpy, dc.drawable);
        XFreeGC(dpy, dc.gc);
        XDestroyWindow(dpy, barwin);
+       XFreeCursor(dpy, cursor[CurNormal]);
+       XFreeCursor(dpy, cursor[CurResize]);
+       XFreeCursor(dpy, cursor[CurMove]);
        XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
        XSync(dpy, False);
        free(seltag);
@@ -104,7 +108,7 @@ setup(void) {
                                numlockmask = (1 << i);
                }
        }
-       XFree(modmap);
+       XFreeModifiermap(modmap);
        /* select for events */
        wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
                | EnterWindowMask | LeaveWindowMask;
@@ -130,7 +134,8 @@ setup(void) {
        sh = DisplayHeight(dpy, screen);
        master = MASTER;
        /* bar */
-       bx = by = 0;
+       bx = sx;
+       by = sy;
        bw = sw;
        dc.h = bh = dc.font.height + 2;
        wa.override_redirect = 1;
@@ -144,7 +149,7 @@ setup(void) {
        strcpy(stext, "dwm-"VERSION);
        /* windowarea */
        wax = sx;
-       way = bh;
+       way = sy + bh;
        wah = sh - bh;
        waw = sw;
        /* pixmap for everything */
@@ -226,15 +231,17 @@ xerror(Display *dpy, XErrorEvent *ee) {
 
 int
 main(int argc, char *argv[]) {
+       char *p;
        int r, xfd;
        fd_set rd;
 
        if(argc == 2 && !strncmp("-v", argv[1], 3)) {
-               fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
+               fputs("dwm-"VERSION", (C)opyright MMVII Anselm R. Garbe\n", stdout);
                exit(EXIT_SUCCESS);
        }
        else if(argc != 1)
                eprint("usage: dwm [-v]\n");
+       setlocale(LC_CTYPE, "");
        dpy = XOpenDisplay(0);
        if(!dpy)
                eprint("dwm: cannot open display\n");
@@ -266,22 +273,32 @@ main(int argc, char *argv[]) {
                if(readin)
                        FD_SET(STDIN_FILENO, &rd);
                FD_SET(xfd, &rd);
-               r = select(xfd + 1, &rd, NULL, NULL, NULL);
-               if((r == -1) && (errno == EINTR))
-                       continue;
-               if(r > 0) {
-                       if(readin && FD_ISSET(STDIN_FILENO, &rd)) {
-                               readin = NULL != fgets(stext, sizeof(stext), stdin);
-                               if(readin)
-                                       stext[strlen(stext) - 1] = 0;
-                               else 
-                                       strcpy(stext, "broken pipe");
-                               drawstatus();
+               if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
+                       if(errno == EINTR)
+                               continue;
+                       eprint("select failed\n");
+               }
+               if(FD_ISSET(STDIN_FILENO, &rd)) {
+                       switch(r = read(STDIN_FILENO, stext, sizeof stext - 1)) {
+                       case -1:
+                               strncpy(stext, strerror(errno), sizeof stext - 1);
+                               stext[sizeof stext - 1] = '\0';
+                               readin = False;
+                               break;
+                       case 0:
+                               strncpy(stext, "EOF", 4);
+                               readin = False;
+                               break;
+                       default:
+                               for(stext[r] = '\0', p = stext + strlen(stext) - 1; p >= stext && *p == '\n'; *p-- = '\0');
+                               for(p = stext + strlen(stext) - 1; p >= stext && *p != '\n'; --p);
+                               if(p > stext)
+                                       strncpy(stext, p + 1, sizeof stext);
                        }
+                       drawstatus();
                }
-               else if(r < 0)
-                       eprint("select failed\n");
-               procevent();
+               if(FD_ISSET(xfd, &rd))
+                       procevent();
        }
        cleanup();
        XCloseDisplay(dpy);