Move kb pointer movement out of the kbfunc_client_moveresize since it's

got nothing to do with clients, thus doing flags work causes lots of
waste and almost useless jumpy pointer movements; while here, split out
move and resize since they share almost no code, just like mouse client
move/resize; factor out amount and factor. Still wonder why this is
here, but it works now.
This commit is contained in:
okan 2015-11-12 18:26:41 +00:00
parent 4db32a8463
commit db0907a53d
3 changed files with 152 additions and 136 deletions

View File

@ -15,7 +15,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.
* *
* $OpenBSD: calmwm.h,v 1.309 2015/11/11 14:22:01 okan Exp $ * $OpenBSD: calmwm.h,v 1.310 2015/11/12 18:26:41 okan Exp $
*/ */
#ifndef _CALMWM_H_ #ifndef _CALMWM_H_
@ -50,15 +50,13 @@
#define KEYMASK (KeyPressMask | ExposureMask) #define KEYMASK (KeyPressMask | ExposureMask)
#define IGNOREMODMASK (LockMask | Mod2Mask | 0x2000) #define IGNOREMODMASK (LockMask | Mod2Mask | 0x2000)
/* kb movement */ /* direction/amount */
#define CWM_MOVE 0x0001 #define CWM_UP 0x0001
#define CWM_RESIZE 0x0002 #define CWM_DOWN 0x0002
#define CWM_PTRMOVE 0x0004 #define CWM_LEFT 0x0004
#define CWM_BIGMOVE 0x0008 #define CWM_RIGHT 0x0008
#define CWM_UP 0x0010 #define CWM_BIGAMOUNT 0x0010
#define CWM_DOWN 0x0020 #define DIRECTIONMASK (CWM_UP | CWM_DOWN | CWM_LEFT | CWM_RIGHT)
#define CWM_LEFT 0x0040
#define CWM_RIGHT 0x0080
#define CWM_CLIENT_CYCLE 0x0001 #define CWM_CLIENT_CYCLE 0x0001
#define CWM_CLIENT_RCYCLE 0x0002 #define CWM_CLIENT_RCYCLE 0x0002
@ -475,14 +473,14 @@ void kbfunc_client_grouptoggle(struct client_ctx *,
void kbfunc_client_hide(struct client_ctx *, union arg *); void kbfunc_client_hide(struct client_ctx *, union arg *);
void kbfunc_client_label(struct client_ctx *, union arg *); void kbfunc_client_label(struct client_ctx *, union arg *);
void kbfunc_client_lower(struct client_ctx *, union arg *); void kbfunc_client_lower(struct client_ctx *, union arg *);
void kbfunc_client_moveresize(struct client_ctx *, void kbfunc_client_move(struct client_ctx *, union arg *);
union arg *);
void kbfunc_client_movetogroup(struct client_ctx *, void kbfunc_client_movetogroup(struct client_ctx *,
union arg *); union arg *);
void kbfunc_client_nogroup(struct client_ctx *, void kbfunc_client_nogroup(struct client_ctx *,
union arg *); union arg *);
void kbfunc_client_raise(struct client_ctx *, union arg *); void kbfunc_client_raise(struct client_ctx *, union arg *);
void kbfunc_client_rcycle(struct client_ctx *, union arg *); void kbfunc_client_rcycle(struct client_ctx *, union arg *);
void kbfunc_client_resize(struct client_ctx *, union arg *);
void kbfunc_client_tile(struct client_ctx *, union arg *); void kbfunc_client_tile(struct client_ctx *, union arg *);
void kbfunc_client_toggle_freeze(struct client_ctx *, void kbfunc_client_toggle_freeze(struct client_ctx *,
union arg *); union arg *);
@ -505,6 +503,7 @@ void kbfunc_menu_client(struct client_ctx *, union arg *);
void kbfunc_menu_cmd(struct client_ctx *, union arg *); void kbfunc_menu_cmd(struct client_ctx *, union arg *);
void kbfunc_menu_group(struct client_ctx *, union arg *); void kbfunc_menu_group(struct client_ctx *, union arg *);
void kbfunc_menu_ssh(struct client_ctx *, union arg *); void kbfunc_menu_ssh(struct client_ctx *, union arg *);
void kbfunc_ptrmove(struct client_ctx *, union arg *);
void mousefunc_client_move(struct client_ctx *, void mousefunc_client_move(struct client_ctx *,
union arg *); union arg *);

View File

@ -15,7 +15,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.
* *
* $OpenBSD: conf.c,v 1.199 2015/11/10 20:05:33 okan Exp $ * $OpenBSD: conf.c,v 1.200 2015/11/12 18:26:41 okan Exp $
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -426,54 +426,54 @@ static const struct {
{ "ssh", kbfunc_menu_ssh, CWM_CONTEXT_SCREEN, {0} }, { "ssh", kbfunc_menu_ssh, CWM_CONTEXT_SCREEN, {0} },
{ "terminal", kbfunc_exec_term, CWM_CONTEXT_SCREEN, {0} }, { "terminal", kbfunc_exec_term, CWM_CONTEXT_SCREEN, {0} },
{ "lock", kbfunc_exec_lock, CWM_CONTEXT_SCREEN, {0} }, { "lock", kbfunc_exec_lock, CWM_CONTEXT_SCREEN, {0} },
{ "moveup", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "moveup", kbfunc_client_move, CWM_CONTEXT_CLIENT,
{.i = (CWM_UP | CWM_MOVE)} }, {.i = (CWM_UP)} },
{ "movedown", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "movedown", kbfunc_client_move, CWM_CONTEXT_CLIENT,
{.i = (CWM_DOWN | CWM_MOVE)} }, {.i = (CWM_DOWN)} },
{ "moveright", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "moveright", kbfunc_client_move, CWM_CONTEXT_CLIENT,
{.i = (CWM_RIGHT | CWM_MOVE)} }, {.i = (CWM_RIGHT)} },
{ "moveleft", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "moveleft", kbfunc_client_move, CWM_CONTEXT_CLIENT,
{.i = (CWM_LEFT | CWM_MOVE)} }, {.i = (CWM_LEFT)} },
{ "bigmoveup", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "bigmoveup", kbfunc_client_move, CWM_CONTEXT_CLIENT,
{.i = (CWM_UP | CWM_MOVE | CWM_BIGMOVE)} }, {.i = (CWM_UP | CWM_BIGAMOUNT)} },
{ "bigmovedown", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "bigmovedown", kbfunc_client_move, CWM_CONTEXT_CLIENT,
{.i = (CWM_DOWN | CWM_MOVE | CWM_BIGMOVE)} }, {.i = (CWM_DOWN | CWM_BIGAMOUNT)} },
{ "bigmoveright", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "bigmoveright", kbfunc_client_move, CWM_CONTEXT_CLIENT,
{.i = (CWM_RIGHT | CWM_MOVE | CWM_BIGMOVE)} }, {.i = (CWM_RIGHT | CWM_BIGAMOUNT)} },
{ "bigmoveleft", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "bigmoveleft", kbfunc_client_move, CWM_CONTEXT_CLIENT,
{.i = (CWM_LEFT | CWM_MOVE | CWM_BIGMOVE)} }, {.i = (CWM_LEFT | CWM_BIGAMOUNT)} },
{ "resizeup", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "resizeup", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
{.i = (CWM_UP | CWM_RESIZE)} }, {.i = (CWM_UP)} },
{ "resizedown", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "resizedown", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
{.i = (CWM_DOWN | CWM_RESIZE)} }, {.i = (CWM_DOWN)} },
{ "resizeright", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "resizeright", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
{.i = (CWM_RIGHT | CWM_RESIZE)} }, {.i = (CWM_RIGHT)} },
{ "resizeleft", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "resizeleft", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
{.i = (CWM_LEFT | CWM_RESIZE)} }, {.i = (CWM_LEFT)} },
{ "bigresizeup", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "bigresizeup", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
{.i = (CWM_UP | CWM_RESIZE | CWM_BIGMOVE)} }, {.i = (CWM_UP | CWM_BIGAMOUNT)} },
{ "bigresizedown", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "bigresizedown", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
{.i = (CWM_DOWN | CWM_RESIZE | CWM_BIGMOVE)} }, {.i = (CWM_DOWN | CWM_BIGAMOUNT)} },
{ "bigresizeright", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "bigresizeright", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
{.i = (CWM_RIGHT | CWM_RESIZE | CWM_BIGMOVE)} }, {.i = (CWM_RIGHT | CWM_BIGAMOUNT)} },
{ "bigresizeleft", kbfunc_client_moveresize, CWM_CONTEXT_CLIENT, { "bigresizeleft", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
{.i = (CWM_LEFT | CWM_RESIZE | CWM_BIGMOVE)} }, {.i = (CWM_LEFT | CWM_BIGAMOUNT)} },
{ "ptrmoveup", kbfunc_client_moveresize, CWM_CONTEXT_SCREEN, { "ptrmoveup", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
{.i = (CWM_UP | CWM_PTRMOVE)} }, {.i = (CWM_UP)} },
{ "ptrmovedown", kbfunc_client_moveresize, CWM_CONTEXT_SCREEN, { "ptrmovedown", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
{.i = (CWM_DOWN | CWM_PTRMOVE)} }, {.i = (CWM_DOWN)} },
{ "ptrmoveleft", kbfunc_client_moveresize, CWM_CONTEXT_SCREEN, { "ptrmoveleft", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
{.i = (CWM_LEFT | CWM_PTRMOVE)} }, {.i = (CWM_LEFT)} },
{ "ptrmoveright", kbfunc_client_moveresize, CWM_CONTEXT_SCREEN, { "ptrmoveright", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
{.i = (CWM_RIGHT | CWM_PTRMOVE)} }, {.i = (CWM_RIGHT)} },
{ "bigptrmoveup", kbfunc_client_moveresize, CWM_CONTEXT_SCREEN, { "bigptrmoveup", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
{.i = (CWM_UP | CWM_PTRMOVE | CWM_BIGMOVE)} }, {.i = (CWM_UP | CWM_BIGAMOUNT)} },
{ "bigptrmovedown", kbfunc_client_moveresize, CWM_CONTEXT_SCREEN, { "bigptrmovedown", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
{.i = (CWM_DOWN | CWM_PTRMOVE | CWM_BIGMOVE)} }, {.i = (CWM_DOWN | CWM_BIGAMOUNT)} },
{ "bigptrmoveleft", kbfunc_client_moveresize, CWM_CONTEXT_SCREEN, { "bigptrmoveleft", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
{.i = (CWM_LEFT | CWM_PTRMOVE | CWM_BIGMOVE)} }, {.i = (CWM_LEFT | CWM_BIGAMOUNT)} },
{ "bigptrmoveright", kbfunc_client_moveresize, CWM_CONTEXT_SCREEN, { "bigptrmoveright", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
{.i = (CWM_RIGHT | CWM_PTRMOVE | CWM_BIGMOVE)} }, {.i = (CWM_RIGHT | CWM_BIGAMOUNT)} },
{ "htile", kbfunc_client_tile, CWM_CONTEXT_CLIENT, { "htile", kbfunc_client_tile, CWM_CONTEXT_CLIENT,
{.i = CWM_CLIENT_TILE_HORIZ} }, {.i = CWM_CLIENT_TILE_HORIZ} },
{ "vtile", kbfunc_client_tile, CWM_CONTEXT_CLIENT, { "vtile", kbfunc_client_tile, CWM_CONTEXT_CLIENT,

View File

@ -15,7 +15,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.
* *
* $OpenBSD: kbfunc.c,v 1.122 2015/11/11 14:22:01 okan Exp $ * $OpenBSD: kbfunc.c,v 1.123 2015/11/12 18:26:41 okan Exp $
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -38,6 +38,8 @@
extern sig_atomic_t cwm_status; extern sig_atomic_t cwm_status;
static void kbfunc_amount(int, unsigned int *, unsigned int *);
void void
kbfunc_client_lower(struct client_ctx *cc, union arg *arg) kbfunc_client_lower(struct client_ctx *cc, union arg *arg)
{ {
@ -51,94 +53,109 @@ kbfunc_client_raise(struct client_ctx *cc, union arg *arg)
client_raise(cc); client_raise(cc);
} }
#define TYPEMASK (CWM_MOVE | CWM_RESIZE | CWM_PTRMOVE) static void
#define MOVEMASK (CWM_UP | CWM_DOWN | CWM_LEFT | CWM_RIGHT) kbfunc_amount(int flags, unsigned int *mx, unsigned int *my)
{
#define CWM_FACTOR 10
int amt;
amt = Conf.mamount;
if (flags & CWM_BIGAMOUNT)
amt *= CWM_FACTOR;
switch (flags & DIRECTIONMASK) {
case CWM_UP:
*my -= amt;
break;
case CWM_DOWN:
*my += amt;
break;
case CWM_RIGHT:
*mx += amt;
break;
case CWM_LEFT:
*mx -= amt;
break;
}
}
void void
kbfunc_client_moveresize(struct client_ctx *cc, union arg *arg) kbfunc_ptrmove(struct client_ctx *cc, union arg *arg)
{
struct screen_ctx *sc = cc->sc;
int x, y;
unsigned int mx = 0, my = 0;
kbfunc_amount(arg->i, &mx, &my);
xu_ptr_getpos(sc->rootwin, &x, &y);
xu_ptr_setpos(sc->rootwin, x + mx, y + my);
}
void
kbfunc_client_move(struct client_ctx *cc, union arg *arg)
{ {
struct screen_ctx *sc = cc->sc; struct screen_ctx *sc = cc->sc;
struct geom area; struct geom area;
int x, y, flags, amt; int x, y;
unsigned int mx, my; unsigned int mx = 0, my = 0;
if (cc->flags & CLIENT_FREEZE) if (cc->flags & CLIENT_FREEZE)
return; return;
mx = my = 0; kbfunc_amount(arg->i, &mx, &my);
flags = arg->i; cc->geom.x += mx;
amt = Conf.mamount; if (cc->geom.x + cc->geom.w < 0)
cc->geom.x = -cc->geom.w;
if (cc->geom.x > sc->view.w - 1)
cc->geom.x = sc->view.w - 1;
cc->geom.y += my;
if (cc->geom.y + cc->geom.h < 0)
cc->geom.y = -cc->geom.h;
if (cc->geom.y > sc->view.h - 1)
cc->geom.y = sc->view.h - 1;
if (flags & CWM_BIGMOVE) { area = screen_area(sc,
flags -= CWM_BIGMOVE; cc->geom.x + cc->geom.w / 2,
amt = amt * 10; cc->geom.y + cc->geom.h / 2, CWM_GAP);
} cc->geom.x += client_snapcalc(cc->geom.x,
cc->geom.x + cc->geom.w + (cc->bwidth * 2),
area.x, area.x + area.w, sc->snapdist);
cc->geom.y += client_snapcalc(cc->geom.y,
cc->geom.y + cc->geom.h + (cc->bwidth * 2),
area.y, area.y + area.h, sc->snapdist);
client_move(cc);
switch (flags & MOVEMASK) { xu_ptr_getpos(cc->win, &x, &y);
case CWM_UP: cc->ptr.x = x + mx;
my -= amt; cc->ptr.y = y + my;
break; client_ptrwarp(cc);
case CWM_DOWN: }
my += amt;
break;
case CWM_RIGHT:
mx += amt;
break;
case CWM_LEFT:
mx -= amt;
break;
}
switch (flags & TYPEMASK) {
case CWM_MOVE:
cc->geom.x += mx;
if (cc->geom.x + cc->geom.w < 0)
cc->geom.x = -cc->geom.w;
if (cc->geom.x > sc->view.w - 1)
cc->geom.x = sc->view.w - 1;
cc->geom.y += my;
if (cc->geom.y + cc->geom.h < 0)
cc->geom.y = -cc->geom.h;
if (cc->geom.y > sc->view.h - 1)
cc->geom.y = sc->view.h - 1;
area = screen_area(sc, void
cc->geom.x + cc->geom.w / 2, kbfunc_client_resize(struct client_ctx *cc, union arg *arg)
cc->geom.y + cc->geom.h / 2, CWM_GAP); {
cc->geom.x += client_snapcalc(cc->geom.x, unsigned int mx = 0, my = 0;
cc->geom.x + cc->geom.w + (cc->bwidth * 2),
area.x, area.x + area.w, sc->snapdist);
cc->geom.y += client_snapcalc(cc->geom.y,
cc->geom.y + cc->geom.h + (cc->bwidth * 2),
area.y, area.y + area.h, sc->snapdist);
client_move(cc); if (cc->flags & CLIENT_FREEZE)
xu_ptr_getpos(cc->win, &x, &y); return;
cc->ptr.x = x + mx;
cc->ptr.y = y + my;
client_ptrwarp(cc);
break;
case CWM_RESIZE:
if ((cc->geom.w += mx) < 1)
cc->geom.w = 1;
if ((cc->geom.h += my) < 1)
cc->geom.h = 1;
client_resize(cc, 1);
/* Make sure the pointer stays within the window. */ kbfunc_amount(arg->i, &mx, &my);
xu_ptr_getpos(cc->win, &cc->ptr.x, &cc->ptr.y);
if (cc->ptr.x > cc->geom.w) if ((cc->geom.w += mx) < 1)
cc->ptr.x = cc->geom.w - cc->bwidth; cc->geom.w = 1;
if (cc->ptr.y > cc->geom.h) if ((cc->geom.h += my) < 1)
cc->ptr.y = cc->geom.h - cc->bwidth; cc->geom.h = 1;
client_ptrwarp(cc); client_resize(cc, 1);
break;
case CWM_PTRMOVE: /* Make sure the pointer stays within the window. */
xu_ptr_getpos(sc->rootwin, &x, &y); xu_ptr_getpos(cc->win, &cc->ptr.x, &cc->ptr.y);
xu_ptr_setpos(sc->rootwin, x + mx, y + my); if (cc->ptr.x > cc->geom.w)
break; cc->ptr.x = cc->geom.w - cc->bwidth;
default: if (cc->ptr.y > cc->geom.h)
warnx("invalid flags passed to kbfunc_client_moveresize"); cc->ptr.y = cc->geom.h - cc->bwidth;
} client_ptrwarp(cc);
} }
void void