Original idea from Dimitris Papastamos to move windows to corners a while ago;

re-proposed by Julien Steinhauser with an updated diff. Apparently this was in
the original calmnwm.

However, expand the original idea and let clients 'snap' to edges instead,
neatly allowing key bindings that snap to adjacent edges (i.e. corners) as
well. No default bindings assigned.
This commit is contained in:
okan 2017-12-07 16:25:33 +00:00
parent f0524fe07a
commit 0fc9d47fb4
4 changed files with 71 additions and 0 deletions

View File

@ -465,6 +465,7 @@ void screen_assert_clients_within(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_move(void *, struct cargs *);
void kbfunc_client_resize(void *, struct cargs *);
void kbfunc_client_delete(void *, struct cargs *);

18
conf.c
View File

@ -92,6 +92,24 @@ static const struct {
{ "window-movetogroup-8", kbfunc_client_movetogroup, CWM_CONTEXT_CC, 8 },
{ "window-movetogroup-9", kbfunc_client_movetogroup, CWM_CONTEXT_CC, 9 },
{ "window-snap-up", kbfunc_client_snap, CWM_CONTEXT_CC,
(CWM_UP) },
{ "window-snap-down", kbfunc_client_snap, CWM_CONTEXT_CC,
(CWM_DOWN) },
{ "window-snap-left", kbfunc_client_snap, CWM_CONTEXT_CC,
(CWM_LEFT) },
{ "window-snap-right", kbfunc_client_snap, CWM_CONTEXT_CC,
(CWM_RIGHT) },
{ "window-snap-up-right", kbfunc_client_snap, CWM_CONTEXT_CC,
(CWM_UP|CWM_RIGHT) },
{ "window-snap-up-left", kbfunc_client_snap, CWM_CONTEXT_CC,
(CWM_UP|CWM_LEFT) },
{ "window-snap-down-right", kbfunc_client_snap, CWM_CONTEXT_CC,
(CWM_DOWN|CWM_RIGHT) },
{ "window-snap-down-left", kbfunc_client_snap, CWM_CONTEXT_CC,
(CWM_DOWN|CWM_LEFT) },
{ "window-move", kbfunc_client_move, CWM_CONTEXT_CC, 0 },
{ "window-move-up", kbfunc_client_move, CWM_CONTEXT_CC,
(CWM_UP) },

16
cwmrc.5
View File

@ -398,6 +398,22 @@ pixels right.
Resize window 10 times
.Ar moveamount
pixels left.
.It window-snap-up
Snap window to top edge.
.It window-snap-down
Snap window to bottom edge.
.It window-snap-right
Snap window to right edge.
.It window-snap-left
Snap window to left edge.
.It window-snap-up-right
Snap window to top-right corner.
.It window-snap-up-left
Snap window to top-left corner.
.It window-snap-down-right
Snap window to bottom-right corner.
.It window-snap-down-left
Snap window to bottom-left corner.
.It pointer-move-up
Move pointer
.Ar moveamount

View File

@ -286,6 +286,42 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
client_ptr_inbound(cc, 0);
}
void
kbfunc_client_snap(void *ctx, struct cargs *cargs)
{
struct client_ctx *cc = ctx;
struct screen_ctx *sc = cc->sc;
struct geom area;
int flags;
area = screen_area(sc,
cc->geom.x + cc->geom.w / 2,
cc->geom.y + cc->geom.h / 2, CWM_GAP);
flags = cargs->flag;
while (flags) {
if (flags & CWM_UP) {
cc->geom.y = area.y;
flags &= ~CWM_UP;
}
if (flags & CWM_LEFT) {
cc->geom.x = area.x;
flags &= ~CWM_LEFT;
}
if (flags & CWM_RIGHT) {
cc->geom.x = area.x + area.w - cc->geom.w -
(cc->bwidth * 2);
flags &= ~CWM_RIGHT;
}
if (flags & CWM_DOWN) {
cc->geom.y = area.y + area.h - cc->geom.h -
(cc->bwidth * 2);
flags &= ~CWM_DOWN;
}
}
client_move(cc);
}
void
kbfunc_client_delete(void *ctx, struct cargs *cargs)
{