summary refs log tree commit diff
diff options
context:
space:
mode:
authoroga <oga>2008-06-17 23:40:33 +0000
committeroga <oga>2008-06-17 23:40:33 +0000
commit4f2d4724c961aac55558069973f8a20bf01d8338 (patch)
tree274432e36f535ac87a4e355edf5c87ee7cdf5af0
parent19ba704ee3b16bcf4a29c223c5796a7f63fa6b6d (diff)
downloadcwm-4f2d4724c961aac55558069973f8a20bf01d8338.tar.gz
cwm-4f2d4724c961aac55558069973f8a20bf01d8338.tar.xz
cwm-4f2d4724c961aac55558069973f8a20bf01d8338.zip
Ignore caps lock and numlock for keyboard bindings. The way Xlib makes
you do this is ugly. Also remove mod2 (numlock) and mod3 (odd) from the
list of keybinding modifiers. They don't make much sense here.

based on a heavily modified diff from Martynas.

ok okan.
-rw-r--r--calmwm.h2
-rw-r--r--conf.c8
-rw-r--r--cwmrc.56
-rw-r--r--xevents.c6
-rw-r--r--xutil.c25
5 files changed, 25 insertions, 22 deletions
diff --git a/calmwm.h b/calmwm.h
index 72aa1e0..33b4949 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -384,7 +384,7 @@ void			 xev_register(struct xevent *);
 void			 xev_loop(void);
 
 int			 xu_ptr_grab(Window, int, Cursor);
-int			 xu_btn_grab(Window, int, u_int);
+void			 xu_btn_grab(Window, int, u_int);
 int			 xu_ptr_regrab(int, Cursor);
 void			 xu_btn_ungrab(Window, int, u_int);
 void			 xu_ptr_ungrab(void);
diff --git a/conf.c b/conf.c
index f05390c..1767d14 100644
--- a/conf.c
+++ b/conf.c
@@ -323,14 +323,6 @@ conf_bindname(struct conf *c, char *name, char *binding)
 	    strchr(name, 'M') < strchr(name, '-'))
 		current_binding->modmask |= Mod1Mask;
 
-	if (strchr(name, '2') != NULL &&
-	    strchr(name, '2') < strchr(name, '-'))
-		current_binding->modmask |= Mod2Mask;
-
-	if (strchr(name, '3') != NULL &&
-	    strchr(name, '3') < strchr(name, '-'))
-		current_binding->modmask |= Mod3Mask;
-
 	if (strchr(name, '4') != NULL &&
 	    strchr(name, '4') < strchr(name, '-'))
 		current_binding->modmask |= Mod4Mask;
diff --git a/cwmrc.5 b/cwmrc.5
index 10be912..c19efad 100644
--- a/cwmrc.5
+++ b/cwmrc.5
@@ -15,7 +15,7 @@
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
 .\" The following requests are required for all man pages.
-.Dd $Mdocdate: June 13 2008 $
+.Dd $Mdocdate: June 14 2008 $
 .Dt CWMRC 5
 .Os
 .Sh NAME
@@ -57,10 +57,6 @@ The Control key.
 The Meta key.
 .It S
 The Shift key.
-.It 2
-The Mod2 key.
-.It 3
-The Mod3 key.
 .It 4
 The Mod4 key (normally the windows key).
 .El
diff --git a/xevents.c b/xevents.c
index dc3ac87..b4f068c 100644
--- a/xevents.c
+++ b/xevents.c
@@ -228,6 +228,9 @@ xev_handle_buttonpress(struct xevent *xev, XEvent *ee)
 
 	cc = client_find(e->window);
 
+	/* Ignore caps lock and numlock */
+	e->state &= ~(Mod2Mask | LockMask);
+
 	TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
 		if (e->button == mb->button && e->state == mb->modmask)
 			break;
@@ -273,6 +276,9 @@ xev_handle_keypress(struct xevent *xev, XEvent *ee)
 	keysym = XKeycodeToKeysym(X_Dpy, e->keycode, 0);
 	skeysym = XKeycodeToKeysym(X_Dpy, e->keycode, 1);
 
+	/* we don't care about caps lock and numlock here */
+	e->state &= ~(LockMask | Mod2Mask);
+
 	TAILQ_FOREACH(kb, &Conf.keybindingq, entry) {
 		if (keysym != kb->keysym && skeysym == kb->keysym)
 			modshift = ShiftMask;
diff --git a/xutil.c b/xutil.c
index 09c6eda..0c60fa6 100644
--- a/xutil.c
+++ b/xutil.c
@@ -21,6 +21,8 @@
 #include "headers.h"
 #include "calmwm.h"
 
+unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask };
+
 int
 xu_ptr_grab(Window win, int mask, Cursor curs)
 {
@@ -42,18 +44,22 @@ xu_ptr_ungrab(void)
 	XUngrabPointer(X_Dpy, CurrentTime);
 }
 
-int
+void
 xu_btn_grab(Window win, int mask, u_int btn)
 {
-	return (XGrabButton(X_Dpy, btn, mask, win,
-	    False, ButtonMask, GrabModeAsync,
-	    GrabModeSync, None, None) == GrabSuccess ? 0 : -1);
+	int	i;
+	for (i = 0; i < sizeof(ign_mods)/sizeof(*ign_mods); i++)
+		XGrabButton(X_Dpy, btn, (mask | ign_mods[i]), win,
+		    False, ButtonMask, GrabModeAsync,
+		    GrabModeSync, None, None);
 }
 
 void
 xu_btn_ungrab(Window win, int mask, u_int btn)
 {
-	XUngrabButton(X_Dpy, btn, mask, win);
+	int	i;
+	for (i = 0; i < sizeof(ign_mods)/sizeof(*ign_mods); i++)
+		XUngrabButton(X_Dpy, btn, (mask | ign_mods[i]), win);
 }
 
 void
@@ -75,15 +81,18 @@ xu_ptr_setpos(Window win, int x, int y)
 void
 xu_key_grab(Window win, int mask, int keysym)
 {
-	KeyCode code;
+	KeyCode	code;
+	int	i;
 
 	code = XKeysymToKeycode(X_Dpy, keysym);
 	if ((XKeycodeToKeysym(X_Dpy, code, 0) != keysym) &&
 	    (XKeycodeToKeysym(X_Dpy, code, 1) == keysym))
 		mask |= ShiftMask;
 
-	XGrabKey(X_Dpy, XKeysymToKeycode(X_Dpy, keysym), mask, win, True,
-	    GrabModeAsync, GrabModeAsync);
+	for (i = 0; i < sizeof(ign_mods)/sizeof(*ign_mods); i++)
+		XGrabKey(X_Dpy, XKeysymToKeycode(X_Dpy, keysym),
+		    (mask | ign_mods[i]), win, True, GrabModeAsync,
+		    GrabModeAsync);
 }
 
 void