diff options
-rw-r--r-- | src/Keys.cc | 111 | ||||
-rw-r--r-- | src/Keys.hh | 60 | ||||
-rw-r--r-- | src/Screen.cc | 1 |
3 files changed, 91 insertions, 81 deletions
diff --git a/src/Keys.cc b/src/Keys.cc index 66ee022..c1e48a2 100644 --- a/src/Keys.cc +++ b/src/Keys.cc | |||
@@ -31,7 +31,8 @@ | |||
31 | #include "FbTk/StringUtil.hh" | 31 | #include "FbTk/StringUtil.hh" |
32 | #include "FbTk/App.hh" | 32 | #include "FbTk/App.hh" |
33 | #include "FbTk/Command.hh" | 33 | #include "FbTk/Command.hh" |
34 | 34 | #include "FbTk/RefCount.hh" | |
35 | #include "FbTk/KeyUtil.hh" | ||
35 | #include "FbTk/ObjectRegistry.hh" | 36 | #include "FbTk/ObjectRegistry.hh" |
36 | #include "FbTk/I18n.hh" | 37 | #include "FbTk/I18n.hh" |
37 | 38 | ||
@@ -90,6 +91,7 @@ | |||
90 | 91 | ||
91 | #include <iostream> | 92 | #include <iostream> |
92 | #include <fstream> | 93 | #include <fstream> |
94 | #include <list> | ||
93 | #include <vector> | 95 | #include <vector> |
94 | #include <map> | 96 | #include <map> |
95 | #include <memory> | 97 | #include <memory> |
@@ -101,7 +103,75 @@ using std::vector; | |||
101 | using std::ifstream; | 103 | using std::ifstream; |
102 | using std::pair; | 104 | using std::pair; |
103 | 105 | ||
104 | Keys::Keys(): m_display(FbTk::App::instance()->display()) { } | 106 | // helper class 'keytree' |
107 | class Keys::t_key { | ||
108 | public: | ||
109 | |||
110 | // typedefs | ||
111 | typedef std::list<t_key*> keylist_t; | ||
112 | |||
113 | // constructor / destructor | ||
114 | t_key(int type, unsigned int mod, unsigned int key, int context, | ||
115 | bool isdouble); | ||
116 | t_key(t_key *k); | ||
117 | ~t_key(); | ||
118 | |||
119 | t_key *find(int type_, unsigned int mod_, unsigned int key_, | ||
120 | int context_, bool isdouble_) { | ||
121 | // t_key ctor sets context_ of 0 to GLOBAL, so we must here too | ||
122 | context_ = context_ ? context_ : GLOBAL; | ||
123 | keylist_t::iterator it = keylist.begin(), it_end = keylist.end(); | ||
124 | for (; it != it_end; it++) { | ||
125 | if ((*it)->type == type_ && (*it)->key == key_ && | ||
126 | ((*it)->context & context_) > 0 && | ||
127 | isdouble_ == (*it)->isdouble && (*it)->mod == | ||
128 | FbTk::KeyUtil::instance().isolateModifierMask(mod_)) | ||
129 | return *it; | ||
130 | } | ||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | // member variables | ||
135 | |||
136 | int type; // KeyPress or ButtonPress | ||
137 | unsigned int mod; | ||
138 | unsigned int key; // key code or button number | ||
139 | int context; // ON_TITLEBAR, etc.: bitwise-or of all desired contexts | ||
140 | bool isdouble; | ||
141 | FbTk::RefCount<FbTk::Command> m_command; | ||
142 | |||
143 | keylist_t keylist; | ||
144 | }; | ||
145 | |||
146 | Keys::t_key::t_key(int type_, unsigned int mod_, unsigned int key_, | ||
147 | int context_, bool isdouble_) : | ||
148 | type(type_), | ||
149 | mod(mod_), | ||
150 | key(key_), | ||
151 | context(context_), | ||
152 | isdouble(isdouble_), | ||
153 | m_command(0) { | ||
154 | context = context_ ? context_ : GLOBAL; | ||
155 | } | ||
156 | |||
157 | Keys::t_key::t_key(t_key *k) { | ||
158 | key = k->key; | ||
159 | mod = k->mod; | ||
160 | type = k->type; | ||
161 | context = k->context; | ||
162 | isdouble = k->isdouble; | ||
163 | m_command = k->m_command; | ||
164 | } | ||
165 | |||
166 | Keys::t_key::~t_key() { | ||
167 | for (keylist_t::iterator list_it = keylist.begin(); list_it != keylist.end(); ++list_it) | ||
168 | delete *list_it; | ||
169 | keylist.clear(); | ||
170 | } | ||
171 | |||
172 | |||
173 | |||
174 | Keys::Keys() { } | ||
105 | 175 | ||
106 | Keys::~Keys() { | 176 | Keys::~Keys() { |
107 | ungrabKeys(); | 177 | ungrabKeys(); |
@@ -168,8 +238,8 @@ void Keys::grabWindow(Window win) { | |||
168 | return; | 238 | return; |
169 | 239 | ||
170 | m_handler_map[win]->grabButtons(); | 240 | m_handler_map[win]->grabButtons(); |
171 | keylist_t::iterator it = m_keylist->keylist.begin(); | 241 | t_key::keylist_t::iterator it = m_keylist->keylist.begin(); |
172 | keylist_t::iterator it_end = m_keylist->keylist.end(); | 242 | t_key::keylist_t::iterator it_end = m_keylist->keylist.end(); |
173 | for (; it != it_end; ++it) { | 243 | for (; it != it_end; ++it) { |
174 | // keys are only grabbed in global context | 244 | // keys are only grabbed in global context |
175 | if ((win_it->second & Keys::GLOBAL) > 0 && (*it)->type == KeyPress) | 245 | if ((win_it->second & Keys::GLOBAL) > 0 && (*it)->type == KeyPress) |
@@ -271,7 +341,7 @@ bool Keys::addBinding(const string &linebuffer) { | |||
271 | FbTk::StringUtil::stringtok(val, linebuffer.c_str()); | 341 | FbTk::StringUtil::stringtok(val, linebuffer.c_str()); |
272 | 342 | ||
273 | // must have at least 1 argument | 343 | // must have at least 1 argument |
274 | if (val.size() <= 0) | 344 | if (val.empty()) |
275 | return true; // empty lines are valid. | 345 | return true; // empty lines are valid. |
276 | 346 | ||
277 | if (val[0][0] == '#' || val[0][0] == '!' ) //the line is commented | 347 | if (val[0][0] == '#' || val[0][0] == '!' ) //the line is commented |
@@ -345,7 +415,7 @@ bool Keys::addBinding(const string &linebuffer) { | |||
345 | // +[1-9] - number between +1 and +9 | 415 | // +[1-9] - number between +1 and +9 |
346 | // numbers 10 and above | 416 | // numbers 10 and above |
347 | // | 417 | // |
348 | } else if (val[argc].size() > 1 && (isdigit(val[argc][0]) && | 418 | } else if (!val[argc].empty() && (isdigit(val[argc][0]) && |
349 | (isdigit(val[argc][1]) || val[argc][1] == 'x') || | 419 | (isdigit(val[argc][1]) || val[argc][1] == 'x') || |
350 | val[argc][0] == '+' && isdigit(val[argc][1])) ) { | 420 | val[argc][0] == '+' && isdigit(val[argc][1])) ) { |
351 | 421 | ||
@@ -512,7 +582,7 @@ bool Keys::reconfigure(const char *filename) { | |||
512 | return load(filename); | 582 | return load(filename); |
513 | } | 583 | } |
514 | 584 | ||
515 | void Keys::keyMode(string keyMode) { | 585 | void Keys::keyMode(const string& keyMode) { |
516 | keyspace_t::iterator it = m_map.find(keyMode + ":"); | 586 | keyspace_t::iterator it = m_map.find(keyMode + ":"); |
517 | if (it == m_map.end()) | 587 | if (it == m_map.end()) |
518 | setKeyMode(m_map["default:"]); | 588 | setKeyMode(m_map["default:"]); |
@@ -530,8 +600,8 @@ void Keys::setKeyMode(t_key *keyMode) { | |||
530 | for (; h_it != h_it_end; ++h_it) | 600 | for (; h_it != h_it_end; ++h_it) |
531 | h_it->second->grabButtons(); | 601 | h_it->second->grabButtons(); |
532 | 602 | ||
533 | keylist_t::iterator it = keyMode->keylist.begin(); | 603 | t_key::keylist_t::iterator it = keyMode->keylist.begin(); |
534 | keylist_t::iterator it_end = keyMode->keylist.end(); | 604 | t_key::keylist_t::iterator it_end = keyMode->keylist.end(); |
535 | for (; it != it_end; ++it) { | 605 | for (; it != it_end; ++it) { |
536 | if ((*it)->type == KeyPress) | 606 | if ((*it)->type == KeyPress) |
537 | grabKey((*it)->key, (*it)->mod); | 607 | grabKey((*it)->key, (*it)->mod); |
@@ -540,28 +610,5 @@ void Keys::setKeyMode(t_key *keyMode) { | |||
540 | } | 610 | } |
541 | m_keylist = keyMode; | 611 | m_keylist = keyMode; |
542 | } | 612 | } |
543 | |||
544 | Keys::t_key::t_key(int type_, unsigned int mod_, unsigned int key_, | ||
545 | int context_, bool isdouble_) { | ||
546 | key = key_; | ||
547 | mod = mod_; | ||
548 | type = type_; | ||
549 | context = context_ ? context_ : GLOBAL; | ||
550 | isdouble = isdouble_; | ||
551 | m_command = 0; | ||
552 | } | ||
553 | 613 | ||
554 | Keys::t_key::t_key(t_key *k) { | ||
555 | key = k->key; | ||
556 | mod = k->mod; | ||
557 | type = k->type; | ||
558 | context = k->context; | ||
559 | isdouble = k->isdouble; | ||
560 | m_command = k->m_command; | ||
561 | } | ||
562 | 614 | ||
563 | Keys::t_key::~t_key() { | ||
564 | for (keylist_t::iterator list_it = keylist.begin(); list_it != keylist.end(); ++list_it) | ||
565 | delete *list_it; | ||
566 | keylist.clear(); | ||
567 | } | ||
diff --git a/src/Keys.hh b/src/Keys.hh index 226d52b..03f11e0 100644 --- a/src/Keys.hh +++ b/src/Keys.hh | |||
@@ -25,12 +25,9 @@ | |||
25 | #define KEYS_HH | 25 | #define KEYS_HH |
26 | 26 | ||
27 | #include "FbTk/NotCopyable.hh" | 27 | #include "FbTk/NotCopyable.hh" |
28 | #include "FbTk/RefCount.hh" | ||
29 | #include "FbTk/Command.hh" | ||
30 | #include "FbTk/KeyUtil.hh" | ||
31 | 28 | ||
29 | #include <X11/Xlib.h> | ||
32 | #include <string> | 30 | #include <string> |
33 | #include <list> | ||
34 | #include <map> | 31 | #include <map> |
35 | 32 | ||
36 | 33 | ||
@@ -92,9 +89,14 @@ public: | |||
92 | @return true on success, else false | 89 | @return true on success, else false |
93 | */ | 90 | */ |
94 | bool reconfigure(const char *filename); | 91 | bool reconfigure(const char *filename); |
95 | const std::string filename() const { return m_filename; } | 92 | const std::string& filename() const { return m_filename; } |
96 | void keyMode(std::string keyMode); | 93 | void keyMode(const std::string& keyMode); |
97 | private: | 94 | private: |
95 | class t_key; // helper class to build a 'keytree' | ||
96 | typedef std::map<std::string, t_key *> keyspace_t; | ||
97 | typedef std::map<Window, int> WindowMap; | ||
98 | typedef std::map<Window, FbTk::EventHandler*> HandlerMap; | ||
99 | |||
98 | void deleteTree(); | 100 | void deleteTree(); |
99 | 101 | ||
100 | void grabKey(unsigned int key, unsigned int mod); | 102 | void grabKey(unsigned int key, unsigned int mod); |
@@ -105,54 +107,14 @@ private: | |||
105 | 107 | ||
106 | // Load default keybindings for when there are errors loading the initial one | 108 | // Load default keybindings for when there are errors loading the initial one |
107 | void loadDefaults(); | 109 | void loadDefaults(); |
108 | |||
109 | std::string m_filename; | ||
110 | |||
111 | class t_key; | ||
112 | typedef std::list<t_key*> keylist_t; | ||
113 | |||
114 | class t_key { | ||
115 | public: | ||
116 | t_key(int type, unsigned int mod, unsigned int key, int context, | ||
117 | bool isdouble); | ||
118 | t_key(t_key *k); | ||
119 | ~t_key(); | ||
120 | |||
121 | t_key *find(int type_, unsigned int mod_, unsigned int key_, | ||
122 | int context_, bool isdouble_) { | ||
123 | // t_key ctor sets context_ of 0 to GLOBAL, so we must here too | ||
124 | context_ = context_ ? context_ : GLOBAL; | ||
125 | keylist_t::iterator it = keylist.begin(), it_end = keylist.end(); | ||
126 | for (; it != it_end; it++) { | ||
127 | if ((*it)->type == type_ && (*it)->key == key_ && | ||
128 | ((*it)->context & context_) > 0 && | ||
129 | isdouble_ == (*it)->isdouble && (*it)->mod == | ||
130 | FbTk::KeyUtil::instance().isolateModifierMask(mod_)) | ||
131 | return *it; | ||
132 | } | ||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | |||
137 | FbTk::RefCount<FbTk::Command> m_command; | ||
138 | int context; // ON_TITLEBAR, etc.: bitwise-or of all desired contexts | ||
139 | int type; // KeyPress or ButtonPress | ||
140 | unsigned int key; // key code or button number | ||
141 | unsigned int mod; | ||
142 | bool isdouble; | ||
143 | keylist_t keylist; | ||
144 | }; | ||
145 | |||
146 | void setKeyMode(t_key *keyMode); | 110 | void setKeyMode(t_key *keyMode); |
147 | 111 | ||
148 | typedef std::map<std::string, t_key *> keyspace_t; | 112 | |
113 | // member variables | ||
114 | std::string m_filename; | ||
149 | t_key *m_keylist; | 115 | t_key *m_keylist; |
150 | keyspace_t m_map; | 116 | keyspace_t m_map; |
151 | 117 | ||
152 | Display *m_display; ///< display connection | ||
153 | |||
154 | typedef std::map<Window, int> WindowMap; | ||
155 | typedef std::map<Window, FbTk::EventHandler*> HandlerMap; | ||
156 | WindowMap m_window_map; | 118 | WindowMap m_window_map; |
157 | HandlerMap m_handler_map; | 119 | HandlerMap m_handler_map; |
158 | }; | 120 | }; |
diff --git a/src/Screen.cc b/src/Screen.cc index 8aa7693..73037f4 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -77,6 +77,7 @@ | |||
77 | #include "FbTk/Compose.hh" | 77 | #include "FbTk/Compose.hh" |
78 | #include "FbTk/FbString.hh" | 78 | #include "FbTk/FbString.hh" |
79 | #include "FbTk/STLUtil.hh" | 79 | #include "FbTk/STLUtil.hh" |
80 | #include "FbTk/KeyUtil.hh" | ||
80 | 81 | ||
81 | //use GNU extensions | 82 | //use GNU extensions |
82 | #ifndef _GNU_SOURCE | 83 | #ifndef _GNU_SOURCE |