diff options
-rw-r--r-- | src/Keys.cc | 74 | ||||
-rw-r--r-- | src/Keys.hh | 11 |
2 files changed, 33 insertions, 52 deletions
diff --git a/src/Keys.cc b/src/Keys.cc index 64eb05d..b73eb67 100644 --- a/src/Keys.cc +++ b/src/Keys.cc | |||
@@ -127,22 +127,20 @@ int extractKeyFromString(const std::string& in, const char* start_pattern, unsig | |||
127 | return ret; | 127 | return ret; |
128 | } | 128 | } |
129 | 129 | ||
130 | } // end of anonymouse namespace | 130 | } // end of anonymous namespace |
131 | 131 | ||
132 | // helper class 'keytree' | 132 | // helper class 'keytree' |
133 | class Keys::t_key { | 133 | class Keys::t_key { |
134 | public: | 134 | public: |
135 | 135 | ||
136 | // typedefs | 136 | // typedefs |
137 | typedef std::list<t_key*> keylist_t; | 137 | typedef std::list<RefKey> keylist_t; |
138 | 138 | ||
139 | // constructor / destructor | 139 | // constructor / destructor |
140 | t_key(int type, unsigned int mod, unsigned int key, int context, | 140 | t_key(int type = 0, unsigned int mod = 0, unsigned int key = 0, int context = 0, |
141 | bool isdouble); | 141 | bool isdouble = false); |
142 | t_key(t_key *k); | ||
143 | ~t_key(); | ||
144 | 142 | ||
145 | t_key *find(int type_, unsigned int mod_, unsigned int key_, | 143 | RefKey find(int type_, unsigned int mod_, unsigned int key_, |
146 | int context_, bool isdouble_) { | 144 | int context_, bool isdouble_) { |
147 | // t_key ctor sets context_ of 0 to GLOBAL, so we must here too | 145 | // t_key ctor sets context_ of 0 to GLOBAL, so we must here too |
148 | context_ = context_ ? context_ : GLOBAL; | 146 | context_ = context_ ? context_ : GLOBAL; |
@@ -154,7 +152,7 @@ public: | |||
154 | FbTk::KeyUtil::instance().isolateModifierMask(mod_)) | 152 | FbTk::KeyUtil::instance().isolateModifierMask(mod_)) |
155 | return *it; | 153 | return *it; |
156 | } | 154 | } |
157 | return 0; | 155 | return RefKey(); |
158 | } | 156 | } |
159 | 157 | ||
160 | // member variables | 158 | // member variables |
@@ -180,22 +178,6 @@ Keys::t_key::t_key(int type_, unsigned int mod_, unsigned int key_, | |||
180 | context = context_ ? context_ : GLOBAL; | 178 | context = context_ ? context_ : GLOBAL; |
181 | } | 179 | } |
182 | 180 | ||
183 | Keys::t_key::t_key(t_key *k) { | ||
184 | key = k->key; | ||
185 | mod = k->mod; | ||
186 | type = k->type; | ||
187 | context = k->context; | ||
188 | isdouble = k->isdouble; | ||
189 | m_command = k->m_command; | ||
190 | } | ||
191 | |||
192 | Keys::t_key::~t_key() { | ||
193 | for (keylist_t::iterator list_it = keylist.begin(); list_it != keylist.end(); ++list_it) | ||
194 | delete *list_it; | ||
195 | keylist.clear(); | ||
196 | } | ||
197 | |||
198 | |||
199 | 181 | ||
200 | Keys::Keys(): | 182 | Keys::Keys(): |
201 | m_reloader(new FbTk::AutoReloadHelper()), | 183 | m_reloader(new FbTk::AutoReloadHelper()), |
@@ -218,10 +200,10 @@ Keys::~Keys() { | |||
218 | /// Destroys the keytree | 200 | /// Destroys the keytree |
219 | void Keys::deleteTree() { | 201 | void Keys::deleteTree() { |
220 | 202 | ||
221 | destroyAndClearSecond(m_map); | 203 | m_map.clear(); |
222 | m_keylist = 0; | 204 | m_keylist.reset(); |
223 | next_key = 0; | 205 | next_key.reset(); |
224 | saved_keymode = 0; | 206 | saved_keymode.reset(); |
225 | } | 207 | } |
226 | 208 | ||
227 | // keys are only grabbed in global context | 209 | // keys are only grabbed in global context |
@@ -324,7 +306,7 @@ void Keys::reload() { | |||
324 | // free memory of previous grabs | 306 | // free memory of previous grabs |
325 | deleteTree(); | 307 | deleteTree(); |
326 | 308 | ||
327 | m_map["default:"] = new t_key(0,0,0,0,false); | 309 | m_map["default:"] = FbTk::makeRef<t_key>(); |
328 | 310 | ||
329 | unsigned int current_line = 0; //so we can tell the user where the fault is | 311 | unsigned int current_line = 0; //so we can tell the user where the fault is |
330 | 312 | ||
@@ -354,7 +336,7 @@ void Keys::loadDefaults() { | |||
354 | fbdbg<<"Loading default key bindings"<<endl; | 336 | fbdbg<<"Loading default key bindings"<<endl; |
355 | 337 | ||
356 | deleteTree(); | 338 | deleteTree(); |
357 | m_map["default:"] = new t_key(0,0,0,0,false); | 339 | m_map["default:"] = FbTk::makeRef<t_key>(); |
358 | addBinding("OnDesktop Mouse1 :HideMenus"); | 340 | addBinding("OnDesktop Mouse1 :HideMenus"); |
359 | addBinding("OnDesktop Mouse2 :WorkspaceMenu"); | 341 | addBinding("OnDesktop Mouse2 :WorkspaceMenu"); |
360 | addBinding("OnDesktop Mouse3 :RootMenu"); | 342 | addBinding("OnDesktop Mouse3 :RootMenu"); |
@@ -387,14 +369,14 @@ bool Keys::addBinding(const string &linebuffer) { | |||
387 | int type = 0, context = 0; | 369 | int type = 0, context = 0; |
388 | bool isdouble = false; | 370 | bool isdouble = false; |
389 | size_t argc = 0; | 371 | size_t argc = 0; |
390 | t_key *current_key=m_map["default:"]; | 372 | RefKey current_key = m_map["default:"]; |
391 | t_key *first_new_keylist = current_key, *first_new_key=0; | 373 | RefKey first_new_keylist = current_key, first_new_key; |
392 | 374 | ||
393 | if (val[0][val[0].length()-1] == ':') { | 375 | if (val[0][val[0].length()-1] == ':') { |
394 | argc++; | 376 | argc++; |
395 | keyspace_t::iterator it = m_map.find(val[0]); | 377 | keyspace_t::iterator it = m_map.find(val[0]); |
396 | if (it == m_map.end()) | 378 | if (it == m_map.end()) |
397 | m_map[val[0]] = new t_key(0,0,0,0,false); | 379 | m_map[val[0]] = FbTk::makeRef<t_key>(); |
398 | current_key = m_map[val[0]]; | 380 | current_key = m_map[val[0]]; |
399 | } | 381 | } |
400 | // for each argument | 382 | // for each argument |
@@ -489,14 +471,14 @@ bool Keys::addBinding(const string &linebuffer) { | |||
489 | current_key = current_key->find(type, mod, key, context, | 471 | current_key = current_key->find(type, mod, key, context, |
490 | isdouble); | 472 | isdouble); |
491 | if (!current_key) { | 473 | if (!current_key) { |
492 | first_new_key = new t_key(type, mod, key, context, | 474 | first_new_key.reset( new t_key(type, mod, key, context, |
493 | isdouble); | 475 | isdouble) ); |
494 | current_key = first_new_key; | 476 | current_key = first_new_key; |
495 | } else if (current_key->m_command) // already being used | 477 | } else if (current_key->m_command) // already being used |
496 | return false; | 478 | return false; |
497 | } else { | 479 | } else { |
498 | t_key *temp_key = new t_key(type, mod, key, context, | 480 | RefKey temp_key( new t_key(type, mod, key, context, |
499 | isdouble); | 481 | isdouble) ); |
500 | current_key->keylist.push_back(temp_key); | 482 | current_key->keylist.push_back(temp_key); |
501 | current_key = temp_key; | 483 | current_key = temp_key; |
502 | } | 484 | } |
@@ -514,12 +496,10 @@ bool Keys::addBinding(const string &linebuffer) { | |||
514 | const char *str = FbTk::StringUtil::strcasestr(linebuffer.c_str(), | 496 | const char *str = FbTk::StringUtil::strcasestr(linebuffer.c_str(), |
515 | val[argc].c_str()); | 497 | val[argc].c_str()); |
516 | if (str) // +1 to skip ':' | 498 | if (str) // +1 to skip ':' |
517 | current_key->m_command = FbTk::CommandParser<void>::instance().parse(str + 1); | 499 | current_key->m_command.reset(FbTk::CommandParser<void>::instance().parse(str + 1)); |
518 | 500 | ||
519 | if (!str || current_key->m_command == 0 || mod) { | 501 | if (!str || current_key->m_command == 0 || mod) |
520 | delete first_new_key; | ||
521 | return false; | 502 | return false; |
522 | } | ||
523 | 503 | ||
524 | // success | 504 | // success |
525 | first_new_keylist->keylist.push_back(first_new_key); | 505 | first_new_keylist->keylist.push_back(first_new_key); |
@@ -563,7 +543,7 @@ bool Keys::doAction(int type, unsigned int mods, unsigned int key, | |||
563 | next_key = m_keylist; | 543 | next_key = m_keylist; |
564 | 544 | ||
565 | mods = FbTk::KeyUtil::instance().cleanMods(mods); | 545 | mods = FbTk::KeyUtil::instance().cleanMods(mods); |
566 | t_key *temp_key = next_key->find(type, mods, key, context, isdouble); | 546 | RefKey temp_key = next_key->find(type, mods, key, context, isdouble); |
567 | 547 | ||
568 | // just because we double-clicked doesn't mean we shouldn't look for single | 548 | // just because we double-clicked doesn't mean we shouldn't look for single |
569 | // click commands | 549 | // click commands |
@@ -581,10 +561,10 @@ bool Keys::doAction(int type, unsigned int mods, unsigned int key, | |||
581 | if (type == KeyPress && | 561 | if (type == KeyPress && |
582 | !FbTk::KeyUtil::instance().keycodeToModmask(key)) { | 562 | !FbTk::KeyUtil::instance().keycodeToModmask(key)) { |
583 | // if we're in the middle of an emacs-style keychain, exit it | 563 | // if we're in the middle of an emacs-style keychain, exit it |
584 | next_key = 0; | 564 | next_key.reset(); |
585 | if (saved_keymode) { | 565 | if (saved_keymode) { |
586 | setKeyMode(saved_keymode); | 566 | setKeyMode(saved_keymode); |
587 | saved_keymode = 0; | 567 | saved_keymode.reset(); |
588 | } | 568 | } |
589 | } | 569 | } |
590 | return false; | 570 | return false; |
@@ -603,9 +583,9 @@ bool Keys::doAction(int type, unsigned int mods, unsigned int key, | |||
603 | if (saved_keymode) { | 583 | if (saved_keymode) { |
604 | if (next_key == m_keylist) // don't reset keymode if command changed it | 584 | if (next_key == m_keylist) // don't reset keymode if command changed it |
605 | setKeyMode(saved_keymode); | 585 | setKeyMode(saved_keymode); |
606 | saved_keymode = 0; | 586 | saved_keymode.reset(); |
607 | } | 587 | } |
608 | next_key = 0; | 588 | next_key.reset(); |
609 | return true; | 589 | return true; |
610 | } | 590 | } |
611 | 591 | ||
@@ -636,7 +616,7 @@ void Keys::keyMode(const string& keyMode) { | |||
636 | setKeyMode(it->second); | 616 | setKeyMode(it->second); |
637 | } | 617 | } |
638 | 618 | ||
639 | void Keys::setKeyMode(t_key *keyMode) { | 619 | void Keys::setKeyMode(const FbTk::RefCount<t_key> &keyMode) { |
640 | ungrabKeys(); | 620 | ungrabKeys(); |
641 | ungrabButtons(); | 621 | ungrabButtons(); |
642 | 622 | ||
diff --git a/src/Keys.hh b/src/Keys.hh index 2dc1c10..e51911d 100644 --- a/src/Keys.hh +++ b/src/Keys.hh | |||
@@ -93,7 +93,8 @@ public: | |||
93 | 93 | ||
94 | private: | 94 | private: |
95 | class t_key; // helper class to build a 'keytree' | 95 | class t_key; // helper class to build a 'keytree' |
96 | typedef std::map<std::string, t_key *> keyspace_t; | 96 | typedef FbTk::RefCount<t_key> RefKey; |
97 | typedef std::map<std::string, RefKey> keyspace_t; | ||
97 | typedef std::map<Window, int> WindowMap; | 98 | typedef std::map<Window, int> WindowMap; |
98 | typedef std::map<Window, FbTk::EventHandler*> HandlerMap; | 99 | typedef std::map<Window, FbTk::EventHandler*> HandlerMap; |
99 | 100 | ||
@@ -107,16 +108,16 @@ private: | |||
107 | 108 | ||
108 | // Load default keybindings for when there are errors loading the keys file | 109 | // Load default keybindings for when there are errors loading the keys file |
109 | void loadDefaults(); | 110 | void loadDefaults(); |
110 | void setKeyMode(t_key *keyMode); | 111 | void setKeyMode(const FbTk::RefCount<t_key> &keyMode); |
111 | 112 | ||
112 | 113 | ||
113 | // member variables | 114 | // member variables |
114 | FbTk::AutoReloadHelper* m_reloader; | 115 | FbTk::AutoReloadHelper* m_reloader; |
115 | t_key *m_keylist; | 116 | RefKey m_keylist; |
116 | keyspace_t m_map; | 117 | keyspace_t m_map; |
117 | 118 | ||
118 | // former doAction static var, we need to access it from deleteTree | 119 | RefKey next_key; |
119 | t_key *next_key, *saved_keymode; | 120 | RefKey saved_keymode; |
120 | 121 | ||
121 | WindowMap m_window_map; | 122 | WindowMap m_window_map; |
122 | HandlerMap m_handler_map; | 123 | HandlerMap m_handler_map; |