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; int bwidth;
#define CONF_MAMOUNT 1 #define CONF_MAMOUNT 1
int mamount; int mamount;
#define CONF_SNAPDIST 0
int snapdist;
struct gap gap; struct gap gap;
#define CONF_COLOR_ACTIVEBORDER "#CCCCCC" #define CONF_COLOR_ACTIVEBORDER "#CCCCCC"
#define CONF_COLOR_INACTIVEBORDER "#666666" #define CONF_COLOR_INACTIVEBORDER "#666666"
@ -325,6 +327,7 @@ void client_resize(struct client_ctx *);
void client_send_delete(struct client_ctx *); void client_send_delete(struct client_ctx *);
void client_setactive(struct client_ctx *, int); void client_setactive(struct client_ctx *, int);
void client_setname(struct client_ctx *); void client_setname(struct client_ctx *);
int client_snapcalc(int, int, int, int, int);
void client_unhide(struct client_ctx *); void client_unhide(struct client_ctx *);
void client_vertmaximize(struct client_ctx *); void client_vertmaximize(struct client_ctx *);
void client_warp(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 && return (x < cc->geom.width && x >= 0 &&
y < cc->geom.height && y >= 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->flags = 0;
c->bwidth = CONF_BWIDTH; c->bwidth = CONF_BWIDTH;
c->mamount = CONF_MAMOUNT; c->mamount = CONF_MAMOUNT;
c->snapdist = CONF_SNAPDIST;
TAILQ_INIT(&c->ignoreq); TAILQ_INIT(&c->ignoreq);
TAILQ_INIT(&c->cmdq); TAILQ_INIT(&c->cmdq);

View File

@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: September 25 2010 $ .Dd $Mdocdate: May 7 2011 $
.Dt CWMRC 5 .Dt CWMRC 5
.Os .Os
.Sh NAME .Sh NAME
@ -277,6 +277,8 @@ Reverse cycle through groups.
Forward cycle through windows. Forward cycle through windows.
.It rcycle .It rcycle
Reverse cycle through windows. Reverse cycle through windows.
.It snapdist
Minimum distance to snap-to adjacent edge.
.It delete .It delete
Delete current window. Delete current window.
.It hide .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) if (cc->geom.x > cc->sc->xmax - 1)
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); client_move(cc);
xu_ptr_getpos(cc->win, &x, &y); xu_ptr_getpos(cc->win, &x, &y);
cc->ptr.y = y + my; 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.x = ev.xmotion.x_root - px - cc->bwidth;
cc->geom.y = ev.xmotion.y_root - py - 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 */ /* don't move more than 60 times / second */
if ((ev.xmotion.time - time) > (1000 / 60)) { if ((ev.xmotion.time - time) > (1000 / 60)) {
time = ev.xmotion.time; time = ev.xmotion.time;

View File

@ -70,7 +70,7 @@ typedef struct {
%token FONTNAME STICKY GAP MOUSEBIND %token FONTNAME STICKY GAP MOUSEBIND
%token AUTOGROUP BIND COMMAND IGNORE %token AUTOGROUP BIND COMMAND IGNORE
%token YES NO BORDERWIDTH MOVEAMOUNT %token YES NO BORDERWIDTH MOVEAMOUNT
%token COLOR %token COLOR SNAPDIST
%token ACTIVEBORDER INACTIVEBORDER %token ACTIVEBORDER INACTIVEBORDER
%token GROUPBORDER UNGROUPBORDER %token GROUPBORDER UNGROUPBORDER
%token ERROR %token ERROR
@ -120,6 +120,9 @@ main : FONTNAME STRING {
| MOVEAMOUNT NUMBER { | MOVEAMOUNT NUMBER {
conf->mamount = $2; conf->mamount = $2;
} }
| SNAPDIST NUMBER {
conf->snapdist = $2;
}
| COMMAND STRING string { | COMMAND STRING string {
conf_cmd_add(conf, $3, $2, 0); conf_cmd_add(conf, $3, $2, 0);
free($2); free($2);
@ -228,6 +231,7 @@ lookup(char *s)
{ "mousebind", MOUSEBIND}, { "mousebind", MOUSEBIND},
{ "moveamount", MOVEAMOUNT}, { "moveamount", MOVEAMOUNT},
{ "no", NO}, { "no", NO},
{ "snapdist", SNAPDIST},
{ "sticky", STICKY}, { "sticky", STICKY},
{ "ungroupborder", UNGROUPBORDER}, { "ungroupborder", UNGROUPBORDER},
{ "yes", YES} { "yes", YES}
@ -523,6 +527,7 @@ parse_config(const char *filename, struct conf *xconf)
xconf->flags = conf->flags; xconf->flags = conf->flags;
xconf->bwidth = conf->bwidth; xconf->bwidth = conf->bwidth;
xconf->mamount = conf->mamount; xconf->mamount = conf->mamount;
xconf->snapdist = conf->snapdist;
xconf->gap = conf->gap; xconf->gap = conf->gap;
while ((cmd = TAILQ_FIRST(&conf->cmdq)) != NULL) { while ((cmd = TAILQ_FIRST(&conf->cmdq)) != NULL) {