diff options
author | markt <markt> | 2007-04-08 17:57:49 (GMT) |
---|---|---|
committer | markt <markt> | 2007-04-08 17:57:49 (GMT) |
commit | 863eca5517b4f91e26d889d598f41816acf60a40 (patch) | |
tree | 18be5baa27a1c5fa8523ff951bdf751b8f163a44 /src/Keys.cc | |
parent | 12a8b3c038c9ccb577c699d41a1d19602132a7a8 (diff) | |
download | fluxbox-863eca5517b4f91e26d889d598f41816acf60a40.zip fluxbox-863eca5517b4f91e26d889d598f41816acf60a40.tar.bz2 |
added OnToolbar modifier, removed followModel, fixed unpressed button rendering
Diffstat (limited to 'src/Keys.cc')
-rw-r--r-- | src/Keys.cc | 110 |
1 files changed, 72 insertions, 38 deletions
diff --git a/src/Keys.cc b/src/Keys.cc index 97a83bf..aca7428 100644 --- a/src/Keys.cc +++ b/src/Keys.cc | |||
@@ -99,18 +99,7 @@ using std::vector; | |||
99 | using std::ifstream; | 99 | using std::ifstream; |
100 | using std::pair; | 100 | using std::pair; |
101 | 101 | ||
102 | Keys::Keys(): | 102 | Keys::Keys(): m_display(FbTk::App::instance()->display()) { } |
103 | m_display(FbTk::App::instance()->display()) | ||
104 | { | ||
105 | typedef std::list<BScreen *> ScreenList; | ||
106 | ScreenList screen_list = Fluxbox::instance()->screenList(); | ||
107 | ScreenList::iterator it = screen_list.begin(); | ||
108 | ScreenList::iterator it_end = screen_list.end(); | ||
109 | |||
110 | for (; it != it_end; ++it) | ||
111 | m_window_list.push_back(RootWindow(m_display,(*it)->screenNumber())); | ||
112 | |||
113 | } | ||
114 | 103 | ||
115 | Keys::~Keys() { | 104 | Keys::~Keys() { |
116 | ungrabKeys(); | 105 | ungrabKeys(); |
@@ -125,37 +114,69 @@ void Keys::deleteTree() { | |||
125 | m_map.clear(); | 114 | m_map.clear(); |
126 | } | 115 | } |
127 | 116 | ||
117 | // keys are only grabbed in global context | ||
128 | void Keys::grabKey(unsigned int key, unsigned int mod) { | 118 | void Keys::grabKey(unsigned int key, unsigned int mod) { |
129 | std::list<Window>::iterator it = m_window_list.begin(); | 119 | WindowMap::iterator it = m_window_map.begin(); |
130 | std::list<Window>::iterator it_end = m_window_list.end(); | 120 | WindowMap::iterator it_end = m_window_map.end(); |
131 | 121 | ||
132 | for (; it != it_end; ++it) | 122 | for (; it != it_end; ++it) { |
133 | FbTk::KeyUtil::grabKey(key, mod, *it); | 123 | if ((it->second & Keys::GLOBAL) > 0) |
124 | FbTk::KeyUtil::grabKey(key, mod, it->first); | ||
125 | } | ||
134 | } | 126 | } |
135 | 127 | ||
128 | // keys are only grabbed in global context | ||
136 | void Keys::ungrabKeys() { | 129 | void Keys::ungrabKeys() { |
137 | std::list<Window>::iterator it = m_window_list.begin(); | 130 | WindowMap::iterator it = m_window_map.begin(); |
138 | std::list<Window>::iterator it_end = m_window_list.end(); | 131 | WindowMap::iterator it_end = m_window_map.end(); |
139 | 132 | ||
140 | for (; it != it_end; ++it) | 133 | for (; it != it_end; ++it) { |
141 | FbTk::KeyUtil::ungrabKeys(*it); | 134 | if ((it->second & Keys::GLOBAL) > 0) |
135 | FbTk::KeyUtil::ungrabKeys(it->first); | ||
136 | } | ||
142 | } | 137 | } |
143 | 138 | ||
144 | void Keys::grabButton(unsigned int button, unsigned int mod) { | 139 | // ON_DESKTOP context doesn't need to be grabbed |
145 | std::list<Window>::iterator it = m_window_list.begin(); | 140 | void Keys::grabButton(unsigned int button, unsigned int mod, int context) { |
146 | std::list<Window>::iterator it_end = m_window_list.end(); | 141 | WindowMap::iterator it = m_window_map.begin(); |
142 | WindowMap::iterator it_end = m_window_map.end(); | ||
147 | 143 | ||
148 | for (; it != it_end; ++it) | 144 | for (; it != it_end; ++it) { |
149 | FbTk::KeyUtil::grabButton(button, mod, *it, | 145 | if ((context & it->second & ~Keys::ON_DESKTOP) > 0) |
150 | ButtonPressMask|ButtonReleaseMask); | 146 | FbTk::KeyUtil::grabButton(button, mod, it->first, |
147 | ButtonPressMask|ButtonReleaseMask); | ||
148 | } | ||
151 | } | 149 | } |
152 | 150 | ||
153 | void Keys::ungrabButtons() { | 151 | void Keys::ungrabButtons() { |
154 | std::list<Window>::iterator it = m_window_list.begin(); | 152 | WindowMap::iterator it = m_window_map.begin(); |
155 | std::list<Window>::iterator it_end = m_window_list.end(); | 153 | WindowMap::iterator it_end = m_window_map.end(); |
156 | 154 | ||
157 | for (; it != it_end; ++it) | 155 | for (; it != it_end; ++it) |
158 | FbTk::KeyUtil::ungrabButtons(*it); | 156 | FbTk::KeyUtil::ungrabButtons(it->first); |
157 | } | ||
158 | |||
159 | void Keys::grabWindow(Window win) { | ||
160 | if (!m_keylist) | ||
161 | return; | ||
162 | |||
163 | // make sure the window is in our list | ||
164 | WindowMap::iterator win_it = m_window_map.find(win); | ||
165 | if (win_it == m_window_map.end()) | ||
166 | return; | ||
167 | |||
168 | keylist_t::iterator it = m_keylist->keylist.begin(); | ||
169 | keylist_t::iterator it_end = m_keylist->keylist.end(); | ||
170 | for (; it != it_end; ++it) { | ||
171 | // keys are only grabbed in global context | ||
172 | if ((win_it->second & Keys::GLOBAL) > 0 && (*it)->type == KeyPress) | ||
173 | FbTk::KeyUtil::grabKey((*it)->key, (*it)->mod, win); | ||
174 | // ON_DESKTOP buttons don't need to be grabbed | ||
175 | else if ((win_it->second & (*it)->context & ~Keys::ON_DESKTOP) > 0 && | ||
176 | (*it)->type == ButtonPress) | ||
177 | FbTk::KeyUtil::grabButton((*it)->key, (*it)->mod, win, | ||
178 | ButtonPressMask|ButtonReleaseMask); | ||
179 | } | ||
159 | } | 180 | } |
160 | 181 | ||
161 | /** | 182 | /** |
@@ -251,6 +272,8 @@ bool Keys::addBinding(const string &linebuffer) { | |||
251 | mod |= tmpmod; //If it's a modifier | 272 | mod |= tmpmod; //If it's a modifier |
252 | else if (strcasecmp("ondesktop", val[argc].c_str()) == 0) | 273 | else if (strcasecmp("ondesktop", val[argc].c_str()) == 0) |
253 | context |= ON_DESKTOP; | 274 | context |= ON_DESKTOP; |
275 | else if (strcasecmp("ontoolbar", val[argc].c_str()) == 0) | ||
276 | context |= ON_TOOLBAR; | ||
254 | else if (strcasecmp("NONE",val[argc].c_str())) { | 277 | else if (strcasecmp("NONE",val[argc].c_str())) { |
255 | // check if it's a mouse button | 278 | // check if it's a mouse button |
256 | if (!strcasecmp(val[argc].substr(0,5).c_str(), "mouse") && | 279 | if (!strcasecmp(val[argc].substr(0,5).c_str(), "mouse") && |
@@ -322,16 +345,15 @@ bool Keys::addBinding(const string &linebuffer) { | |||
322 | } | 345 | } |
323 | 346 | ||
324 | // return true if bound to a command, else false | 347 | // return true if bound to a command, else false |
325 | bool Keys::doAction(int type, unsigned int mods, unsigned int key) { | 348 | bool Keys::doAction(int type, unsigned int mods, unsigned int key, |
349 | int context) { | ||
326 | 350 | ||
327 | static t_key* next_key = m_keylist; | 351 | static t_key* next_key = m_keylist; |
328 | if (!next_key) | 352 | if (!next_key) |
329 | next_key = m_keylist; | 353 | next_key = m_keylist; |
330 | 354 | ||
331 | mods = FbTk::KeyUtil::instance().cleanMods(mods); | 355 | mods = FbTk::KeyUtil::instance().cleanMods(mods); |
332 | // at the moment, any key/button that gets here is on root window | 356 | t_key *temp_key = next_key->find(type, mods, key, context); |
333 | // context will need to be added as an argument to doAction, though | ||
334 | t_key *temp_key = next_key->find(type, mods, key, ON_DESKTOP|GLOBAL); | ||
335 | 357 | ||
336 | // need to save this for emacs-style keybindings | 358 | // need to save this for emacs-style keybindings |
337 | static t_key *saved_keymode = 0; | 359 | static t_key *saved_keymode = 0; |
@@ -369,6 +391,19 @@ bool Keys::doAction(int type, unsigned int mods, unsigned int key) { | |||
369 | return true; | 391 | return true; |
370 | } | 392 | } |
371 | 393 | ||
394 | /// adds the window to m_window_map, so we know to grab buttons on it | ||
395 | void Keys::registerWindow(Window win, int context) { | ||
396 | m_window_map[win] = context; | ||
397 | grabWindow(win); | ||
398 | } | ||
399 | |||
400 | /// remove the window from the window map, probably being deleted | ||
401 | void Keys::unregisterWindow(Window win) { | ||
402 | FbTk::KeyUtil::ungrabKeys(win); | ||
403 | FbTk::KeyUtil::ungrabButtons(win); | ||
404 | m_window_map.erase(win); | ||
405 | } | ||
406 | |||
372 | /** | 407 | /** |
373 | deletes the tree and load configuration | 408 | deletes the tree and load configuration |
374 | returns true on success else false | 409 | returns true on success else false |
@@ -392,14 +427,13 @@ void Keys::setKeyMode(t_key *keyMode) { | |||
392 | keylist_t::iterator it_end = keyMode->keylist.end(); | 427 | keylist_t::iterator it_end = keyMode->keylist.end(); |
393 | for (; it != it_end; ++it) { | 428 | for (; it != it_end; ++it) { |
394 | if ((*it)->type == KeyPress) | 429 | if ((*it)->type == KeyPress) |
395 | grabKey((*it)->key,(*it)->mod); | 430 | grabKey((*it)->key, (*it)->mod); |
396 | else if ((*it)->context == GLOBAL) | 431 | else |
397 | grabButton((*it)->key,(*it)->mod); | 432 | grabButton((*it)->key, (*it)->mod, (*it)->context); |
398 | // we must use root window's event mask to get ON_DESKTOP events | ||
399 | } | 433 | } |
400 | m_keylist = keyMode; | 434 | m_keylist = keyMode; |
401 | } | 435 | } |
402 | 436 | ||
403 | Keys::t_key::t_key(int type_, unsigned int mod_, unsigned int key_, | 437 | Keys::t_key::t_key(int type_, unsigned int mod_, unsigned int key_, |
404 | int context_, FbTk::RefCount<FbTk::Command> command) { | 438 | int context_, FbTk::RefCount<FbTk::Command> command) { |
405 | key = key_; | 439 | key = key_; |