summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--calmwm.h3
-rw-r--r--client.c29
-rw-r--r--conf.c1
-rw-r--r--cwmrc.54
-rw-r--r--kbfunc.c7
-rw-r--r--mousefunc.c7
-rw-r--r--parse.y7
7 files changed, 56 insertions, 2 deletions
diff --git a/calmwm.h b/calmwm.h
index d6b74f9..68426ac 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -273,6 +273,8 @@ struct conf {
 	int			 bwidth;
 #define	CONF_MAMOUNT			1
 	int			 mamount;
+#define	CONF_SNAPDIST			0
+	int			 snapdist;
 	struct gap		 gap;
 #define CONF_COLOR_ACTIVEBORDER		"#CCCCCC"
 #define CONF_COLOR_INACTIVEBORDER	"#666666"
@@ -325,6 +327,7 @@ void			 client_resize(struct client_ctx *);
 void			 client_send_delete(struct client_ctx *);
 void			 client_setactive(struct client_ctx *, int);
 void			 client_setname(struct client_ctx *);
+int			 client_snapcalc(int, int, int, int, int);
 void			 client_unhide(struct client_ctx *);
 void			 client_vertmaximize(struct client_ctx *);
 void			 client_warp(struct client_ctx *);
diff --git a/client.c b/client.c
index 49b16c9..42fef6b 100644
--- a/client.c
+++ b/client.c
@@ -842,3 +842,32 @@ client_inbound(struct client_ctx *cc, int x, int y)
 	return (x < cc->geom.width && x >= 0 &&
 	    y < cc->geom.height && y >= 0);
 }
+
+int
+client_snapcalc(int n, int dn, int nmax, int bwidth, int snapdist)
+{
+	int	 n0, n1, s0, s1;
+
+	s0 = s1 = 0;
+	n0 = n;
+	n1 = n + dn + (bwidth * 2);
+
+	if (abs(n0) <= snapdist)
+		s0 = -n0;
+
+	if (nmax - snapdist <= n1 && n1 <= nmax + snapdist)
+		s1 = nmax - n1;
+
+	/* possible to snap in both directions */
+	if (s0 != 0 && s1 != 0)
+		if (abs(s0) < abs(s1))
+			return s0;
+		else
+			return s1;
+	else if (s0 != 0)
+		return s0;
+	else if (s1 != 0)
+		return s1;
+	else
+		return 0;
+}
diff --git a/conf.c b/conf.c
index a7e2631..4d97f94 100644
--- a/conf.c
+++ b/conf.c
@@ -184,6 +184,7 @@ conf_init(struct conf *c)
 	c->flags = 0;
 	c->bwidth = CONF_BWIDTH;
 	c->mamount = CONF_MAMOUNT;
+	c->snapdist = CONF_SNAPDIST;
 
 	TAILQ_INIT(&c->ignoreq);
 	TAILQ_INIT(&c->cmdq);
diff --git a/cwmrc.5 b/cwmrc.5
index a0544ff..b5a5779 100644
--- a/cwmrc.5
+++ b/cwmrc.5
@@ -14,7 +14,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: September 25 2010 $
+.Dd $Mdocdate: May 7 2011 $
 .Dt CWMRC 5
 .Os
 .Sh NAME
@@ -277,6 +277,8 @@ Reverse cycle through groups.
 Forward cycle through windows.
 .It rcycle
 Reverse cycle through windows.
+.It snapdist
+Minimum distance to snap-to adjacent edge.
 .It delete
 Delete current window.
 .It hide
diff --git a/kbfunc.c b/kbfunc.c
index a60fc33..2946173 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -100,6 +100,13 @@ kbfunc_moveresize(struct client_ctx *cc, union arg *arg)
 		if (cc->geom.x > cc->sc->xmax - 1)
 			cc->geom.x = cc->sc->xmax - 1;
 
+		cc->geom.x += client_snapcalc(cc->geom.x,
+		    cc->geom.width, cc->sc->xmax,
+		    cc->bwidth, Conf.snapdist);
+		cc->geom.y += client_snapcalc(cc->geom.y,
+		    cc->geom.height, cc->sc->ymax,
+		    cc->bwidth, Conf.snapdist);
+
 		client_move(cc);
 		xu_ptr_getpos(cc->win, &x, &y);
 		cc->ptr.y = y + my;
diff --git a/mousefunc.c b/mousefunc.c
index 3050c31..d287d8b 100644
--- a/mousefunc.c
+++ b/mousefunc.c
@@ -160,6 +160,13 @@ mousefunc_window_move(struct client_ctx *cc, void *arg)
 			cc->geom.x = ev.xmotion.x_root - px - cc->bwidth;
 			cc->geom.y = ev.xmotion.y_root - py - cc->bwidth;
 
+			cc->geom.x += client_snapcalc(cc->geom.x,
+			    cc->geom.width, cc->sc->xmax,
+			    cc->bwidth, Conf.snapdist);
+			cc->geom.y += client_snapcalc(cc->geom.y,
+			    cc->geom.height, cc->sc->ymax,
+			    cc->bwidth, Conf.snapdist);
+
 			/* don't move more than 60 times / second */
 			if ((ev.xmotion.time - time) > (1000 / 60)) {
 				time = ev.xmotion.time;
diff --git a/parse.y b/parse.y
index d86c4e1..76ee731 100644
--- a/parse.y
+++ b/parse.y
@@ -70,7 +70,7 @@ typedef struct {
 %token	FONTNAME STICKY GAP MOUSEBIND
 %token	AUTOGROUP BIND COMMAND IGNORE
 %token	YES NO BORDERWIDTH MOVEAMOUNT
-%token	COLOR
+%token	COLOR SNAPDIST
 %token	ACTIVEBORDER INACTIVEBORDER
 %token	GROUPBORDER UNGROUPBORDER
 %token	ERROR
@@ -120,6 +120,9 @@ main		: FONTNAME STRING		{
 		| MOVEAMOUNT NUMBER {
 			conf->mamount = $2;
 		}
+		| SNAPDIST NUMBER {
+			conf->snapdist = $2;
+		}
 		| COMMAND STRING string		{
 			conf_cmd_add(conf, $3, $2, 0);
 			free($2);
@@ -228,6 +231,7 @@ lookup(char *s)
 		{ "mousebind",		MOUSEBIND},
 		{ "moveamount",		MOVEAMOUNT},
 		{ "no",			NO},
+		{ "snapdist",		SNAPDIST},
 		{ "sticky",		STICKY},
 		{ "ungroupborder",	UNGROUPBORDER},
 		{ "yes",		YES}
@@ -523,6 +527,7 @@ parse_config(const char *filename, struct conf *xconf)
 		xconf->flags = conf->flags;
 		xconf->bwidth = conf->bwidth;
 		xconf->mamount = conf->mamount;
+		xconf->snapdist = conf->snapdist;
 		xconf->gap = conf->gap;
 
 		while ((cmd = TAILQ_FIRST(&conf->cmdq)) != NULL) {