summary refs log tree commit diff
path: root/kbfunc.c
diff options
context:
space:
mode:
authorokan <okan>2017-12-07 16:25:33 +0000
committerokan <okan>2017-12-07 16:25:33 +0000
commit0fc9d47fb407a65fd08e3095fface42eb93ac914 (patch)
tree4f53758a765d7b0649c8cb24d839001160ca4e0b /kbfunc.c
parentf0524fe07a3a671f706d7183bb0cfbc6c8f09780 (diff)
downloadcwm-0fc9d47fb407a65fd08e3095fface42eb93ac914.tar.gz
cwm-0fc9d47fb407a65fd08e3095fface42eb93ac914.tar.xz
cwm-0fc9d47fb407a65fd08e3095fface42eb93ac914.zip
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.
Diffstat (limited to 'kbfunc.c')
-rw-r--r--kbfunc.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/kbfunc.c b/kbfunc.c
index 086e753..ad7145b 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -287,6 +287,42 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
 }
 
 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)
 {
 	client_send_delete(ctx);