summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-12-20 17:37:57 (GMT)
committerfluxgen <fluxgen>2003-12-20 17:37:57 (GMT)
commit29c778459955d5aaa17e619f8acf09dc3ec1d9b2 (patch)
treecee66d71d15d855b71f2987f6de255ac3e7a92db /src
parent7e167d9b83e81a634a4bdc09ba78be5d83bbbc37 (diff)
downloadfluxbox_lack-29c778459955d5aaa17e619f8acf09dc3ec1d9b2.zip
fluxbox_lack-29c778459955d5aaa17e619f8acf09dc3ec1d9b2.tar.bz2
addBinding function and some cleaning
Diffstat (limited to 'src')
-rw-r--r--src/Keys.cc172
-rw-r--r--src/Keys.hh27
2 files changed, 117 insertions, 82 deletions
diff --git a/src/Keys.cc b/src/Keys.cc
index d5bf786..8ca47c3 100644
--- a/src/Keys.cc
+++ b/src/Keys.cc
@@ -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.cc,v 1.39 2003/12/04 21:31:02 fluxgen Exp $ 22//$Id: Keys.cc,v 1.40 2003/12/20 17:37:57 fluxgen Exp $
23 23
24 24
25#include "Keys.hh" 25#include "Keys.hh"
@@ -118,97 +118,125 @@ bool Keys::load(const char *filename) {
118 if (!infile) 118 if (!infile)
119 return false; // faild to open file 119 return false; // faild to open file
120 120
121 int line=0;//current line, so we can tell the user where the fault is 121 m_current_line = 0;//current line, so we can tell the user where the fault is
122 122
123 while (!infile.eof()) { 123 while (!infile.eof()) {
124 string linebuffer; 124 string linebuffer;
125 125
126 getline(infile, linebuffer); 126 getline(infile, linebuffer);
127 127
128 line++; 128 m_current_line++;
129 vector<string> val;
130 //Parse arguments
131 FbTk::StringUtil::stringtok(val, linebuffer.c_str());
132 129
133 //must have at least 1 argument 130 addBinding(linebuffer);
134 if (val.size() <= 0) 131 } // end while eof
135 continue; 132
133 m_current_line = 0;
134 m_filename = filename;
135 return true;
136}
137
138bool Keys::save(const char *filename) const {
139 //!!
140 //!! TODO: fix keybinding saving
141 //!! (we probably need to save key actions
142 //!! as strings instead of creating new Commands)
143
144 // open file for writing
145 // ofstream outfile(filename);
146 // if (!outfile)
147 return false;
148 // return true;
149}
150
151bool Keys::addBinding(const std::string &linebuffer) {
152
153 vector<string> val;
154 // Parse arguments
155 FbTk::StringUtil::stringtok(val, linebuffer.c_str());
156
157 // must have at least 1 argument
158 if (val.size() <= 0)
159 return true; // empty lines are valid.
136 160
137 if (val[0][0] == '#') //the line is commented 161 if (val[0][0] == '#') //the line is commented
138 continue; 162 return true; // still a valid line.
139 163
140 unsigned int key=0, mod=0; 164 unsigned int key = 0, mod = 0;
141 char keyarg=0; 165 char keyarg = 0;
142 t_key *current_key=0, *last_key=0; 166 t_key *current_key=0, *last_key=0;
143 167
144 for (unsigned int argc=0; argc<val.size(); argc++) { 168 // for each argument
145 169 for (unsigned int argc=0; argc<val.size(); argc++) {
146 if (val[argc][0] != ':') { // parse key(s) 170
147 keyarg++; 171 if (val[argc][0] != ':') { // parse key(s)
148 if (keyarg==1) //first arg is modifier 172 keyarg++;
149 mod = FbTk::KeyUtil::getModifier(val[argc].c_str()); 173 if (keyarg==1) //first arg is modifier
150 else if (keyarg>1) { 174 mod = FbTk::KeyUtil::getModifier(val[argc].c_str());
151 175 else if (keyarg > 1) {
152 //keyarg=0; 176
153 int tmpmod = FbTk::KeyUtil::getModifier(val[argc].c_str()); 177 int tmpmod = FbTk::KeyUtil::getModifier(val[argc].c_str());
154 if(tmpmod) 178 if(tmpmod)
155 mod|=tmpmod; //If it's a modifier 179 mod |= tmpmod; //If it's a modifier
156 else { 180 else {
157 key = FbTk::KeyUtil::getKey(val[argc].c_str()); // else get the key 181 key = FbTk::KeyUtil::getKey(val[argc].c_str()); // else get the key
158 if (key == 0) { 182 if (key == 0) {
159 cerr<<"["<<filename<<"]: Invalid key/modifier on line("<< 183 cerr<<"Keys: Invalid key/modifier on line("<<
160 line<<"): "<<linebuffer<<endl; 184 m_current_line<<"): "<<linebuffer<<endl;
161 break; // get next line 185 return false;
162 } 186 }
163 if (!current_key) { 187 if (!current_key) {
164 current_key = new t_key(key, mod); 188 current_key = new t_key(key, mod);
165 last_key = current_key; 189 last_key = current_key;
166 } else { 190 } else {
167 t_key *temp_key = new t_key(key, mod); 191 t_key *temp_key = new t_key(key, mod);
168 last_key->keylist.push_back(temp_key); 192 last_key->keylist.push_back(temp_key);
169 last_key = temp_key; 193 last_key = temp_key;
170 }
171 } 194 }
172 }
173
174 } else { // parse command line
175 if (last_key == 0) {
176 cerr<<"File: "<<filename<<". Error on line: "<<line<<endl;
177 cerr<<"> "<<linebuffer<<endl;
178 break;
179 } 195 }
196 }
180 197
181 const char *str = 198 } else { // parse command line
182 FbTk::StringUtil::strcasestr(linebuffer.c_str(), 199 if (last_key == 0) {
183 val[argc].c_str() + 1); // +1 to skip ':' 200 cerr<<"Keys: Error on line: "<<m_current_line<<endl;
184 if (str == 0) { 201 cerr<<"> "<<linebuffer<<endl;
185 cerr<<"File: "<<filename<<". Error on line: "<<line<<endl; 202 return false;
186 cerr<<"> "<<linebuffer<<endl; 203 }
187 } else { 204 bool ret_val = true;
205 const char *str =
206 FbTk::StringUtil::strcasestr(linebuffer.c_str(),
207 val[argc].c_str() + 1); // +1 to skip ':'
208 if (str == 0) {
209 cerr<<"Keys: Error on line: "<<m_current_line<<endl;
210 cerr<<"> "<<linebuffer<<endl;
211 ret_val = false;
212 } else {
188 213
189 last_key->m_command = CommandParser::instance().parseLine(str); 214 last_key->m_command = CommandParser::instance().parseLine(str);
190 215
191 if (*last_key->m_command == 0) { 216 if (*last_key->m_command == 0) {
192 cerr<<"File: "<<filename<<". Error on line: "<<line<<endl; 217 cerr<<"Keys: Error on line: "<<m_current_line<<endl;
193 cerr<<"> "<<linebuffer<<endl; 218 cerr<<"> "<<linebuffer<<endl;
194 } else { 219 } else {
195 // Add the keychain to list 220 // Add the keychain to list
196 if (!mergeTree(current_key)) 221 if (!mergeTree(current_key)) {
197 cerr<<"Keys: Failed to merge keytree!"<<endl; 222 cerr<<"Keys: Failed to merge keytree!"<<endl;
223 ret_val = false;
198 } 224 }
199 } 225 }
200 delete current_key; 226 }
201 current_key = 0; 227 delete current_key;
202 last_key = 0; 228 current_key = 0;
229 last_key = 0;
203 230
204 break; // dont process this linebuffer more 231 return ret_val;
205 } // end if
206 } // end for
207 } // end while eof
208 232
209 return true; 233 } // end if
234 } // end for
235
236 return false;
210} 237}
211 238
239
212/** 240/**
213 @return the KeyAction of the XKeyEvent 241 @return the KeyAction of the XKeyEvent
214*/ 242*/
diff --git a/src/Keys.hh b/src/Keys.hh
index b04cdc8..014f5a1 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.30 2003/12/16 23:32:29 fluxgen Exp $ 22// $Id: Keys.hh,v 1.31 2003/12/20 17:37:20 fluxgen Exp $
23 23
24#ifndef KEYS_HH 24#ifndef KEYS_HH
25#define KEYS_HH 25#define KEYS_HH
@@ -48,27 +48,34 @@ public:
48 Load configuration from file 48 Load configuration from file
49 @return true on success, else false 49 @return true on success, else false
50 */ 50 */
51 bool load(const char *filename=0); 51 bool load(const char *filename = 0);
52 /**
53 Save keybindings to a file
54 Note: the file will be overwritten
55 @return true on success, else false
56 */
57 bool save(const char *filename = 0) const;
58 /// bind a key action from a string
59 /// @return false on failure
60 bool addBinding(const std::string &binding);
61
52 /** 62 /**
53 do action from XKeyEvent 63 do action from XKeyEvent
54 */ 64 */
55 void doAction(XKeyEvent &ke); 65 void doAction(XKeyEvent &ke);
66
56 /** 67 /**
57 Reload configuration from filename 68 Reload configuration from filename
58 @return true on success, else false 69 @return true on success, else false
59 */ 70 */
60 bool reconfigure(const char *filename); 71 bool reconfigure(const char *filename);
61 72 const std::string filename() const { return m_filename; }
62private: 73private:
63 void deleteTree(); 74 void deleteTree();
64 75
65 void bindKey(unsigned int key, unsigned int mod); 76 void bindKey(unsigned int key, unsigned int mod);
66 /** 77
67 @param modstr modifier string (i.e Mod4, Mod5) 78 std::string m_filename;
68 @return modifier number that match modstr
69 */
70
71 std::string filename;
72 79
73 class t_key { 80 class t_key {
74 public: 81 public:
@@ -111,7 +118,7 @@ private:
111 std::vector<t_key *> m_keylist; 118 std::vector<t_key *> m_keylist;
112 119
113 Display *m_display; ///< display connection 120 Display *m_display; ///< display connection
114 121 unsigned int m_current_line;
115}; 122};
116 123
117#endif // KEYS_HH 124#endif // KEYS_HH