aboutsummaryrefslogtreecommitdiff
path: root/src/Keys.cc
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2008-01-02 08:28:00 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2008-01-02 08:28:00 (GMT)
commitec13263a18e77c0e1e1a7bfb9fda6cc10b25ca34 (patch)
tree30de4b96ec70ebf20de853bf4b9ec1dbb3191546 /src/Keys.cc
parent7588fc10a61c141208ccccc423cc7920207b2e89 (diff)
downloadfluxbox-ec13263a18e77c0e1e1a7bfb9fda6cc10b25ca34.zip
fluxbox-ec13263a18e77c0e1e1a7bfb9fda6cc10b25ca34.tar.bz2
decoupling, moved private datastructures to Keys.cc
Diffstat (limited to 'src/Keys.cc')
-rw-r--r--src/Keys.cc111
1 files changed, 79 insertions, 32 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;
101using std::ifstream; 103using std::ifstream;
102using std::pair; 104using std::pair;
103 105
104Keys::Keys(): m_display(FbTk::App::instance()->display()) { } 106// helper class 'keytree'
107class Keys::t_key {
108public:
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
146Keys::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
157Keys::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
166Keys::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
174Keys::Keys() { }
105 175
106Keys::~Keys() { 176Keys::~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
515void Keys::keyMode(string keyMode) { 585void 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
544Keys::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
554Keys::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
563Keys::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}