JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Add unusual paranoia to make sure we crash and dump core if we see any
[spectrwm.git] / scrotwm.c
index 3f1566a..ad295f7 100644 (file)
--- a/scrotwm.c
+++ b/scrotwm.c
@@ -52,7 +52,7 @@
 
 static const char      *cvstag = "$scrotwm$";
 
-#define        SWM_VERSION     "1.0"
+#define        SWM_VERSION     "0.9.11"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -941,6 +941,7 @@ set_win_state(struct ws_win *win, long state)
        long                    data[] = {state, None};
        XEvent                  ev;
        XWindowAttributes       wa;
+       int                     putback;
 
        DNPRINTF(SWM_D_EVENT, "set_win_state: window: %lu\n", win->id);
 
@@ -957,8 +958,11 @@ set_win_state(struct ws_win *win, long state)
            (unsigned char *)data, 2);
 
        /* wait for completion of XChangeProperty */
+       putback = 0;
        while (XCheckIfEvent(display, &ev, set_win_notify_cb, (char *)win))
-               ;
+               putback = 1;
+       if (putback)
+               XPutBackEvent(display, &ev);
 }
 
 long
@@ -997,6 +1001,9 @@ client_msg(struct ws_win *win, Atom a)
 {
        XClientMessageEvent     cm;
 
+       if (win == NULL)
+               return;
+
        bzero(&cm, sizeof cm);
        cm.type = ClientMessage;
        cm.window = win->id;
@@ -1014,6 +1021,10 @@ config_win(struct ws_win *win)
 
        DNPRINTF(SWM_D_MISC, "config_win: win %lu x %d y %d w %d h %d\n",
            win->id, win->g.x, win->g.y, win->g.w, win->g.h);
+
+       if (win == NULL)
+               return;
+
        ce.type = ConfigureNotify;
        ce.display = display;
        ce.event = win->id;
@@ -1083,6 +1094,7 @@ unmap_window(struct ws_win *win)
 {
        XEvent                  ev;
        XWindowAttributes       wa;
+       int                     putback;
 
        if (win == NULL)
                return;
@@ -1102,8 +1114,11 @@ unmap_window(struct ws_win *win)
        XUnmapWindow(display, win->id);
 
        /* make sure we wait for XUnmapWindow completion */
+       putback = 0;
        while (XCheckIfEvent(display, &ev, unmap_window_cb, (char *)win))
-               ;
+               putback = 1;
+       if (putback)
+               XPutBackEvent(display, &ev);
 }
 
 void
@@ -1123,6 +1138,9 @@ fake_keypress(struct ws_win *win, int keysym, int modifiers)
 {
        XKeyEvent event;
 
+       if (win == NULL)
+               return;
+
        event.display = display;        /* Ignored, but what the hell */
        event.window = win->id;
        event.root = win->s->root;
@@ -1261,7 +1279,8 @@ unfocus_win(struct ws_win *win)
 {
        if (win == NULL)
                return;
-
+       if (win->ws == NULL)
+               return;
        if (win->ws->r == NULL)
                return;
 
@@ -1296,6 +1315,8 @@ focus_win(struct ws_win *win)
 
        if (win == NULL)
                return;
+       if (win->ws == NULL)
+               return;
 
        /* use big hammer to make sure it works under all use cases */
        unfocus_all();
@@ -1321,6 +1342,15 @@ switchws(struct swm_region *r, union arg *args)
        struct ws_win           *win, *winfocus = NULL, *parent = NULL;
        struct workspace        *new_ws, *old_ws;
 
+       if (!(r && r->s)) {
+               fprintf(stderr, "r && r->s failed\n");
+               abort();
+       }
+       if (wsid < 0 || wsid > SWM_WS_MAX) {
+               fprintf(stderr, "illegal wsid\n");
+               abort();
+       }
+
        this_r = r;
        old_ws = this_r->ws;
        new_ws = &this_r->s->ws[wsid];
@@ -1329,6 +1359,11 @@ switchws(struct swm_region *r, union arg *args)
            "%d -> %d\n", r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r),
            old_ws->idx, wsid);
 
+       if (new_ws == NULL || old_ws == NULL) {
+               fprintf(stderr, "new_ws = %p old_ws = %p\n", new_ws, old_ws);
+               abort();
+       }
+
        if (new_ws == old_ws)
                return;
 
@@ -1638,6 +1673,10 @@ stack(void) {
                            "(screen %d, region %d)\n", r->ws->idx, i, j++);
 
                        /* start with screen geometry, adjust for bar */
+                       if (r == NULL) {
+                               fprintf(stderr, "illegal r\n");
+                               abort();
+                       }
                        g = r->g;
                        g.w -= 2;
                        g.h -= 2;
@@ -1645,8 +1684,19 @@ stack(void) {
                                g.y += bar_height;
                                g.h -= bar_height;
                        }
-
+                       if (r->ws == NULL) {
+                               fprintf(stderr, "illegal ws\n");
+                               abort();
+                       }
+                       if (r->ws->cur_layout == NULL) {
+                               fprintf(stderr, "illegal cur_layout\n");
+                               abort();
+                       }
                        r->ws->restack = 0;
+                       if (r->ws->cur_layout->l_stack == NULL) {
+                               fprintf(stderr, "illegal l_stack\n");
+                               abort();
+                       }
                        r->ws->cur_layout->l_stack(r->ws, &g);
                }
        }
@@ -3444,8 +3494,6 @@ manage_window(Window id)
                }
        }
 
-       if (win->java && win->transient) {
-       }
        /* alter window position if quirky */
        if (win->quirks & SWM_Q_ANYWHERE) {
                win->manual = 1; /* don't center the quirky windows */
@@ -3501,6 +3549,9 @@ unmanage_window(struct ws_win *win)
 
        DNPRINTF(SWM_D_MISC, "unmanage_window:  %lu\n", win->id);
 
+       /* needed for restart wm */
+       set_win_state(win, WithdrawnState);
+
        if (win->transient) {
                parent = find_window(win->transient);
                if (parent)
@@ -4183,7 +4234,6 @@ setup_screens(void)
                /* attach windows to a region */
                /* normal windows */
                for (j = 0; j < no; j++) {
-                        XGetWindowAttributes(display, wins[j], &wa);
                        if (!XGetWindowAttributes(display, wins[j], &wa) ||
                            wa.override_redirect ||
                            XGetTransientForHint(display, wins[j], &d1))
@@ -4196,7 +4246,8 @@ setup_screens(void)
                }
                /* transient windows */
                for (j = 0; j < no; j++) {
-                       if (!XGetWindowAttributes(display, wins[j], &wa))
+                       if (!XGetWindowAttributes(display, wins[j], &wa) ||
+                           wa.override_redirect)
                                continue;
 
                        state = getstate(wins[j]);