From 85316137bacf8a5c8a3ee4b48e7b7253615ba60c Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sat, 6 Sep 2003 13:58:06 +0000 Subject: moved modifier detection to FbTk KeyUtil --- src/Keys.cc | 94 +++++++++++++++++++------------------------------------------ src/Keys.hh | 22 ++++----------- 2 files changed, 35 insertions(+), 81 deletions(-) diff --git a/src/Keys.cc b/src/Keys.cc index 196c5e0..1667f43 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -19,14 +19,16 @@ // 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 @@ 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 @@ Keys::Keys(const char *filename): } Keys::~Keys() { - if (m_modmap) { + if (m_modmap) XFreeModifiermap(m_modmap); - } + ungrabKeys(); deleteTree(); } @@ -223,12 +221,24 @@ bool Keys::load(const char *filename) { 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; screenmax_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) { if (!m_modmap) return 0; diff --git a/src/Keys.hh b/src/Keys.hh index efd6331..f3a89bd 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.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 @@ public: /// 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); - void loadModmap(); + void loadModmap(); /** Load configuration from file @return true on success, else false @@ -132,13 +124,11 @@ private: */ bool mergeTree(t_key *newtree, t_key *basetree=0); - static int s_capslock_mod, s_numlock_mod, s_scrolllock_mod; ///< modifiers - std::vector 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 -- cgit v0.11.2