From 598ff7125d6b035e16bc854547846ca7b606e590 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Wed, 13 Nov 2002 14:35:01 +0000 Subject: determine lock masks --- src/Keys.cc | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/Keys.hh | 10 +++++++--- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/Keys.cc b/src/Keys.cc index 84953d9..c4185b7 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -//$Id: Keys.cc,v 1.19 2002/08/28 20:25:15 fluxgen Exp $ +//$Id: Keys.cc,v 1.20 2002/11/13 14:34:24 fluxgen Exp $ #include "Keys.hh" @@ -126,9 +126,13 @@ Keys::t_actionstr Keys::m_actionlist[] = { }; Keys::Keys(Display *display, const char *filename): +m_capslock_mod(0), +m_numlock_mod(0), +m_scrolllock_mod(0), m_abortkey(0), m_display(display) { + determineModmap(); assert(display); if (filename != 0) load(filename); @@ -363,35 +367,35 @@ void Keys::grabKey(unsigned int key, unsigned int mod) { // Grab with numlock, capslock and scrlock //numlock - XGrabKey(m_display, key, mod|Mod2Mask, + XGrabKey(m_display, key, mod|m_numlock_mod, root, True, GrabModeAsync, GrabModeAsync); //scrolllock - XGrabKey(m_display, key, mod|Mod5Mask, + XGrabKey(m_display, key, mod|m_scrolllock_mod, root, True, GrabModeAsync, GrabModeAsync); //capslock - XGrabKey(m_display, key, mod|LockMask, + XGrabKey(m_display, key, mod|m_capslock_mod, root, True, GrabModeAsync, GrabModeAsync); //capslock+numlock - XGrabKey(m_display, key, mod|LockMask|Mod2Mask, + XGrabKey(m_display, key, mod|m_capslock_mod|m_numlock_mod, root, True, GrabModeAsync, GrabModeAsync); //capslock+scrolllock - XGrabKey(m_display, key, mod|LockMask|Mod5Mask, + XGrabKey(m_display, key, mod|m_capslock_mod|m_scrolllock_mod, root, True, GrabModeAsync, GrabModeAsync); //capslock+numlock+scrolllock - XGrabKey(m_display, key, mod|Mod2Mask|Mod5Mask|LockMask, + XGrabKey(m_display, key, mod|m_capslock_mod|m_scrolllock_mod|m_numlock_mod, root, True, GrabModeAsync, GrabModeAsync); //numlock+scrollLock - XGrabKey(m_display, key, mod|Mod2Mask|Mod5Mask, + XGrabKey(m_display, key, mod|m_numlock_mod|m_scrolllock_mod, root, True, GrabModeAsync, GrabModeAsync); @@ -628,3 +632,43 @@ Keys::t_key::~t_key() { } } } + +void Keys::determineModmap() { + // mask to use for modifier + int mods[] = { + ShiftMask, + LockMask, + ControlMask, + Mod1Mask, + Mod2Mask, + Mod3Mask, + Mod4Mask, + Mod5Mask, + 0 + }; + + XModifierKeymap *map = XGetModifierMapping(m_display); + // find modifiers and set them + for (int i=0, realkey=0; i<8; ++i) { + for (int key=0; keymax_keypermod; ++key, ++realkey) { + + if (map->modifiermap[realkey] == 0) + continue; + + KeySym ks = XKeycodeToKeysym(m_display, map->modifiermap[realkey], 0); + + switch (ks) { + case XK_Caps_Lock: + m_capslock_mod = mods[i]; + break; + case XK_Scroll_Lock: + m_scrolllock_mod = mods[i]; + break; + case XK_Num_Lock: + m_numlock_mod = mods[i]; + break; + } + } + } + XFreeModifiermap(map); +} diff --git a/src/Keys.hh b/src/Keys.hh index 3351668..9f24fc3 100644 --- a/src/Keys.hh +++ b/src/Keys.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Keys.hh,v 1.15 2002/08/04 15:55:13 fluxgen Exp $ +// $Id: Keys.hh,v 1.16 2002/11/13 14:35:01 fluxgen Exp $ #ifndef KEYS_HH #define KEYS_HH @@ -165,12 +165,16 @@ private: /// debug function void showKeyTree(t_key *key, unsigned int w=0); #endif //DEBUG + /// determine key modifier maps for caps-, num- and scrolllock + void determineModmap(); struct t_actionstr{ const char *string; KeyAction action; - }; - + }; + + int m_capslock_mod, m_numlock_mod, m_scrolllock_mod; ///< modifiers + static t_actionstr m_actionlist[]; std::vector m_keylist; -- cgit v0.11.2