snap to half commands

This commit is contained in:
Ryan Goniwiecha
2026-04-20 14:01:25 -04:00
parent 9618137422
commit f1dd7ceb04
4 changed files with 69 additions and 0 deletions

View File

@@ -519,6 +519,7 @@ void screen_updatestackingorder(struct screen_ctx *);
void kbfunc_cwm_status(void *, struct cargs *); void kbfunc_cwm_status(void *, struct cargs *);
void kbfunc_ptrmove(void *, struct cargs *); void kbfunc_ptrmove(void *, struct cargs *);
void kbfunc_client_snap(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_move(void *, struct cargs *);
void kbfunc_client_resize(void *, struct cargs *); void kbfunc_client_resize(void *, struct cargs *);
void kbfunc_client_close(void *, struct cargs *); void kbfunc_client_close(void *, struct cargs *);

4
conf.c
View File

@@ -107,6 +107,10 @@ static const struct {
{ FUNC_CC(window-snap-down, client_snap, (CWM_DOWN)) }, { FUNC_CC(window-snap-down, client_snap, (CWM_DOWN)) },
{ FUNC_CC(window-snap-right, client_snap, (CWM_RIGHT)) }, { FUNC_CC(window-snap-right, client_snap, (CWM_RIGHT)) },
{ FUNC_CC(window-snap-left, client_snap, (CWM_LEFT)) }, { 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-right, client_snap, (CWM_UP_RIGHT)) },
{ FUNC_CC(window-snap-up-left, client_snap, (CWM_UP_LEFT)) }, { FUNC_CC(window-snap-up-left, client_snap, (CWM_UP_LEFT)) },
{ FUNC_CC(window-snap-down-right, client_snap, (CWM_DOWN_RIGHT)) }, { FUNC_CC(window-snap-down-right, client_snap, (CWM_DOWN_RIGHT)) },

View File

@@ -411,6 +411,14 @@ Snap window to bottom edge.
Snap window to right edge. Snap window to right edge.
.It window-snap-left .It window-snap-left
Snap window to left edge. 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 .It window-snap-up-right
Snap window to top-right corner. Snap window to top-right corner.
.It window-snap-up-left .It window-snap-up-left

View File

@@ -359,6 +359,62 @@ kbfunc_client_snap(void *ctx, struct cargs *cargs)
client_ptr_inbound(cc, 1); 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 void
kbfunc_client_close(void *ctx, struct cargs *cargs) kbfunc_client_close(void *ctx, struct cargs *cargs)
{ {