aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--calmwm.h5
-rw-r--r--client.c31
-rw-r--r--conf.c3
-rw-r--r--cwmrc.56
-rw-r--r--kbfunc.c9
-rw-r--r--mousefunc.c9
-rw-r--r--parse.y9
7 files changed, 63 insertions, 9 deletions
diff --git a/calmwm.h b/calmwm.h
index 8e37e3b..75ef1df 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: calmwm.h,v 1.130 2011/06/24 06:01:47 okan Exp $
+ * $OpenBSD: calmwm.h,v 1.131 2011/06/24 06:06:24 okan Exp $
*/
#ifndef _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 d366f30..523a3b6 100644
--- a/client.c
+++ b/client.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: client.c,v 1.84 2011/06/24 06:01:47 okan Exp $
+ * $OpenBSD: client.c,v 1.85 2011/06/24 06:06:24 okan Exp $
*/
#include <sys/param.h>
@@ -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 775ae2c..db40051 100644
--- a/conf.c
+++ b/conf.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: conf.c,v 1.83 2011/06/24 05:54:30 okan Exp $
+ * $OpenBSD: conf.c,v 1.84 2011/06/24 06:06:24 okan Exp $
*/
#include <sys/param.h>
@@ -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 f684380..1d8b64b 100644
--- a/cwmrc.5
+++ b/cwmrc.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: cwmrc.5,v 1.35 2011/05/07 17:15:37 okan Exp $
+.\" $OpenBSD: cwmrc.5,v 1.36 2011/06/24 06:06:24 okan Exp $
.\"
.\" Copyright (c) 2004,2005 Marius Aamodt Eriksen <marius@monkey.org>
.\"
@@ -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: May 7 2011 $
+.Dd $Mdocdate: June 24 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 3b4e6ba..d0b278a 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: kbfunc.c,v 1.54 2011/06/24 05:33:41 okan Exp $
+ * $OpenBSD: kbfunc.c,v 1.55 2011/06/24 06:06:24 okan Exp $
*/
#include <sys/param.h>
@@ -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 1ff2393..e38873e 100644
--- a/mousefunc.c
+++ b/mousefunc.c
@@ -16,7 +16,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: mousefunc.c,v 1.28 2011/06/24 05:51:25 okan Exp $
+ * $OpenBSD: mousefunc.c,v 1.29 2011/06/24 06:06:24 okan Exp $
*/
#include <sys/param.h>
@@ -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 e106298..a6ba528 100644
--- a/parse.y
+++ b/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.26 2010/09/25 20:02:58 okan Exp $ */
+/* $OpenBSD: parse.y,v 1.27 2011/06/24 06:06:24 okan Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -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) {