diff options
author | Okan Demirmen <okan@cvs.openbsd.org> | 2011-06-24 06:06:25 +0000 |
---|---|---|
committer | Okan Demirmen <okan@cvs.openbsd.org> | 2011-06-24 06:06:25 +0000 |
commit | 8a7ff79029d1e2c3902612d407babe0e3cda2dde (patch) | |
tree | 21fa53a5a7647d9bbe3f42be92ce1e01ae049651 /app | |
parent | 341bef3da06ab643444209c104829763b2b0ce1c (diff) |
introduce a new config option to snap to the screen edge. 'snapdist'
keyword taken from a diff from Sviatoslav Chagaev to do the same thing,
but implemented in a completely way (based on some very old code from
mk@). default set to 0, so no behavior change.
ok oga@ (who would also like to take it further...)
Diffstat (limited to 'app')
-rw-r--r-- | app/cwm/calmwm.h | 5 | ||||
-rw-r--r-- | app/cwm/client.c | 31 | ||||
-rw-r--r-- | app/cwm/conf.c | 3 | ||||
-rw-r--r-- | app/cwm/cwmrc.5 | 6 | ||||
-rw-r--r-- | app/cwm/kbfunc.c | 9 | ||||
-rw-r--r-- | app/cwm/mousefunc.c | 9 | ||||
-rw-r--r-- | app/cwm/parse.y | 9 |
7 files changed, 63 insertions, 9 deletions
diff --git a/app/cwm/calmwm.h b/app/cwm/calmwm.h index 8e37e3bf3..75ef1df1b 100644 --- a/app/cwm/calmwm.h +++ b/app/cwm/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/app/cwm/client.c b/app/cwm/client.c index d366f308c..523a3b631 100644 --- a/app/cwm/client.c +++ b/app/cwm/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/app/cwm/conf.c b/app/cwm/conf.c index 775ae2ccd..db4005195 100644 --- a/app/cwm/conf.c +++ b/app/cwm/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/app/cwm/cwmrc.5 b/app/cwm/cwmrc.5 index f6843809d..1d8b64b62 100644 --- a/app/cwm/cwmrc.5 +++ b/app/cwm/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/app/cwm/kbfunc.c b/app/cwm/kbfunc.c index 3b4e6ba60..d0b278ade 100644 --- a/app/cwm/kbfunc.c +++ b/app/cwm/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/app/cwm/mousefunc.c b/app/cwm/mousefunc.c index 1ff23934e..e38873ebf 100644 --- a/app/cwm/mousefunc.c +++ b/app/cwm/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/app/cwm/parse.y b/app/cwm/parse.y index e10629814..a6ba52821 100644 --- a/app/cwm/parse.y +++ b/app/cwm/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) { |