mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
add window grow/shrink, add snap grid
This commit is contained in:
parent
961f21a790
commit
d61e5289bd
3
calmwm.h
3
calmwm.h
@ -75,6 +75,9 @@ size_t strlcat(char *, const char *, size_t);
|
||||
#define CWM_DOWN 0x0020
|
||||
#define CWM_LEFT 0x0040
|
||||
#define CWM_RIGHT 0x0080
|
||||
#define CWM_GROW 0x0100
|
||||
#define CWM_SHRINK 0x0200
|
||||
#define CWM_SNAP 0x0400
|
||||
|
||||
/* exec */
|
||||
#define CWM_EXEC_PROGRAM 0x0001
|
||||
|
18
conf.c
18
conf.c
@ -169,6 +169,12 @@ static struct {
|
||||
{ "CS-Down", "bigptrmovedown" },
|
||||
{ "CS-Up", "bigptrmoveup" },
|
||||
{ "CS-Right", "bigptrmoveright" },
|
||||
{ "4-Page_Up", "grow" },
|
||||
{ "4-Page_Down", "shrink" },
|
||||
{ "4-Insert", "snapleft" },
|
||||
{ "4-Home", "snapup" },
|
||||
{ "4-Delete", "snapdown" },
|
||||
{ "4-End", "snapright" },
|
||||
},
|
||||
m_binds[] = {
|
||||
{ "1", "menu_unhide" },
|
||||
@ -422,6 +428,18 @@ static struct {
|
||||
{.i = (CWM_LEFT|CWM_PTRMOVE|CWM_BIGMOVE)} },
|
||||
{ "bigptrmoveright", kbfunc_moveresize, 0,
|
||||
{.i = (CWM_RIGHT|CWM_PTRMOVE|CWM_BIGMOVE)} },
|
||||
{ "grow", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
{.i = (CWM_GROW|CWM_SNAP)} },
|
||||
{ "shrink", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
{.i = (CWM_SHRINK|CWM_SNAP)} },
|
||||
{ "snapup", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
{.i = (CWM_UP|CWM_SNAP)} },
|
||||
{ "snapdown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
{.i = (CWM_DOWN|CWM_SNAP)} },
|
||||
{ "snapleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
{.i = (CWM_LEFT|CWM_SNAP)} },
|
||||
{ "snapright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
{.i = (CWM_RIGHT|CWM_SNAP)} },
|
||||
};
|
||||
|
||||
/*
|
||||
|
68
kbfunc.c
68
kbfunc.c
@ -50,7 +50,7 @@ kbfunc_client_raise(struct client_ctx *cc, union arg *arg)
|
||||
client_raise(cc);
|
||||
}
|
||||
|
||||
#define TYPEMASK (CWM_MOVE | CWM_RESIZE | CWM_PTRMOVE)
|
||||
#define TYPEMASK (CWM_MOVE | CWM_RESIZE | CWM_PTRMOVE | CWM_SNAP)
|
||||
#define MOVEMASK (CWM_UP | CWM_DOWN | CWM_LEFT | CWM_RIGHT)
|
||||
void
|
||||
kbfunc_moveresize(struct client_ctx *cc, union arg *arg)
|
||||
@ -58,6 +58,7 @@ kbfunc_moveresize(struct client_ctx *cc, union arg *arg)
|
||||
struct screen_ctx *sc;
|
||||
int x, y, flags, amt;
|
||||
u_int mx, my;
|
||||
int ox, oy, ow, oh;
|
||||
|
||||
if (cc->flags & CLIENT_FREEZE)
|
||||
return;
|
||||
@ -133,6 +134,71 @@ kbfunc_moveresize(struct client_ctx *cc, union arg *arg)
|
||||
xu_ptr_getpos(sc->rootwin, &x, &y);
|
||||
xu_ptr_setpos(sc->rootwin, x + mx, y + my);
|
||||
break;
|
||||
case CWM_SNAP:
|
||||
ox = cc->geom.x; ow = cc->geom.width;
|
||||
oy = cc->geom.y; oh = cc->geom.height;
|
||||
#define sw cc->sc->xmax
|
||||
#define sh cc->sc->ymax
|
||||
#define bw 2 * cc->bwidth
|
||||
#define nw cc->geom.width
|
||||
#define nh cc->geom.height
|
||||
#define nx cc->geom.x
|
||||
#define ny cc->geom.y
|
||||
if (flags & CWM_UP) {
|
||||
if (oy > sh - oh - bw) ny = sh - oh - bw;
|
||||
else if ( oy > (sh - oh - bw) / 2 ) ny = (sh - oh - bw) / 2;
|
||||
else ny = 0;
|
||||
} else if (flags & CWM_DOWN) {
|
||||
if (oy < 0) ny = 0;
|
||||
else if (oy < (sh - oh - bw) / 2) ny = (sh - oh - bw)/2;
|
||||
else ny = sh - oh - bw;
|
||||
} else if (flags & CWM_LEFT) {
|
||||
if (ox + bw > sw - ow) nx = sw - ow - bw;
|
||||
else if (ox > (sw - ow - bw) / 2) nx = (sw - ow - bw) / 2;
|
||||
else cc->geom.x = 0;
|
||||
} else if (flags & CWM_RIGHT) {
|
||||
if (ox < 0) nx = 0;
|
||||
else if (ox < (sw - ow - bw) / 2) nx = (sw - ow - bw) / 2;
|
||||
else nx = sw - ow - bw;
|
||||
} else if (flags & CWM_GROW) {
|
||||
if ((cc->flags & CLIENT_MAXFLAGS) == CLIENT_MAXIMIZED) {
|
||||
} else if (ow + bw < sw / 3) {
|
||||
nw = sw / 3 - bw;
|
||||
nh = sh / 3 - bw;
|
||||
} else if (ow + bw < sw / 2) {
|
||||
nw = sw / 2 - bw;
|
||||
nh = sh / 2 - bw;
|
||||
} else if (ow + bw < sw * 2 / 3) {
|
||||
nw = sw * 2 / 3 - bw;
|
||||
nh = sh * 2 / 3 - bw;
|
||||
} else {
|
||||
client_maximize(cc);
|
||||
goto end;
|
||||
}
|
||||
} else if (flags & CWM_SHRINK) {
|
||||
if ((cc->flags & CLIENT_MAXFLAGS) == CLIENT_MAXIMIZED) {
|
||||
client_maximize(cc);
|
||||
goto end;
|
||||
} else if (ow + bw > sw * 2 / 3) {
|
||||
nw = sw * 2 / 3 - bw;
|
||||
nh = sh * 2 / 3 - bw;
|
||||
} else if (ow + bw> sw / 2) {
|
||||
nw = sw / 2 - bw;
|
||||
nh = sh / 2 - bw;
|
||||
} else if (ow + bw > sw / 3) {
|
||||
nw = sw / 3 - bw;
|
||||
nh = sh / 3 - bw;
|
||||
}
|
||||
}
|
||||
nx += (ow - nw)/2;
|
||||
ny += (oh - nh)/2;
|
||||
client_ptrsave(cc);
|
||||
client_resize(cc);
|
||||
cc->ptr.x += (nw - ow)/2;
|
||||
cc->ptr.y += (nh - oh)/2;
|
||||
client_ptrwarp(cc);
|
||||
end:
|
||||
break;
|
||||
default:
|
||||
warnx("invalid flags passed to kbfunc_client_moveresize");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user