From e81c12ba73d4e86fe08110f8fa1fabc02745626c Mon Sep 17 00:00:00 2001 From: oga Date: Tue, 17 Jun 2008 23:40:33 +0000 Subject: 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. --- xutil.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'xutil.c') diff --git a/xutil.c b/xutil.c index ad58c00..a76d5c0 100644 --- a/xutil.c +++ b/xutil.c @@ -15,12 +15,14 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $Id: xutil.c,v 1.6 2008/05/15 22:18:00 oga Exp $ + * $Id: xutil.c,v 1.7 2008/06/17 23:40:33 oga Exp $ */ #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 -- cgit v1.2.3-2-gb3c3