cvsimport
* refs/heads/master: more client vs screen context differences If a client sets hints, honor them for kb resize requests, just like we do for mouse based resize requests. 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. pledge "stdio rpath proc exec" cwm before main event loop, after init/setup - mostly for menu building. Partial revert of replacing screen_area() with region_find(); until a fix for a regression is found; this bug has been around for a long time it seems, but this change exposed it. Likely need to track clients in to and out of regions. Use position on root to figure out region. Start cleaning up name vs function differences; replace magic numbers. Clean up unused defines. Extend region to include both view and work areas; switch to region_find() which no longer needs to recalculate gap each time a client (or menu) is created or altered. If no RandR, fall back to display dimensions while building regions instead of during execution.
This commit is contained in:
209
kbfunc.c
209
kbfunc.c
@@ -38,6 +38,8 @@
|
||||
|
||||
extern sig_atomic_t cwm_status;
|
||||
|
||||
static void kbfunc_amount(int, unsigned int *, unsigned int *);
|
||||
|
||||
void
|
||||
kbfunc_client_lower(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
@@ -51,98 +53,113 @@ kbfunc_client_raise(struct client_ctx *cc, union arg *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_moveresize(struct client_ctx *cc, union arg *arg)
|
||||
static void
|
||||
kbfunc_amount(int flags, unsigned int *mx, unsigned int *my)
|
||||
{
|
||||
struct screen_ctx *sc = cc->sc;
|
||||
struct geom area;
|
||||
int x, y, flags, amt;
|
||||
unsigned int mx, my;
|
||||
#define CWM_FACTOR 10
|
||||
int amt;
|
||||
|
||||
if (cc->flags & CLIENT_FREEZE)
|
||||
return;
|
||||
|
||||
mx = my = 0;
|
||||
|
||||
flags = arg->i;
|
||||
amt = Conf.mamount;
|
||||
if (flags & CWM_BIGAMOUNT)
|
||||
amt *= CWM_FACTOR;
|
||||
|
||||
if (flags & CWM_BIGMOVE) {
|
||||
flags -= CWM_BIGMOVE;
|
||||
amt = amt * 10;
|
||||
}
|
||||
|
||||
switch (flags & MOVEMASK) {
|
||||
switch (flags & DIRECTIONMASK) {
|
||||
case CWM_UP:
|
||||
my -= amt;
|
||||
*my -= amt;
|
||||
break;
|
||||
case CWM_DOWN:
|
||||
my += amt;
|
||||
*my += amt;
|
||||
break;
|
||||
case CWM_RIGHT:
|
||||
mx += amt;
|
||||
*mx += amt;
|
||||
break;
|
||||
case CWM_LEFT:
|
||||
mx -= amt;
|
||||
*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,
|
||||
cc->geom.x + cc->geom.w / 2,
|
||||
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);
|
||||
xu_ptr_getpos(cc->win, &x, &y);
|
||||
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. */
|
||||
xu_ptr_getpos(cc->win, &cc->ptr.x, &cc->ptr.y);
|
||||
if (cc->ptr.x > cc->geom.w)
|
||||
cc->ptr.x = cc->geom.w - cc->bwidth;
|
||||
if (cc->ptr.y > cc->geom.h)
|
||||
cc->ptr.y = cc->geom.h - cc->bwidth;
|
||||
client_ptrwarp(cc);
|
||||
break;
|
||||
case CWM_PTRMOVE:
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_search(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 geom area;
|
||||
int x, y;
|
||||
unsigned int mx = 0, my = 0;
|
||||
|
||||
if (cc->flags & CLIENT_FREEZE)
|
||||
return;
|
||||
|
||||
kbfunc_amount(arg->i, &mx, &my);
|
||||
|
||||
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,
|
||||
cc->geom.x + cc->geom.w / 2,
|
||||
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);
|
||||
|
||||
xu_ptr_getpos(cc->win, &x, &y);
|
||||
cc->ptr.x = x + mx;
|
||||
cc->ptr.y = y + my;
|
||||
client_ptrwarp(cc);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_resize(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
unsigned int mx = 0, my = 0;
|
||||
|
||||
if (cc->flags & CLIENT_FREEZE)
|
||||
return;
|
||||
|
||||
kbfunc_amount(arg->i, &mx, &my);
|
||||
|
||||
if ((cc->geom.w += mx * cc->hint.incw) < cc->hint.minw)
|
||||
cc->geom.w = cc->hint.minw;
|
||||
if ((cc->geom.h += my * cc->hint.inch) < cc->hint.minh)
|
||||
cc->geom.h = cc->hint.minh;
|
||||
client_resize(cc, 1);
|
||||
|
||||
/* Make sure the pointer stays within the window. */
|
||||
xu_ptr_getpos(cc->win, &cc->ptr.x, &cc->ptr.y);
|
||||
if (cc->ptr.x > cc->geom.w)
|
||||
cc->ptr.x = cc->geom.w - cc->bwidth;
|
||||
if (cc->ptr.y > cc->geom.h)
|
||||
cc->ptr.y = cc->geom.h - cc->bwidth;
|
||||
client_ptrwarp(cc);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_menu_client(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
struct screen_ctx *sc = cc->sc;
|
||||
struct client_ctx *old_cc;
|
||||
@@ -230,13 +247,13 @@ kbfunc_client_hide(struct client_ctx *cc, union arg *arg)
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_cmdexec(struct client_ctx *cc, union arg *arg)
|
||||
kbfunc_exec(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
u_spawn(arg->c);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_term(struct client_ctx *cc, union arg *arg)
|
||||
kbfunc_exec_term(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
|
||||
@@ -247,7 +264,7 @@ kbfunc_term(struct client_ctx *cc, union arg *arg)
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_lock(struct client_ctx *cc, union arg *arg)
|
||||
kbfunc_exec_lock(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
|
||||
@@ -258,7 +275,7 @@ kbfunc_lock(struct client_ctx *cc, union arg *arg)
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_exec(struct client_ctx *cc, union arg *arg)
|
||||
kbfunc_menu_exec(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
#define NPATHS 256
|
||||
struct screen_ctx *sc = cc->sc;
|
||||
@@ -273,14 +290,14 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg)
|
||||
struct stat sb;
|
||||
|
||||
switch (cmd) {
|
||||
case CWM_EXEC_PROGRAM:
|
||||
case CWM_MENU_EXEC:
|
||||
label = "exec";
|
||||
break;
|
||||
case CWM_EXEC_WM:
|
||||
case CWM_MENU_EXEC_WM:
|
||||
label = "wm";
|
||||
break;
|
||||
default:
|
||||
errx(1, "kbfunc_exec: invalid cmd %d", cmd);
|
||||
errx(1, "kbfunc_menu_exec: invalid cmd %d", cmd);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
@@ -327,11 +344,11 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg)
|
||||
if (mi->text[0] == '\0')
|
||||
goto out;
|
||||
switch (cmd) {
|
||||
case CWM_EXEC_PROGRAM:
|
||||
case CWM_MENU_EXEC:
|
||||
u_spawn(mi->text);
|
||||
break;
|
||||
case CWM_EXEC_WM:
|
||||
cwm_status = CWM_EXECWM;
|
||||
case CWM_MENU_EXEC_WM:
|
||||
cwm_status = CWM_EXEC_WM;
|
||||
free(wm_argv);
|
||||
wm_argv = xstrdup(mi->text);
|
||||
break;
|
||||
@@ -347,7 +364,7 @@ out:
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_ssh(struct client_ctx *cc, union arg *arg)
|
||||
kbfunc_menu_ssh(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
struct screen_ctx *sc = cc->sc;
|
||||
struct cmd *cmd;
|
||||
@@ -367,7 +384,7 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
|
||||
TAILQ_INIT(&menuq);
|
||||
|
||||
if ((fp = fopen(Conf.known_hosts, "r")) == NULL) {
|
||||
warn("kbfunc_ssh: %s", Conf.known_hosts);
|
||||
warn("kbfunc_menu_ssh: %s", Conf.known_hosts);
|
||||
goto menu;
|
||||
}
|
||||
|
||||
@@ -439,25 +456,25 @@ kbfunc_client_delete(struct client_ctx *cc, union arg *arg)
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_group(struct client_ctx *cc, union arg *arg)
|
||||
kbfunc_group_toggle(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
group_hidetoggle(cc->sc, arg->i);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_grouponly(struct client_ctx *cc, union arg *arg)
|
||||
kbfunc_group_only(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
group_only(cc->sc, arg->i);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_cyclegroup(struct client_ctx *cc, union arg *arg)
|
||||
kbfunc_group_cycle(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
group_cycle(cc->sc, arg->i);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_nogroup(struct client_ctx *cc, union arg *arg)
|
||||
kbfunc_group_alltoggle(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
group_alltoggle(cc->sc);
|
||||
}
|
||||
@@ -465,7 +482,7 @@ kbfunc_client_nogroup(struct client_ctx *cc, union arg *arg)
|
||||
void
|
||||
kbfunc_client_grouptoggle(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
if (arg->i == 0) {
|
||||
if (arg->i == CWM_KBD) {
|
||||
/* For X apps that steal events. */
|
||||
XGrabKeyboard(X_Dpy, cc->win, True,
|
||||
GrabModeAsync, GrabModeAsync, CurrentTime);
|
||||
@@ -523,13 +540,13 @@ kbfunc_cwm_status(struct client_ctx *cc, union arg *arg)
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_tile(struct client_ctx *cc, union arg *arg)
|
||||
kbfunc_client_tile(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
switch (arg->i) {
|
||||
case CWM_TILE_HORIZ:
|
||||
case CWM_CLIENT_TILE_HORIZ:
|
||||
client_htile(cc);
|
||||
break;
|
||||
case CWM_TILE_VERT:
|
||||
case CWM_CLIENT_TILE_VERT:
|
||||
client_vtile(cc);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user