X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fmodkeys.c;h=3346a88dccd2f78f021e829d9c90526cf7aeb605;hb=b0aa29db6973d3a052980459c413c1c193bcc671;hp=4f0ddca94c078fae96cdc1ae8c5195d762e5dea2;hpb=7e946f68d9f8ec7c880664b437edbbaa5d49ac10;p=chaz%2Fopenbox diff --git a/openbox/modkeys.c b/openbox/modkeys.c index 4f0ddca9..3346a88d 100644 --- a/openbox/modkeys.c +++ b/openbox/modkeys.c @@ -20,6 +20,7 @@ #include "openbox.h" #include +#include /* These masks are constants and the modifier keys are bound to them as anyone sees fit: @@ -27,7 +28,7 @@ Mod2Mask (1<<4), Mod3Mask (1<<5), Mod4Mask (1<<6), Mod5Mask (1<<7) */ #define NUM_MASKS 8 -#define ALL_MASKS 0xf /* an or'ing of all 8 keyboard masks */ +#define ALL_MASKS 0xff /* an or'ing of all 8 keyboard masks */ /* Get the bitflag for the n'th modifier mask */ #define nth_mask(n) (1 << n) @@ -35,21 +36,27 @@ static void set_modkey_mask(guchar mask, KeySym sym); static XModifierKeymap *modmap; +static KeySym *keymap; +static gint min_keycode, max_keycode, keysyms_per_keycode; /* This is a bitmask of the different masks for each modifier key */ static guchar modkeys_keys[OB_MODKEY_NUM_KEYS]; void modkeys_startup(gboolean reconfigure) { - /* keycodes for the modifier keys which will be bound to the masks */ gint i, j, k; - modmap = XGetModifierMapping(ob_display); - g_assert(modmap->max_keypermod > 0); - /* reset the keys to not be bound to any masks */ for (i = 0; i < OB_MODKEY_NUM_KEYS; ++i) modkeys_keys[i] = 0; + modmap = XGetModifierMapping(ob_display); + g_assert(modmap->max_keypermod > 0); + + XDisplayKeycodes(ob_display, &min_keycode, &max_keycode); + keymap = XGetKeyboardMapping(ob_display, min_keycode, + max_keycode - min_keycode + 1, + &keysyms_per_keycode); + /* go through each of the modifier masks (eg ShiftMask, CapsMask...) */ for (i = 0; i < NUM_MASKS; ++i) { /* go through each keycode that is bound to the mask */ @@ -57,13 +64,16 @@ void modkeys_startup(gboolean reconfigure) KeySym sym; /* get a keycode that is bound to the mask (i) */ KeyCode keycode = modmap->modifiermap[i*modmap->max_keypermod + j]; - /* go through each keysym bound to the given keycode */ - for (k = 0; ; ++k) { - sym = XKeycodeToKeysym(ob_display, keycode, k); - if (sym == NoSymbol) break; - - /* bind the key to the mask (e.g. Alt_L => Mod1Mask) */ - set_modkey_mask(nth_mask(i), sym); + if (keycode) { + /* go through each keysym bound to the given keycode */ + for (k = 0; k < keysyms_per_keycode; ++k) { + sym = keymap[(keycode-min_keycode) * keysyms_per_keycode + + k]; + if (sym != NoSymbol) { + /* bind the key to the mask (e.g. Alt_L => Mod1Mask) */ + set_modkey_mask(nth_mask(i), sym); + } + } } } } @@ -72,6 +82,7 @@ void modkeys_startup(gboolean reconfigure) void modkeys_shutdown(gboolean reconfigure) { XFreeModifiermap(modmap); + XFree(keymap); } guint modkeys_keycode_to_mask(guint keycode) @@ -131,3 +142,16 @@ static void set_modkey_mask(guchar mask, KeySym sym) else if (sym == XK_Meta_L || sym == XK_Meta_R) modkeys_keys[OB_MODKEY_KEY_META] |= mask; } + +KeyCode modkeys_sym_to_code(KeySym sym) +{ + gint i, j; + + /* go through each keycode and look for the keysym */ + for (i = min_keycode; i <= max_keycode; ++i) + for (j = 0; j < keysyms_per_keycode; ++j) + if (sym == keymap[(i-min_keycode) * keysyms_per_keycode + j]) + return i; + return 0; +} +