From f1dd7ceb04c1060cf90e4a3ad4f73824b0295f28 Mon Sep 17 00:00:00 2001 From: Ryan Goniwiecha Date: Mon, 20 Apr 2026 14:01:25 -0400 Subject: [PATCH] snap to half commands --- calmwm.h | 1 + conf.c | 4 ++++ cwmrc.5 | 8 ++++++++ kbfunc.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) diff --git a/calmwm.h b/calmwm.h index 992bc03..fbf5ac3 100644 --- a/calmwm.h +++ b/calmwm.h @@ -519,6 +519,7 @@ void screen_updatestackingorder(struct screen_ctx *); void kbfunc_cwm_status(void *, struct cargs *); void kbfunc_ptrmove(void *, struct cargs *); void kbfunc_client_snap(void *, struct cargs *); +void kbfunc_client_snaptohalf(void *, struct cargs *); void kbfunc_client_move(void *, struct cargs *); void kbfunc_client_resize(void *, struct cargs *); void kbfunc_client_close(void *, struct cargs *); diff --git a/conf.c b/conf.c index 39e4fac..c02943c 100644 --- a/conf.c +++ b/conf.c @@ -107,6 +107,10 @@ static const struct { { FUNC_CC(window-snap-down, client_snap, (CWM_DOWN)) }, { FUNC_CC(window-snap-right, client_snap, (CWM_RIGHT)) }, { FUNC_CC(window-snap-left, client_snap, (CWM_LEFT)) }, + { FUNC_CC(window-snap-up-half, client_snaptohalf, (CWM_UP)) }, + { FUNC_CC(window-snap-down-half, client_snaptohalf, (CWM_DOWN)) }, + { FUNC_CC(window-snap-right-half, client_snaptohalf, (CWM_RIGHT)) }, + { FUNC_CC(window-snap-left-half, client_snaptohalf, (CWM_LEFT)) }, { FUNC_CC(window-snap-up-right, client_snap, (CWM_UP_RIGHT)) }, { FUNC_CC(window-snap-up-left, client_snap, (CWM_UP_LEFT)) }, { FUNC_CC(window-snap-down-right, client_snap, (CWM_DOWN_RIGHT)) }, diff --git a/cwmrc.5 b/cwmrc.5 index a647127..7b44769 100644 --- a/cwmrc.5 +++ b/cwmrc.5 @@ -411,6 +411,14 @@ Snap window to bottom edge. Snap window to right edge. .It window-snap-left Snap window to left edge. +.It window-snap-up-half +Snap and resize window to the top half of the screen. +.It window-snap-down-half +Snap and resize window to the bottom half of the screen. +.It window-snap-right-half +Snap and resize window to the right half of the screen. +.It window-snap-left-half +Snap and resize window to the left half of the screen. .It window-snap-up-right Snap window to top-right corner. .It window-snap-up-left diff --git a/kbfunc.c b/kbfunc.c index 3b435f0..759a79c 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -359,6 +359,62 @@ kbfunc_client_snap(void *ctx, struct cargs *cargs) client_ptr_inbound(cc, 1); } +void +kbfunc_client_snaptohalf(void *ctx, struct cargs *cargs) +{ + struct client_ctx *cc = ctx; + struct screen_ctx *sc = cc->sc; + struct geom area; + int halfw, halfh; + + if (cc->flags & CLIENT_FREEZE) + return; + + area = screen_area(sc, + cc->geom.x + cc->geom.w / 2, + cc->geom.y + cc->geom.h / 2, 1); + halfw = area.w / 2; + halfh = area.h / 2; + + switch (cargs->flag) { + case CWM_UP: + cc->geom.x = area.x; + cc->geom.y = area.y; + cc->geom.w = area.w - (cc->bwidth * 2); + cc->geom.h = halfh - (cc->bwidth * 2); + client_apply_sizehints(cc); + break; + case CWM_DOWN: + cc->geom.x = area.x; + cc->geom.w = area.w - (cc->bwidth * 2); + cc->geom.h = area.h - halfh - (cc->bwidth * 2); + client_apply_sizehints(cc); + cc->geom.y = area.y + area.h - cc->geom.h - + (cc->bwidth * 2); + break; + case CWM_LEFT: + cc->geom.x = area.x; + cc->geom.y = area.y; + cc->geom.w = halfw - (cc->bwidth * 2); + cc->geom.h = area.h - (cc->bwidth * 2); + client_apply_sizehints(cc); + break; + case CWM_RIGHT: + cc->geom.y = area.y; + cc->geom.w = area.w - halfw - (cc->bwidth * 2); + cc->geom.h = area.h - (cc->bwidth * 2); + client_apply_sizehints(cc); + cc->geom.x = area.x + area.w - cc->geom.w - + (cc->bwidth * 2); + break; + default: + return; + } + + client_resize(cc, 1); + client_ptr_inbound(cc, 1); +} + void kbfunc_client_close(void *ctx, struct cargs *cargs) {