[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Xbindkeys-devel] [PATCH] Prevent xbindkeys from grabing all keys if Key
From: |
Nicolas Boichat |
Subject: |
[Xbindkeys-devel] [PATCH] Prevent xbindkeys from grabing all keys if KeySym is not mapped on current layout |
Date: |
Tue, 4 Jun 2013 12:52:02 +0800 |
Hi,
xbindkeys grabs all keys if the specified KeySym is not mapped on the
current keyboard layout, making it impossible to type anything.
This is because XKeysymToKeycode returns 0 if KeySym is not mapped,
and 0 also happens to mean "AnyKey".
This patch checks the return value, and warns the user if necessary.
Example test case: Overlay1_Enable is not mapped on standard PC keyboards.
; Map Search+click to middle button
(xbindkey-function '(Overlay1_Enable) (lambda ()
; Map on Release so that it does not appear both buttons are pressed
(xbindkey '(release "b:1") "xte 'mouseclick 2'")
(grab-all-keys)
))
(xbindkey-function '(release Overlay1_Enable) (lambda ()
(remove-xbindkey '(release "b:1"))
(grab-all-keys)
))
Thank you and best regards,
Nicolas
---
grab_key.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/grab_key.c b/grab_key.c
index 0702f0a..1a867a3 100644
--- a/grab_key.c
+++ b/grab_key.c
@@ -226,8 +226,27 @@ grab_keys (Display * dpy)
{
for (screen = 0; screen < ScreenCount (dpy); screen++)
{
- my_grab_key (dpy, XKeysymToKeycode (dpy, keys[i].key.sym),
- keys[i].modifier, RootWindow (dpy, screen));
+ KeyCode code = XKeysymToKeycode (dpy, keys[i].key.sym);
+ if (code != 0)
+ {
+ my_grab_key (dpy, code,
+ keys[i].modifier, RootWindow (dpy, screen));
+ }
+ else
+ {
+ fprintf (stderr, "--- xbindkeys error ---\n");
+ if (!verbose)
+ {
+ verbose = 1;
+ print_key (dpy, &keys[i]);
+ verbose = 0;
+ }
+ fprintf (stderr,
+ " The key symbol '%s' cannot be used, as it's not
mapped\n"
+ " on your keyboard.\n"
+ " xbindkeys will keep running, but will ignore this
symbol.\n",
+ XKeysymToString (keys[i].key.sym));
+ }
}
}
else if (keys[i].type == BUTTON)
--
1.8.3
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Xbindkeys-devel] [PATCH] Prevent xbindkeys from grabing all keys if KeySym is not mapped on current layout,
Nicolas Boichat <=