all repos — fluxbox @ 85316137bacf8a5c8a3ee4b48e7b7253615ba60c

custom fork of the fluxbox windowmanager

moved modifier detection to FbTk KeyUtil
fluxgen fluxgen
commit

85316137bacf8a5c8a3ee4b48e7b7253615ba60c

parent

e67aa125ff0cde31580c804355d8021556c3f52d

2 files changed, 35 insertions(+), 81 deletions(-)

jump to
M src/Keys.ccsrc/Keys.cc

@@ -19,14 +19,16 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -//$Id: Keys.cc,v 1.36 2003/08/19 16:19:28 fluxgen Exp $ +//$Id: Keys.cc,v 1.37 2003/09/06 13:58:06 fluxgen Exp $ #include "Keys.hh" -#include "StringUtil.hh" -#include "App.hh" -#include "Command.hh" +#include "FbTk/StringUtil.hh" +#include "FbTk/App.hh" +#include "FbTk/Command.hh" +#include "FbTk/KeyUtil.hh" + #include "CommandParser.hh" #ifdef HAVE_CONFIG_H

@@ -71,10 +73,6 @@ #include <memory>

using namespace std; -int Keys::s_capslock_mod = 0; -int Keys::s_numlock_mod = 0; -int Keys::s_scrolllock_mod = 0; - Keys::Keys(const char *filename): m_display(FbTk::App::instance()->display()), m_modmap(0) {

@@ -86,9 +84,9 @@ load(filename);

} Keys::~Keys() { - if (m_modmap) { + if (m_modmap) XFreeModifiermap(m_modmap); - } + ungrabKeys(); deleteTree(); }

@@ -223,12 +221,24 @@

return true; } +void Keys::loadModmap() { + if (m_modmap) + XFreeModifiermap(m_modmap); + + m_modmap = XGetModifierMapping(m_display); + // force reinit of modifiers + FbTk::KeyUtil::init(); +} + /** Grabs a key with the modifier and with numlock,capslock and scrollock */ void Keys::grabKey(unsigned int key, unsigned int mod) { - + const int capsmod = FbTk::KeyUtil::capslockMod(); + const int nummod = FbTk::KeyUtil::numlockMod(); + const int scrollmod = FbTk::KeyUtil::scrolllockMod(); + for (int screen=0; screen<ScreenCount(m_display); screen++) { Window root = RootWindow(m_display, screen);

@@ -240,35 +250,35 @@

// Grab with numlock, capslock and scrlock //numlock - XGrabKey(m_display, key, mod|s_numlock_mod, + XGrabKey(m_display, key, mod|nummod, root, True, GrabModeAsync, GrabModeAsync); //scrolllock - XGrabKey(m_display, key, mod|s_scrolllock_mod, + XGrabKey(m_display, key, mod|scrollmod, root, True, GrabModeAsync, GrabModeAsync); //capslock - XGrabKey(m_display, key, mod|s_capslock_mod, + XGrabKey(m_display, key, mod|capsmod, root, True, GrabModeAsync, GrabModeAsync); //capslock+numlock - XGrabKey(m_display, key, mod|s_capslock_mod|s_numlock_mod, + XGrabKey(m_display, key, mod|capsmod|nummod, root, True, GrabModeAsync, GrabModeAsync); //capslock+scrolllock - XGrabKey(m_display, key, mod|s_capslock_mod|s_scrolllock_mod, + XGrabKey(m_display, key, mod|capsmod|scrollmod, root, True, GrabModeAsync, GrabModeAsync); //capslock+numlock+scrolllock - XGrabKey(m_display, key, mod|s_capslock_mod|s_scrolllock_mod|s_numlock_mod, + XGrabKey(m_display, key, mod|capsmod|scrollmod|nummod, root, True, GrabModeAsync, GrabModeAsync); //numlock+scrollLock - XGrabKey(m_display, key, mod|s_numlock_mod|s_scrolllock_mod, + XGrabKey(m_display, key, mod|nummod|scrollmod, root, True, GrabModeAsync, GrabModeAsync);

@@ -325,7 +335,7 @@ */

void Keys::doAction(XKeyEvent &ke) { static t_key *next_key = 0; // Remove numlock, capslock and scrolllock - ke.state = cleanMods(ke.state); + ke.state = FbTk::KeyUtil::cleanMods(ke.state); if (!next_key) {

@@ -442,52 +452,6 @@ keylist.pop_back();

} } -} - -/** - * load state relating to the modifier map - */ -void Keys::loadModmap() { - if (m_modmap) { - XFreeModifiermap(m_modmap); - } - m_modmap = XGetModifierMapping(m_display); - - // mask to use for modifier - int mods[] = { - ShiftMask, - LockMask, - ControlMask, - Mod1Mask, - Mod2Mask, - Mod3Mask, - Mod4Mask, - Mod5Mask, - 0 - }; - - // find modifiers and set them - for (int i=0, realkey=0; i<8; ++i) { - for (int key=0; key<m_modmap->max_keypermod; ++key, ++realkey) { - - if (m_modmap->modifiermap[realkey] == 0) - continue; - - KeySym ks = XKeycodeToKeysym(m_display, m_modmap->modifiermap[realkey], 0); - - switch (ks) { - case XK_Caps_Lock: - s_capslock_mod = mods[i]; - break; - case XK_Scroll_Lock: - s_scrolllock_mod = mods[i]; - break; - case XK_Num_Lock: - s_numlock_mod = mods[i]; - break; - } - } - } } unsigned int Keys::keycodeToModmask(unsigned int keycode) {
M src/Keys.hhsrc/Keys.hh

@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Keys.hh,v 1.27 2003/08/19 16:18:54 fluxgen Exp $ +// $Id: Keys.hh,v 1.28 2003/09/06 13:58:06 fluxgen Exp $ #ifndef KEYS_HH #define KEYS_HH

@@ -46,17 +46,9 @@ explicit Keys(const char *filename=0);

/// destructor ~Keys(); - /** - Strip out modifiers we want to ignore - @return the cleaned state number - */ - static unsigned int cleanMods(unsigned int mods) - //remove numlock, capslock and scrolllock - { return mods & (~s_capslock_mod & ~s_numlock_mod & ~s_scrolllock_mod); } + unsigned int keycodeToModmask(unsigned int keycode); - unsigned int keycodeToModmask(unsigned int keycode); void loadModmap(); - /** Load configuration from file @return true on success, else false

@@ -132,13 +124,11 @@ @return true on success, else false

*/ bool mergeTree(t_key *newtree, t_key *basetree=0); - static int s_capslock_mod, s_numlock_mod, s_scrolllock_mod; ///< modifiers - std::vector<t_key *> m_keylist; - std::string m_execcmdstring; ///< copy of the execcommandstring - int m_param; ///< copy of the param argument - Display *m_display; ///< display connection - XModifierKeymap *m_modmap; ///< Modifier->keycode mapping + + Display *m_display; ///< display connection + XModifierKeymap *m_modmap; + }; #endif // KEYS_HH