JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
shuffle some stuff around to make more sense
[spectrwm.git] / scrotwm.c
index 380eaf1..edcd339 100644 (file)
--- a/scrotwm.c
+++ b/scrotwm.c
@@ -1193,14 +1193,14 @@ unfocus_win(struct ws_win *win)
        if (win->ws->r == NULL)
                return;
 
-       grabbuttons(win, 0);
-       XSetWindowBorder(display, win->id,
-           win->ws->r->s->c[SWM_S_COLOR_UNFOCUS].color);
-
        if (win->ws->focus == win) {
                win->ws->focus = NULL;
                win->ws->focus_prev = win;
        }
+
+       grabbuttons(win, 0);
+       XSetWindowBorder(display, win->id,
+           win->ws->r->s->c[SWM_S_COLOR_UNFOCUS].color);
 }
 
 void
@@ -1233,12 +1233,11 @@ focus_win(struct ws_win *win)
        if (win->ws->r != NULL) {
                XSetWindowBorder(display, win->id,
                    win->ws->r->s->c[SWM_S_COLOR_FOCUS].color);
-               grabbuttons(win, 1);
                if (win->ws->cur_layout->flags & SWM_L_MAPONFOCUS)
                        XMapRaised(display, win->id);
                XSetInputFocus(display, win->id,
                    RevertToPointerRoot, CurrentTime);
-               XSync(display, False);
+               grabbuttons(win, 1);
        }
 }
 
@@ -1353,8 +1352,10 @@ cyclews(struct swm_region *r, union arg *args)
 void
 cyclescr(struct swm_region *r, union arg *args)
 {
-       struct swm_region       *rr;
-       int                     i;
+       struct swm_region       *rr = NULL;
+       struct workspace        *ws = NULL;
+       struct ws_win           *winfocus = NULL;
+       int                     i, x, y;
 
        /* do nothing if we don't have more than one screen */
        if (!(ScreenCount(display) > 1 || outputs > 1))
@@ -1375,10 +1376,28 @@ cyclescr(struct swm_region *r, union arg *args)
        default:
                return;
        };
+       if (rr == NULL)
+               return;
+
+       ws = rr->ws;
+       winfocus = ws->focus;
+       if (winfocus == NULL)
+               winfocus = ws->focus_prev;
+       if (winfocus) {
+               /* use window coordinates */
+               x = winfocus->g.x + 1;
+               y = winfocus->g.y + 1;
+       } else {
+               /* use region coordinates */
+               x = rr->g.x + 1;
+               y = rr->g.y + 1 + bar_enabled ? bar_height : 0;
+       }
+
        unfocus_all();
        XSetInputFocus(display, PointerRoot, RevertToPointerRoot, CurrentTime);
-       XWarpPointer(display, None, rr->s[i].root, 0, 0, 0, 0, rr->g.x + 1,
-           rr->g.y + bar_enabled + 1 ? bar_height : 0);
+       XWarpPointer(display, None, rr->s[i].root, 0, 0, 0, 0, x, y);
+
+       focus_win(winfocus);
 }
 
 void
@@ -1561,7 +1580,6 @@ stack(void) {
        }
        if (font_adjusted)
                font_adjusted--;
-       XSync(display, False);
 }
 
 void
@@ -1976,7 +1994,6 @@ send_to_ws(struct swm_region *r, union arg *args)
                if (ScreenCount(display) > 1 || outputs > 1)
                        winfocus = win;
 
-
        unmap_window(win);
        TAILQ_REMOVE(&ws->winlist, win, entry);
        TAILQ_INSERT_TAIL(&nws->winlist, win, entry);