diff options
author | fluxgen <fluxgen> | 2003-09-06 13:58:06 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-09-06 13:58:06 (GMT) |
commit | 85316137bacf8a5c8a3ee4b48e7b7253615ba60c (patch) | |
tree | a92e1b38cf3e5b608360f996c054174fff0075a2 /src | |
parent | e67aa125ff0cde31580c804355d8021556c3f52d (diff) | |
download | fluxbox_paul-85316137bacf8a5c8a3ee4b48e7b7253615ba60c.zip fluxbox_paul-85316137bacf8a5c8a3ee4b48e7b7253615ba60c.tar.bz2 |
moved modifier detection to FbTk KeyUtil
Diffstat (limited to 'src')
-rw-r--r-- | src/Keys.cc | 94 | ||||
-rw-r--r-- | 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 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | //$Id: Keys.cc,v 1.36 2003/08/19 16:19:28 fluxgen Exp $ | 22 | //$Id: Keys.cc,v 1.37 2003/09/06 13:58:06 fluxgen Exp $ |
23 | 23 | ||
24 | 24 | ||
25 | #include "Keys.hh" | 25 | #include "Keys.hh" |
26 | 26 | ||
27 | #include "StringUtil.hh" | 27 | #include "FbTk/StringUtil.hh" |
28 | #include "App.hh" | 28 | #include "FbTk/App.hh" |
29 | #include "Command.hh" | 29 | #include "FbTk/Command.hh" |
30 | #include "FbTk/KeyUtil.hh" | ||
31 | |||
30 | #include "CommandParser.hh" | 32 | #include "CommandParser.hh" |
31 | 33 | ||
32 | #ifdef HAVE_CONFIG_H | 34 | #ifdef HAVE_CONFIG_H |
@@ -71,10 +73,6 @@ | |||
71 | 73 | ||
72 | using namespace std; | 74 | using namespace std; |
73 | 75 | ||
74 | int Keys::s_capslock_mod = 0; | ||
75 | int Keys::s_numlock_mod = 0; | ||
76 | int Keys::s_scrolllock_mod = 0; | ||
77 | |||
78 | Keys::Keys(const char *filename): | 76 | Keys::Keys(const char *filename): |
79 | m_display(FbTk::App::instance()->display()), | 77 | m_display(FbTk::App::instance()->display()), |
80 | m_modmap(0) { | 78 | m_modmap(0) { |
@@ -86,9 +84,9 @@ Keys::Keys(const char *filename): | |||
86 | } | 84 | } |
87 | 85 | ||
88 | Keys::~Keys() { | 86 | Keys::~Keys() { |
89 | if (m_modmap) { | 87 | if (m_modmap) |
90 | XFreeModifiermap(m_modmap); | 88 | XFreeModifiermap(m_modmap); |
91 | } | 89 | |
92 | ungrabKeys(); | 90 | ungrabKeys(); |
93 | deleteTree(); | 91 | deleteTree(); |
94 | } | 92 | } |
@@ -223,12 +221,24 @@ bool Keys::load(const char *filename) { | |||
223 | return true; | 221 | return true; |
224 | } | 222 | } |
225 | 223 | ||
224 | void Keys::loadModmap() { | ||
225 | if (m_modmap) | ||
226 | XFreeModifiermap(m_modmap); | ||
227 | |||
228 | m_modmap = XGetModifierMapping(m_display); | ||
229 | // force reinit of modifiers | ||
230 | FbTk::KeyUtil::init(); | ||
231 | } | ||
232 | |||
226 | /** | 233 | /** |
227 | Grabs a key with the modifier | 234 | Grabs a key with the modifier |
228 | and with numlock,capslock and scrollock | 235 | and with numlock,capslock and scrollock |
229 | */ | 236 | */ |
230 | void Keys::grabKey(unsigned int key, unsigned int mod) { | 237 | void Keys::grabKey(unsigned int key, unsigned int mod) { |
231 | 238 | const int capsmod = FbTk::KeyUtil::capslockMod(); | |
239 | const int nummod = FbTk::KeyUtil::numlockMod(); | ||
240 | const int scrollmod = FbTk::KeyUtil::scrolllockMod(); | ||
241 | |||
232 | for (int screen=0; screen<ScreenCount(m_display); screen++) { | 242 | for (int screen=0; screen<ScreenCount(m_display); screen++) { |
233 | 243 | ||
234 | Window root = RootWindow(m_display, screen); | 244 | Window root = RootWindow(m_display, screen); |
@@ -240,35 +250,35 @@ void Keys::grabKey(unsigned int key, unsigned int mod) { | |||
240 | // Grab with numlock, capslock and scrlock | 250 | // Grab with numlock, capslock and scrlock |
241 | 251 | ||
242 | //numlock | 252 | //numlock |
243 | XGrabKey(m_display, key, mod|s_numlock_mod, | 253 | XGrabKey(m_display, key, mod|nummod, |
244 | root, True, | 254 | root, True, |
245 | GrabModeAsync, GrabModeAsync); | 255 | GrabModeAsync, GrabModeAsync); |
246 | //scrolllock | 256 | //scrolllock |
247 | XGrabKey(m_display, key, mod|s_scrolllock_mod, | 257 | XGrabKey(m_display, key, mod|scrollmod, |
248 | root, True, | 258 | root, True, |
249 | GrabModeAsync, GrabModeAsync); | 259 | GrabModeAsync, GrabModeAsync); |
250 | //capslock | 260 | //capslock |
251 | XGrabKey(m_display, key, mod|s_capslock_mod, | 261 | XGrabKey(m_display, key, mod|capsmod, |
252 | root, True, | 262 | root, True, |
253 | GrabModeAsync, GrabModeAsync); | 263 | GrabModeAsync, GrabModeAsync); |
254 | 264 | ||
255 | //capslock+numlock | 265 | //capslock+numlock |
256 | XGrabKey(m_display, key, mod|s_capslock_mod|s_numlock_mod, | 266 | XGrabKey(m_display, key, mod|capsmod|nummod, |
257 | root, True, | 267 | root, True, |
258 | GrabModeAsync, GrabModeAsync); | 268 | GrabModeAsync, GrabModeAsync); |
259 | 269 | ||
260 | //capslock+scrolllock | 270 | //capslock+scrolllock |
261 | XGrabKey(m_display, key, mod|s_capslock_mod|s_scrolllock_mod, | 271 | XGrabKey(m_display, key, mod|capsmod|scrollmod, |
262 | root, True, | 272 | root, True, |
263 | GrabModeAsync, GrabModeAsync); | 273 | GrabModeAsync, GrabModeAsync); |
264 | 274 | ||
265 | //capslock+numlock+scrolllock | 275 | //capslock+numlock+scrolllock |
266 | XGrabKey(m_display, key, mod|s_capslock_mod|s_scrolllock_mod|s_numlock_mod, | 276 | XGrabKey(m_display, key, mod|capsmod|scrollmod|nummod, |
267 | root, True, | 277 | root, True, |
268 | GrabModeAsync, GrabModeAsync); | 278 | GrabModeAsync, GrabModeAsync); |
269 | 279 | ||
270 | //numlock+scrollLock | 280 | //numlock+scrollLock |
271 | XGrabKey(m_display, key, mod|s_numlock_mod|s_scrolllock_mod, | 281 | XGrabKey(m_display, key, mod|nummod|scrollmod, |
272 | root, True, | 282 | root, True, |
273 | GrabModeAsync, GrabModeAsync); | 283 | GrabModeAsync, GrabModeAsync); |
274 | 284 | ||
@@ -325,7 +335,7 @@ unsigned int Keys::getKey(const char *keystr) { | |||
325 | void Keys::doAction(XKeyEvent &ke) { | 335 | void Keys::doAction(XKeyEvent &ke) { |
326 | static t_key *next_key = 0; | 336 | static t_key *next_key = 0; |
327 | // Remove numlock, capslock and scrolllock | 337 | // Remove numlock, capslock and scrolllock |
328 | ke.state = cleanMods(ke.state); | 338 | ke.state = FbTk::KeyUtil::cleanMods(ke.state); |
329 | 339 | ||
330 | if (!next_key) { | 340 | if (!next_key) { |
331 | 341 | ||
@@ -444,52 +454,6 @@ Keys::t_key::~t_key() { | |||
444 | 454 | ||
445 | } | 455 | } |
446 | 456 | ||
447 | /** | ||
448 | * load state relating to the modifier map | ||
449 | */ | ||
450 | void Keys::loadModmap() { | ||
451 | if (m_modmap) { | ||
452 | XFreeModifiermap(m_modmap); | ||
453 | } | ||
454 | m_modmap = XGetModifierMapping(m_display); | ||
455 | |||
456 | // mask to use for modifier | ||
457 | int mods[] = { | ||
458 | ShiftMask, | ||
459 | LockMask, | ||
460 | ControlMask, | ||
461 | Mod1Mask, | ||
462 | Mod2Mask, | ||
463 | Mod3Mask, | ||
464 | Mod4Mask, | ||
465 | Mod5Mask, | ||
466 | 0 | ||
467 | }; | ||
468 | |||
469 | // find modifiers and set them | ||
470 | for (int i=0, realkey=0; i<8; ++i) { | ||
471 | for (int key=0; key<m_modmap->max_keypermod; ++key, ++realkey) { | ||
472 | |||
473 | if (m_modmap->modifiermap[realkey] == 0) | ||
474 | continue; | ||
475 | |||
476 | KeySym ks = XKeycodeToKeysym(m_display, m_modmap->modifiermap[realkey], 0); | ||
477 | |||
478 | switch (ks) { | ||
479 | case XK_Caps_Lock: | ||
480 | s_capslock_mod = mods[i]; | ||
481 | break; | ||
482 | case XK_Scroll_Lock: | ||
483 | s_scrolllock_mod = mods[i]; | ||
484 | break; | ||
485 | case XK_Num_Lock: | ||
486 | s_numlock_mod = mods[i]; | ||
487 | break; | ||
488 | } | ||
489 | } | ||
490 | } | ||
491 | } | ||
492 | |||
493 | unsigned int Keys::keycodeToModmask(unsigned int keycode) { | 457 | unsigned int Keys::keycodeToModmask(unsigned int keycode) { |
494 | if (!m_modmap) return 0; | 458 | if (!m_modmap) return 0; |
495 | 459 | ||
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 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: Keys.hh,v 1.27 2003/08/19 16:18:54 fluxgen Exp $ | 22 | // $Id: Keys.hh,v 1.28 2003/09/06 13:58:06 fluxgen Exp $ |
23 | 23 | ||
24 | #ifndef KEYS_HH | 24 | #ifndef KEYS_HH |
25 | #define KEYS_HH | 25 | #define KEYS_HH |
@@ -46,17 +46,9 @@ public: | |||
46 | /// destructor | 46 | /// destructor |
47 | ~Keys(); | 47 | ~Keys(); |
48 | 48 | ||
49 | /** | ||
50 | Strip out modifiers we want to ignore | ||
51 | @return the cleaned state number | ||
52 | */ | ||
53 | static unsigned int cleanMods(unsigned int mods) | ||
54 | //remove numlock, capslock and scrolllock | ||
55 | { return mods & (~s_capslock_mod & ~s_numlock_mod & ~s_scrolllock_mod); } | ||
56 | |||
57 | unsigned int keycodeToModmask(unsigned int keycode); | 49 | unsigned int keycodeToModmask(unsigned int keycode); |
58 | void loadModmap(); | ||
59 | 50 | ||
51 | void loadModmap(); | ||
60 | /** | 52 | /** |
61 | Load configuration from file | 53 | Load configuration from file |
62 | @return true on success, else false | 54 | @return true on success, else false |
@@ -132,13 +124,11 @@ private: | |||
132 | */ | 124 | */ |
133 | bool mergeTree(t_key *newtree, t_key *basetree=0); | 125 | bool mergeTree(t_key *newtree, t_key *basetree=0); |
134 | 126 | ||
135 | static int s_capslock_mod, s_numlock_mod, s_scrolllock_mod; ///< modifiers | ||
136 | |||
137 | std::vector<t_key *> m_keylist; | 127 | std::vector<t_key *> m_keylist; |
138 | std::string m_execcmdstring; ///< copy of the execcommandstring | 128 | |
139 | int m_param; ///< copy of the param argument | 129 | Display *m_display; ///< display connection |
140 | Display *m_display; ///< display connection | 130 | XModifierKeymap *m_modmap; |
141 | XModifierKeymap *m_modmap; ///< Modifier->keycode mapping | 131 | |
142 | }; | 132 | }; |
143 | 133 | ||
144 | #endif // KEYS_HH | 134 | #endif // KEYS_HH |