summary refs log tree commit diff
diff options
context:
space:
mode:
authortodd <todd>2007-06-27 13:28:22 +0000
committertodd <todd>2007-06-27 13:28:22 +0000
commit365aecd25e854df386f1980d925301a9b0e8056f (patch)
tree43465a24d19bacad058bb201652920a650436b4a
parenta1d4169eb318f504f3a869ec429517de25eb5427 (diff)
downloadcwm-365aecd25e854df386f1980d925301a9b0e8056f.tar.gz
cwm-365aecd25e854df386f1980d925301a9b0e8056f.tar.xz
cwm-365aecd25e854df386f1980d925301a9b0e8056f.zip
implement keyboard initiated movement of windows
enhanced version of diff originally from niallo@
man bits from niallo@
ok niallo@ japser@
-rw-r--r--calmwm.h6
-rw-r--r--conf.c21
-rw-r--r--cwm.17
-rw-r--r--kbfunc.c40
4 files changed, 74 insertions, 0 deletions
diff --git a/calmwm.h b/calmwm.h
index 5bbd3c0..4e9afbf 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -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 *);
diff --git a/conf.c b/conf.c
index 299d480..59c1b5b 100644
--- a/conf.c
+++ b/conf.c
@@ -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),
diff --git a/cwm.1 b/cwm.1
index 6092c88..b73447f 100644
--- a/cwm.1
+++ b/cwm.1
@@ -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
diff --git a/kbfunc.c b/kbfunc.c
index 23a0d1c..1b7cfc4 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -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)
@@ -28,6 +29,45 @@ kbfunc_client_raise(struct client_ctx *cc, void *arg)
 }
 
 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)
 {
 	struct menu_q menuq;