Replace XKeysymToKeycode

See github issue #60

XKeysymToKeycode fails on keyboard-layouts that have the same keysym on
different keycodes.
This commit is contained in:
Sascha Kruse 2012-09-10 20:47:01 +02:00
parent 1a4deea501
commit 3e3235f522

17
dunst.c
View File

@ -11,6 +11,7 @@
#include <fnmatch.h> #include <fnmatch.h>
#include <getopt.h> #include <getopt.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#ifdef XINERAMA #ifdef XINERAMA
@ -1049,7 +1050,21 @@ void init_shortcut(keyboard_shortcut * ks)
strtrim_end(str); strtrim_end(str);
ks->sym = XStringToKeysym(str); ks->sym = XStringToKeysym(str);
ks->code = XKeysymToKeycode(dc->dpy, ks->sym); /* find matching keycode for ks->sym */
int min_keysym, max_keysym;
XDisplayKeycodes(dc->dpy, &min_keysym, &max_keysym);
ks->code = NoSymbol;
int level = ks->mask & ShiftMask ? 1 : 0;
for (int i = min_keysym; i <= max_keysym; i++) {
if (XkbKeycodeToKeysym(dc->dpy, i, 0, level) == ks->sym) {
ks->code = i;
break;
}
}
if (ks->sym == NoSymbol || ks->code == NoSymbol) { if (ks->sym == NoSymbol || ks->code == NoSymbol) {
fprintf(stderr, "Warning: Unknown keyboard shortcut: %s\n", fprintf(stderr, "Warning: Unknown keyboard shortcut: %s\n",