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...)
This commit is contained in:
okan 2011-06-24 06:06:24 +00:00
parent b230e611be
commit 34ba6cdbcc
7 changed files with 56 additions and 2 deletions

View File

@ -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 *);

View File

@ -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;
}

1
conf.c
View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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) {