diff --git a/calmwm.h b/calmwm.h index 867f3ad..f62014b 100644 --- a/calmwm.h +++ b/calmwm.h @@ -455,6 +455,7 @@ struct geom screen_area(struct screen_ctx *, int, int, int); void screen_init(int); void screen_update_geometry(struct screen_ctx *); void screen_updatestackingorder(struct screen_ctx *); +void screen_assert_clients_within(struct screen_ctx *); void kbfunc_client_cycle(struct client_ctx *, union arg *); void kbfunc_client_delete(struct client_ctx *, union arg *); diff --git a/screen.c b/screen.c index 79e7cc5..b9f1ac9 100644 --- a/screen.c +++ b/screen.c @@ -229,3 +229,26 @@ screen_apply_gap(struct screen_ctx *sc, struct geom geom) return(geom); } + +/* Bring back clients which are beyond the screen. */ +void +screen_assert_clients_within(struct screen_ctx *sc) +{ + struct client_ctx *cc; + int top, left, right, bottom; + + TAILQ_FOREACH(cc, &sc->clientq, entry) { + if (cc->sc != sc) + continue; + top = cc->geom.y; + left = cc->geom.x; + right = cc->geom.x + cc->geom.w + (cc->bwidth * 2) - 1; + bottom = cc->geom.y + cc->geom.h + (cc->bwidth * 2) - 1; + if ((top > sc->view.h || left > sc->view.w) || + (bottom < 0 || right < 0)) { + cc->geom.x = sc->gap.left; + cc->geom.y = sc->gap.top; + client_move(cc); + } + } +} diff --git a/xevents.c b/xevents.c index a4ff04d..3dab168 100644 --- a/xevents.c +++ b/xevents.c @@ -386,6 +386,7 @@ xev_handle_randr(XEvent *ee) if (sc->which == i) { XRRUpdateConfiguration(ee); screen_update_geometry(sc); + screen_assert_clients_within(sc); } } }