implement keyboard initiated movement of windows

enhanced version of diff originally from niallo@
man bits from niallo@
ok niallo@ japser@
This commit is contained in:
todd 2007-06-27 13:28:22 +00:00
parent a1d4169eb3
commit 365aecd25e
4 changed files with 74 additions and 0 deletions

View File

@ -204,6 +204,11 @@ enum kbtype {
KB__LAST
};
#define CWM_BIGMOVE 0x1000
enum directions {
CWM_UP=0, CWM_DOWN, CWM_LEFT, CWM_RIGHT,
};
#define KBFLAG_NEEDCLIENT 0x01
#define KBFLAG_FINDCLIENT 0x02
@ -426,6 +431,7 @@ void kbfunc_client_prevgroup(struct client_ctx *, void *);
void kbfunc_client_nogroup(struct client_ctx *, void *);
void kbfunc_client_maximize(struct client_ctx *, void *);
void kbfunc_client_vmaximize(struct client_ctx *, void *);
void kbfunc_client_move(struct client_ctx *, void *);
void kbfunc_menu_search(struct client_ctx *, void *);
void kbfunc_exec(struct client_ctx *, void *);
void kbfunc_ssh(struct client_ctx *, void *);

21
conf.c
View File

@ -20,6 +20,7 @@
#define CONF_MAX_WINTITLE 256
#define CONF_IGNORECASE 0x01
/*
* Match a window.
*/
@ -237,6 +238,26 @@ conf_setup(struct conf *c)
XK_f, ControlMask|Mod1Mask, KBFLAG_NEEDCLIENT, 0);
conf_bindkey(c, kbfunc_client_vmaximize,
XK_equal, ControlMask|Mod1Mask, KBFLAG_NEEDCLIENT, 0);
conf_bindkey(c, kbfunc_client_move,
XK_k, Mod1Mask, KBFLAG_NEEDCLIENT, (void *)CWM_UP);
conf_bindkey(c, kbfunc_client_move,
XK_j, Mod1Mask, KBFLAG_NEEDCLIENT, (void *)CWM_DOWN);
conf_bindkey(c, kbfunc_client_move,
XK_l, Mod1Mask, KBFLAG_NEEDCLIENT, (void *)CWM_RIGHT);
conf_bindkey(c, kbfunc_client_move,
XK_h, Mod1Mask, KBFLAG_NEEDCLIENT, (void *)CWM_LEFT);
conf_bindkey(c, kbfunc_client_move,
XK_K, Mod1Mask, KBFLAG_NEEDCLIENT,
(void *)(CWM_UP|CWM_BIGMOVE));
conf_bindkey(c, kbfunc_client_move,
XK_J, Mod1Mask, KBFLAG_NEEDCLIENT,
(void *)(CWM_DOWN|CWM_BIGMOVE));
conf_bindkey(c, kbfunc_client_move,
XK_L, Mod1Mask, KBFLAG_NEEDCLIENT,
(void *)(CWM_RIGHT|CWM_BIGMOVE));
conf_bindkey(c, kbfunc_client_move,
XK_H, Mod1Mask, KBFLAG_NEEDCLIENT,
(void *)(CWM_LEFT|CWM_BIGMOVE));
}
snprintf(dir_settings, sizeof(dir_settings),

7
cwm.1
View File

@ -126,6 +126,13 @@ font string
.Ar fontname
the default font.
.El
.Sh WINDOW MOVEMENT
.Nm
windows can be moved with the use of the keyboard through Vi-like bindings.
M-[hjkl] moves the current window a small amount, while M-shift-[hjkl] moves
the current window a larger amount.
For example, to move the current window to the left a small amount, press M-h.
To move the current window down by a larger amount, press M-shift-j.
.Sh SEARCH
.Nm
features the ability to search for windows by their current title, old

View File

@ -14,6 +14,7 @@
#define KNOWN_HOSTS ".ssh/known_hosts"
#define HASH_MARKER "|1|"
#define MOVE_AMOUNT 10
void
kbfunc_client_lower(struct client_ctx *cc, void *arg)
@ -27,6 +28,45 @@ kbfunc_client_raise(struct client_ctx *cc, void *arg)
client_raise(cc);
}
void
kbfunc_client_move(struct client_ctx *cc, void *arg)
{
int x,y,flags,amt;
u_int mx,my;
mx = my = 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;
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_search(struct client_ctx *scratch, void *arg)
{