diff options
author | oga <oga> | 2008-04-16 13:47:29 +0000 |
---|---|---|
committer | oga <oga> | 2008-04-16 13:47:29 +0000 |
commit | 898bfff36a8ce64146f1e1bc4452859dbda7595d (patch) | |
tree | 0c7b647808cd43e370e086e9deca87f3ddda6eda /kbfunc.c | |
parent | cd5c340e011da37650125d75c40aedda51757a5b (diff) | |
download | cwm-898bfff36a8ce64146f1e1bc4452859dbda7595d.tar.gz cwm-898bfff36a8ce64146f1e1bc4452859dbda7595d.tar.xz cwm-898bfff36a8ce64146f1e1bc4452859dbda7595d.zip |
merge kbfunc_{ptrmove,client_{move,resize}} into one function that takes a flag,
this code was almost identical... ok okan.
Diffstat (limited to 'kbfunc.c')
-rw-r--r-- | kbfunc.c | 123 |
1 files changed, 36 insertions, 87 deletions
diff --git a/kbfunc.c b/kbfunc.c index a512137..a6e0da5 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -41,9 +41,12 @@ kbfunc_client_raise(struct client_ctx *cc, void *arg) client_raise(cc); } +#define typemask (CWM_MOVE | CWM_RESIZE | CWM_PTRMOVE) +#define movemask (CWM_UP | CWM_DOWN | CWM_LEFT | CWM_RIGHT) void -kbfunc_client_move(struct client_ctx *cc, void *arg) +kbfunc_moveresize(struct client_ctx *cc, void *arg) { + struct screen_ctx *sc = screen_current(); int x,y,flags,amt; u_int mx,my; @@ -57,47 +60,7 @@ kbfunc_client_move(struct client_ctx *cc, void *arg) amt = amt*10; } - switch (flags) { - case CWM_UP: - my -= amt; - break; - case CWM_DOWN: - my += amt; - break; - case CWM_RIGHT: - mx += amt; - break; - case CWM_LEFT: - mx -= amt; - break; - } - - cc->geom.y += my; - cc->geom.x += mx; - client_move(cc); - xu_ptr_getpos(cc->pwin, &x, &y); - cc->ptr.y = y + my; - cc->ptr.x = x + mx; - client_ptrwarp(cc); -} - -void -kbfunc_client_resize(struct client_ctx *cc, void *arg) -{ - int flags,mx,my; - u_int amt; - - mx = my = 0; - - flags = (int)arg; - amt = MOVE_AMOUNT; - - if (flags & CWM_BIGMOVE) { - flags -= CWM_BIGMOVE; - amt = amt*10; - } - - switch (flags) { + switch (flags & movemask) { case CWM_UP: my -= amt; break; @@ -111,56 +74,42 @@ kbfunc_client_resize(struct client_ctx *cc, void *arg) mx -= amt; break; } - - cc->geom.height += my; - cc->geom.width += mx; - client_resize(cc); - - /* - * Moving the cursor while resizing is problematic. Just place - * it in the middle of the window. - */ - cc->ptr.x = -1; - cc->ptr.y = -1; - client_ptrwarp(cc); -} - -void -kbfunc_ptrmove(struct client_ctx *cc, void *arg) -{ - int px,py,mx,my,flags,amt; - struct screen_ctx *sc = screen_current(); - my = mx = 0; - - flags = (int)arg; - amt = MOVE_AMOUNT; - - if (flags & CWM_BIGMOVE) { - flags -= CWM_BIGMOVE; - amt = amt * 10; - } - switch (flags) { - case CWM_UP: - my -= amt; - break; - case CWM_DOWN: - my += amt; + switch (flags & typemask) { + case CWM_MOVE: + cc->geom.y += my; + cc->geom.x += mx; + client_move(cc); + xu_ptr_getpos(cc->pwin, &x, &y); + cc->ptr.y = y + my; + cc->ptr.x = x + mx; + client_ptrwarp(cc); break; - case CWM_RIGHT: - mx += amt; + case CWM_RESIZE: + cc->geom.height += my; + cc->geom.width += mx; + client_resize(cc); + + /* + * Moving the cursor while resizing is problematic. Just place + * it in the middle of the window. + */ + cc->ptr.x = -1; + cc->ptr.y = -1; + client_ptrwarp(cc); break; - case CWM_LEFT: - mx -= amt; + case CWM_PTRMOVE: + if (cc) { + xu_ptr_getpos(cc->pwin, &x, &y); + xu_ptr_setpos(cc->pwin, x + mx, y + my); + } else { + xu_ptr_getpos(sc->rootwin, &x, &y); + xu_ptr_setpos(sc->rootwin, x + mx, y + my); + } break; + default: + warnx("invalid flags passed to kbfunc_client_moveresize"); } - if (cc) { - xu_ptr_getpos(cc->pwin, &px, &py); - xu_ptr_setpos(cc->pwin, px + mx, py + my); - } else { - xu_ptr_getpos(sc->rootwin, &px, &py); - xu_ptr_setpos(sc->rootwin, px + mx, py + my); - } } void |