diff options
author | rathnor <rathnor> | 2002-12-01 13:42:15 (GMT) |
---|---|---|
committer | rathnor <rathnor> | 2002-12-01 13:42:15 (GMT) |
commit | 28b5c604490094e187494dcc566bd3d7a05a2c25 (patch) | |
tree | 8f78f5714a5cd055c10b067a2656fe7b2338e71a /src/Keys.cc | |
parent | b9134162f9633784d9097df18769a699a62650fe (diff) | |
download | fluxbox_pavel-28b5c604490094e187494dcc566bd3d7a05a2c25.zip fluxbox_pavel-28b5c604490094e187494dcc566bd3d7a05a2c25.tar.bz2 |
Indenting from tabs to emacs 4-space
Diffstat (limited to 'src/Keys.cc')
-rw-r--r-- | src/Keys.cc | 920 |
1 files changed, 460 insertions, 460 deletions
diff --git a/src/Keys.cc b/src/Keys.cc index c4185b7..96452d3 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.20 2002/11/13 14:34:24 fluxgen Exp $ | 22 | //$Id: Keys.cc,v 1.21 2002/12/01 13:41:57 rathnor Exp $ |
23 | 23 | ||
24 | 24 | ||
25 | #include "Keys.hh" | 25 | #include "Keys.hh" |
@@ -69,103 +69,103 @@ | |||
69 | using namespace std; | 69 | using namespace std; |
70 | 70 | ||
71 | Keys::t_actionstr Keys::m_actionlist[] = { | 71 | Keys::t_actionstr Keys::m_actionlist[] = { |
72 | {"Minimize", ICONIFY}, | 72 | {"Minimize", ICONIFY}, |
73 | {"Raise", RAISE}, | 73 | {"Raise", RAISE}, |
74 | {"Lower", LOWER}, | 74 | {"Lower", LOWER}, |
75 | {"Close", CLOSE}, | 75 | {"Close", CLOSE}, |
76 | {"AbortKeychain", ABORTKEYCHAIN}, | 76 | {"AbortKeychain", ABORTKEYCHAIN}, |
77 | {"Workspace", WORKSPACE}, | 77 | {"Workspace", WORKSPACE}, |
78 | {"Workspace1", WORKSPACE1}, | 78 | {"Workspace1", WORKSPACE1}, |
79 | {"Workspace2", WORKSPACE2}, | 79 | {"Workspace2", WORKSPACE2}, |
80 | {"Workspace3", WORKSPACE3}, | 80 | {"Workspace3", WORKSPACE3}, |
81 | {"Workspace4", WORKSPACE4}, | 81 | {"Workspace4", WORKSPACE4}, |
82 | {"Workspace5", WORKSPACE5}, | 82 | {"Workspace5", WORKSPACE5}, |
83 | {"Workspace6", WORKSPACE6}, | 83 | {"Workspace6", WORKSPACE6}, |
84 | {"Workspace7", WORKSPACE7}, | 84 | {"Workspace7", WORKSPACE7}, |
85 | {"Workspace8", WORKSPACE8}, | 85 | {"Workspace8", WORKSPACE8}, |
86 | {"Workspace9", WORKSPACE9}, | 86 | {"Workspace9", WORKSPACE9}, |
87 | {"Workspace10", WORKSPACE10}, | 87 | {"Workspace10", WORKSPACE10}, |
88 | {"Workspace11", WORKSPACE11}, | 88 | {"Workspace11", WORKSPACE11}, |
89 | {"Workspace12", WORKSPACE12}, | 89 | {"Workspace12", WORKSPACE12}, |
90 | {"SendToWorkspace", SENDTOWORKSPACE}, | 90 | {"SendToWorkspace", SENDTOWORKSPACE}, |
91 | {"NextWorkspace", NEXTWORKSPACE}, | 91 | {"NextWorkspace", NEXTWORKSPACE}, |
92 | {"PrevWorkspace", PREVWORKSPACE}, | 92 | {"PrevWorkspace", PREVWORKSPACE}, |
93 | {"LeftWorkspace", LEFTWORKSPACE}, | 93 | {"LeftWorkspace", LEFTWORKSPACE}, |
94 | {"RightWorkspace", RIGHTWORKSPACE}, | 94 | {"RightWorkspace", RIGHTWORKSPACE}, |
95 | {"KillWindow", KILLWINDOW}, | 95 | {"KillWindow", KILLWINDOW}, |
96 | {"NextWindow", NEXTWINDOW}, | 96 | {"NextWindow", NEXTWINDOW}, |
97 | {"PrevWindow", PREVWINDOW}, | 97 | {"PrevWindow", PREVWINDOW}, |
98 | {"NextTab", NEXTTAB}, | 98 | {"NextTab", NEXTTAB}, |
99 | {"PrevTab", PREVTAB}, | 99 | {"PrevTab", PREVTAB}, |
100 | {"FirstTab", FIRSTTAB}, | 100 | {"FirstTab", FIRSTTAB}, |
101 | {"LastTab", LASTTAB}, | 101 | {"LastTab", LASTTAB}, |
102 | {"MoveTabPrev", MOVETABPREV}, | 102 | {"MoveTabPrev", MOVETABPREV}, |
103 | {"MoveTabNext", MOVETABNEXT}, | 103 | {"MoveTabNext", MOVETABNEXT}, |
104 | {"ShadeWindow", SHADE}, | 104 | {"ShadeWindow", SHADE}, |
105 | {"MaximizeWindow", MAXIMIZE}, | 105 | {"MaximizeWindow", MAXIMIZE}, |
106 | {"StickWindow", STICK}, | 106 | {"StickWindow", STICK}, |
107 | {"ExecCommand", EXECUTE}, | 107 | {"ExecCommand", EXECUTE}, |
108 | {"MaximizeVertical", VERTMAX}, | 108 | {"MaximizeVertical", VERTMAX}, |
109 | {"MaximizeHorizontal", HORIZMAX}, | 109 | {"MaximizeHorizontal", HORIZMAX}, |
110 | {"NudgeRight", NUDGERIGHT}, | 110 | {"NudgeRight", NUDGERIGHT}, |
111 | {"NudgeLeft", NUDGELEFT}, | 111 | {"NudgeLeft", NUDGELEFT}, |
112 | {"NudgeUp", NUDGEUP}, | 112 | {"NudgeUp", NUDGEUP}, |
113 | {"NudgeDown", NUDGEDOWN}, | 113 | {"NudgeDown", NUDGEDOWN}, |
114 | {"BigNudgeRight", BIGNUDGERIGHT}, | 114 | {"BigNudgeRight", BIGNUDGERIGHT}, |
115 | {"BigNudgeLeft", BIGNUDGELEFT}, | 115 | {"BigNudgeLeft", BIGNUDGELEFT}, |
116 | {"BigNudgeUp", BIGNUDGEUP}, | 116 | {"BigNudgeUp", BIGNUDGEUP}, |
117 | {"BigNudgeDown", BIGNUDGEDOWN}, | 117 | {"BigNudgeDown", BIGNUDGEDOWN}, |
118 | {"HorizontalIncrement", HORIZINC}, | 118 | {"HorizontalIncrement", HORIZINC}, |
119 | {"VerticalIncrement", VERTINC}, | 119 | {"VerticalIncrement", VERTINC}, |
120 | {"HorizontalDecrement", HORIZDEC}, | 120 | {"HorizontalDecrement", HORIZDEC}, |
121 | {"VerticalDecrement", VERTDEC}, | 121 | {"VerticalDecrement", VERTDEC}, |
122 | {"ToggleDecor", TOGGLEDECOR}, | 122 | {"ToggleDecor", TOGGLEDECOR}, |
123 | {"ToggleTab", TOGGLETAB}, | 123 | {"ToggleTab", TOGGLETAB}, |
124 | {"RootMenu", ROOTMENU}, | 124 | {"RootMenu", ROOTMENU}, |
125 | {0, LASTKEYGRAB} | 125 | {0, LASTKEYGRAB} |
126 | }; | 126 | }; |
127 | 127 | ||
128 | Keys::Keys(Display *display, const char *filename): | 128 | Keys::Keys(Display *display, const char *filename): |
129 | m_capslock_mod(0), | 129 | m_capslock_mod(0), |
130 | m_numlock_mod(0), | 130 | m_numlock_mod(0), |
131 | m_scrolllock_mod(0), | 131 | m_scrolllock_mod(0), |
132 | m_abortkey(0), | 132 | m_abortkey(0), |
133 | m_display(display) | 133 | m_display(display) |
134 | { | 134 | { |
135 | determineModmap(); | 135 | determineModmap(); |
136 | assert(display); | 136 | assert(display); |
137 | if (filename != 0) | 137 | if (filename != 0) |
138 | load(filename); | 138 | load(filename); |
139 | } | 139 | } |
140 | 140 | ||
141 | Keys::~Keys() { | 141 | Keys::~Keys() { |
142 | ungrabKeys(); | 142 | ungrabKeys(); |
143 | deleteTree(); | 143 | deleteTree(); |
144 | } | 144 | } |
145 | 145 | ||
146 | //--------- deleteTree ----------- | 146 | //--------- deleteTree ----------- |
147 | // Destroys the keytree and m_abortkey | 147 | // Destroys the keytree and m_abortkey |
148 | //-------------------------------- | 148 | //-------------------------------- |
149 | void Keys::deleteTree() { | 149 | void Keys::deleteTree() { |
150 | while (!m_keylist.empty()) { | 150 | while (!m_keylist.empty()) { |
151 | if (m_keylist.back() && m_keylist.back() != 0) | 151 | if (m_keylist.back() && m_keylist.back() != 0) |
152 | delete m_keylist.back(); | 152 | delete m_keylist.back(); |
153 | m_keylist.pop_back(); | 153 | m_keylist.pop_back(); |
154 | } | 154 | } |
155 | if (m_abortkey) { | 155 | if (m_abortkey) { |
156 | delete m_abortkey; | 156 | delete m_abortkey; |
157 | m_abortkey=0; | 157 | m_abortkey=0; |
158 | } | 158 | } |
159 | } | 159 | } |
160 | 160 | ||
161 | //-------- ungrabKeys --------- | 161 | //-------- ungrabKeys --------- |
162 | // Ungrabs the keys | 162 | // Ungrabs the keys |
163 | //----------------------------- | 163 | //----------------------------- |
164 | void Keys::ungrabKeys() { | 164 | void Keys::ungrabKeys() { |
165 | for (int screen=0; screen<ScreenCount(m_display); screen++) { | 165 | for (int screen=0; screen<ScreenCount(m_display); screen++) { |
166 | XUngrabKey(m_display, AnyKey, AnyModifier, | 166 | XUngrabKey(m_display, AnyKey, AnyModifier, |
167 | RootWindow(m_display, screen)); | 167 | RootWindow(m_display, screen)); |
168 | } | 168 | } |
169 | } | 169 | } |
170 | 170 | ||
171 | //-------------- load ---------------- | 171 | //-------------- load ---------------- |
@@ -174,180 +174,180 @@ void Keys::ungrabKeys() { | |||
174 | // TODO: error checking | 174 | // TODO: error checking |
175 | //------------------------------------ | 175 | //------------------------------------ |
176 | bool Keys::load(const char *filename) { | 176 | bool Keys::load(const char *filename) { |
177 | if (!filename) | 177 | if (!filename) |
178 | return false; | 178 | return false; |
179 | 179 | ||
180 | //ungrab all keys | 180 | //ungrab all keys |
181 | ungrabKeys(); | 181 | ungrabKeys(); |
182 | 182 | ||
183 | //free memory of previous grabs | 183 | //free memory of previous grabs |
184 | deleteTree(); | 184 | deleteTree(); |
185 | 185 | ||
186 | XSync(m_display, False); | 186 | XSync(m_display, False); |
187 | 187 | ||
188 | //open the file | 188 | //open the file |
189 | ifstream infile(filename); | 189 | ifstream infile(filename); |
190 | if (!infile) | 190 | if (!infile) |
191 | return false; // faild to open file | 191 | return false; // faild to open file |
192 | 192 | ||
193 | int line=0;//current line, so we can tell the user where the fault is | 193 | int line=0;//current line, so we can tell the user where the fault is |
194 | 194 | ||
195 | while (!infile.eof()) { | 195 | while (!infile.eof()) { |
196 | string linebuffer; | 196 | string linebuffer; |
197 | 197 | ||
198 | getline(infile, linebuffer); | 198 | getline(infile, linebuffer); |
199 | 199 | ||
200 | line++; | 200 | line++; |
201 | vector<string> val; | 201 | vector<string> val; |
202 | //Parse arguments | 202 | //Parse arguments |
203 | StringUtil::stringtok(val, linebuffer.c_str()); | 203 | StringUtil::stringtok(val, linebuffer.c_str()); |
204 | 204 | ||
205 | //must have at least 1 argument | 205 | //must have at least 1 argument |
206 | if (val.size() <= 0) | 206 | if (val.size() <= 0) |
207 | continue; | 207 | continue; |
208 | 208 | ||
209 | if (val[0][0] == '#') //the line is commented | 209 | if (val[0][0] == '#') //the line is commented |
210 | continue; | 210 | continue; |
211 | 211 | ||
212 | unsigned int key=0, mod=0; | 212 | unsigned int key=0, mod=0; |
213 | char keyarg=0; | 213 | char keyarg=0; |
214 | t_key *current_key=0, *last_key=0; | 214 | t_key *current_key=0, *last_key=0; |
215 | 215 | ||
216 | for (unsigned int argc=0; argc<val.size(); argc++) { | 216 | for (unsigned int argc=0; argc<val.size(); argc++) { |
217 | 217 | ||
218 | if (val[argc][0]!=':') { | 218 | if (val[argc][0]!=':') { |
219 | keyarg++; | 219 | keyarg++; |
220 | if (keyarg==1) //first arg is modifier | 220 | if (keyarg==1) //first arg is modifier |
221 | mod = getModifier(val[argc].c_str()); | 221 | mod = getModifier(val[argc].c_str()); |
222 | else if (keyarg>1) { | 222 | else if (keyarg>1) { |
223 | 223 | ||
224 | //keyarg=0; | 224 | //keyarg=0; |
225 | int tmpmod=getModifier(val[argc].c_str()); | 225 | int tmpmod=getModifier(val[argc].c_str()); |
226 | if(tmpmod) | 226 | if(tmpmod) |
227 | mod|=tmpmod; //If it's a modifier | 227 | mod|=tmpmod; //If it's a modifier |
228 | else { | 228 | else { |
229 | key = getKey(val[argc].c_str()); // else get the key | 229 | key = getKey(val[argc].c_str()); // else get the key |
230 | if (key == 0) { | 230 | if (key == 0) { |
231 | cerr<<"["<<filename<<"]: Invalid key/modifier on line("<< | 231 | cerr<<"["<<filename<<"]: Invalid key/modifier on line("<< |
232 | line<<"): "<<linebuffer<<endl; | 232 | line<<"): "<<linebuffer<<endl; |
233 | break; // get next line | 233 | break; // get next line |
234 | } | 234 | } |
235 | if (!current_key) { | 235 | if (!current_key) { |
236 | current_key = new t_key(key, mod); | 236 | current_key = new t_key(key, mod); |
237 | last_key = current_key; | 237 | last_key = current_key; |
238 | } else { | 238 | } else { |
239 | t_key *temp_key = new t_key(key, mod); | 239 | t_key *temp_key = new t_key(key, mod); |
240 | last_key->keylist.push_back(temp_key); | 240 | last_key->keylist.push_back(temp_key); |
241 | last_key = temp_key; | 241 | last_key = temp_key; |
242 | } | 242 | } |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | } else { | 246 | } else { |
247 | 247 | ||
248 | unsigned int i=0; | 248 | unsigned int i=0; |
249 | 249 | ||
250 | for (i=0; i< LASTKEYGRAB; i++) { | 250 | for (i=0; i< LASTKEYGRAB; i++) { |
251 | // +1 on the val[argc] because we dont want to compare the ':' | 251 | // +1 on the val[argc] because we dont want to compare the ':' |
252 | if (strcasecmp(m_actionlist[i].string, val[argc].c_str()+1) == 0) | 252 | if (strcasecmp(m_actionlist[i].string, val[argc].c_str()+1) == 0) |
253 | break; | 253 | break; |
254 | } | 254 | } |
255 | 255 | ||
256 | if (i < LASTKEYGRAB ) { | 256 | if (i < LASTKEYGRAB ) { |
257 | if (!current_key) { | 257 | if (!current_key) { |
258 | cerr<<"Error on line: "<<line<<endl; | 258 | cerr<<"Error on line: "<<line<<endl; |
259 | cerr<<linebuffer<<endl; | 259 | cerr<<linebuffer<<endl; |
260 | delete current_key; | 260 | delete current_key; |
261 | current_key = 0; | 261 | current_key = 0; |
262 | last_key = 0; | 262 | last_key = 0; |
263 | break; //break out and read next line | 263 | break; //break out and read next line |
264 | } | 264 | } |
265 | 265 | ||
266 | //special case for grabAbortKeychain | 266 | //special case for grabAbortKeychain |
267 | if (m_actionlist[i].action == ABORTKEYCHAIN) { | 267 | if (m_actionlist[i].action == ABORTKEYCHAIN) { |
268 | if (last_key!=current_key) | 268 | if (last_key!=current_key) |
269 | cerr<<"Keys: "<<m_actionlist[i].string<<" cant be in chained mode"<<endl; | 269 | cerr<<"Keys: "<<m_actionlist[i].string<<" cant be in chained mode"<<endl; |
270 | else if (m_abortkey) | 270 | else if (m_abortkey) |
271 | cerr<<"Keys: "<<m_actionlist[i].string<<" is already bound."<<endl; | 271 | cerr<<"Keys: "<<m_actionlist[i].string<<" is already bound."<<endl; |
272 | else | 272 | else |
273 | m_abortkey = new t_key(current_key->key, current_key->mod, ABORTKEYCHAIN); | 273 | m_abortkey = new t_key(current_key->key, current_key->mod, ABORTKEYCHAIN); |
274 | 274 | ||
275 | delete current_key; | 275 | delete current_key; |
276 | current_key = 0; | 276 | current_key = 0; |
277 | last_key = 0; | 277 | last_key = 0; |
278 | break; //break out and read next line | 278 | break; //break out and read next line |
279 | } | 279 | } |
280 | 280 | ||
281 | last_key->action = m_actionlist[i].action; | 281 | last_key->action = m_actionlist[i].action; |
282 | switch(last_key->action) { | 282 | switch(last_key->action) { |
283 | case Keys::EXECUTE: | 283 | case Keys::EXECUTE: |
284 | last_key->execcommand = | 284 | last_key->execcommand = |
285 | const_cast<char *> | 285 | const_cast<char *> |
286 | (StringUtil::strcasestr(linebuffer.c_str(), | 286 | (StringUtil::strcasestr(linebuffer.c_str(), |
287 | getActionStr(Keys::EXECUTE))+ | 287 | getActionStr(Keys::EXECUTE))+ |
288 | strlen(getActionStr(Keys::EXECUTE))); | 288 | strlen(getActionStr(Keys::EXECUTE))); |
289 | break; | 289 | break; |
290 | case WORKSPACE: | 290 | case WORKSPACE: |
291 | case SENDTOWORKSPACE: | 291 | case SENDTOWORKSPACE: |
292 | if (argc + 1 < val.size()) | 292 | if (argc + 1 < val.size()) |
293 | last_key->param = atoi( val[argc+1].c_str()); | 293 | last_key->param = atoi( val[argc+1].c_str()); |
294 | else | 294 | else |
295 | last_key->param = 0; | 295 | last_key->param = 0; |
296 | break; | 296 | break; |
297 | case NEXTWINDOW: | 297 | case NEXTWINDOW: |
298 | case PREVWINDOW: | 298 | case PREVWINDOW: |
299 | if (argc + 1 < val.size()) | 299 | if (argc + 1 < val.size()) |
300 | last_key->param = atoi( val[argc+1].c_str()); | 300 | last_key->param = atoi( val[argc+1].c_str()); |
301 | else | 301 | else |
302 | last_key->param = 0; | 302 | last_key->param = 0; |
303 | break; | 303 | break; |
304 | case LEFTWORKSPACE: | 304 | case LEFTWORKSPACE: |
305 | case RIGHTWORKSPACE: | 305 | case RIGHTWORKSPACE: |
306 | case NEXTWORKSPACE: | 306 | case NEXTWORKSPACE: |
307 | case PREVWORKSPACE: | 307 | case PREVWORKSPACE: |
308 | if (argc + 1 < val.size()) | 308 | if (argc + 1 < val.size()) |
309 | last_key->param = atoi( val[argc+1].c_str()); | 309 | last_key->param = atoi( val[argc+1].c_str()); |
310 | else | 310 | else |
311 | last_key->param = 1; | 311 | last_key->param = 1; |
312 | break; | 312 | break; |
313 | case NUDGERIGHT: | 313 | case NUDGERIGHT: |
314 | case NUDGELEFT: | 314 | case NUDGELEFT: |
315 | case NUDGEUP: | 315 | case NUDGEUP: |
316 | case NUDGEDOWN: | 316 | case NUDGEDOWN: |
317 | if (argc + 1 < val.size()) | 317 | if (argc + 1 < val.size()) |
318 | last_key->param = atoi( val[argc+1].c_str()); | 318 | last_key->param = atoi( val[argc+1].c_str()); |
319 | else | 319 | else |
320 | last_key->param = 2; | 320 | last_key->param = 2; |
321 | break; | 321 | break; |
322 | default: | 322 | default: |
323 | break; | 323 | break; |
324 | } | 324 | } |
325 | 325 | ||
326 | //add the keychain to list | 326 | //add the keychain to list |
327 | if (!mergeTree(current_key)) | 327 | if (!mergeTree(current_key)) |
328 | cerr<<"Keys: Failed to merge keytree!"<<endl; | 328 | cerr<<"Keys: Failed to merge keytree!"<<endl; |
329 | 329 | ||
330 | //clear keypointers now that we have them in m_keylist | 330 | //clear keypointers now that we have them in m_keylist |
331 | delete current_key; | 331 | delete current_key; |
332 | current_key = 0; | 332 | current_key = 0; |
333 | last_key = 0; | 333 | last_key = 0; |
334 | 334 | ||
335 | } else { //destroy list if no action is found | 335 | } else { //destroy list if no action is found |
336 | #ifdef DEBUG | 336 | #ifdef DEBUG |
337 | cerr<<"Didnt find action="<<val[argc]<<endl; | 337 | cerr<<"Didnt find action="<<val[argc]<<endl; |
338 | #endif // DEBUG | 338 | #endif // DEBUG |
339 | //destroy current_key ... this will also destroy the last_key | 339 | //destroy current_key ... this will also destroy the last_key |
340 | delete current_key; | 340 | delete current_key; |
341 | current_key = 0; | 341 | current_key = 0; |
342 | last_key = 0; | 342 | last_key = 0; |
343 | } | 343 | } |
344 | 344 | ||
345 | break; //dont process this linebuffer more | 345 | break; //dont process this linebuffer more |
346 | } | 346 | } |
347 | } | 347 | } |
348 | } | 348 | } |
349 | 349 | ||
350 | return true; | 350 | return true; |
351 | } | 351 | } |
352 | 352 | ||
353 | //--------- grabKey --------------------- | 353 | //--------- grabKey --------------------- |
@@ -356,50 +356,50 @@ bool Keys::load(const char *filename) { | |||
356 | //---------------------------------------- | 356 | //---------------------------------------- |
357 | void Keys::grabKey(unsigned int key, unsigned int mod) { | 357 | void Keys::grabKey(unsigned int key, unsigned int mod) { |
358 | 358 | ||
359 | for (int screen=0; screen<ScreenCount(m_display); screen++) { | 359 | for (int screen=0; screen<ScreenCount(m_display); screen++) { |
360 | 360 | ||
361 | Window root = RootWindow(m_display, screen); | 361 | Window root = RootWindow(m_display, screen); |
362 | 362 | ||
363 | XGrabKey(m_display, key, mod, | 363 | XGrabKey(m_display, key, mod, |
364 | root, True, | 364 | root, True, |
365 | GrabModeAsync, GrabModeAsync); | 365 | GrabModeAsync, GrabModeAsync); |
366 | 366 | ||
367 | // Grab with numlock, capslock and scrlock | 367 | // Grab with numlock, capslock and scrlock |
368 | 368 | ||
369 | //numlock | 369 | //numlock |
370 | XGrabKey(m_display, key, mod|m_numlock_mod, | 370 | XGrabKey(m_display, key, mod|m_numlock_mod, |
371 | root, True, | 371 | root, True, |
372 | GrabModeAsync, GrabModeAsync); | 372 | GrabModeAsync, GrabModeAsync); |
373 | //scrolllock | 373 | //scrolllock |
374 | XGrabKey(m_display, key, mod|m_scrolllock_mod, | 374 | XGrabKey(m_display, key, mod|m_scrolllock_mod, |
375 | root, True, | 375 | root, True, |
376 | GrabModeAsync, GrabModeAsync); | 376 | GrabModeAsync, GrabModeAsync); |
377 | //capslock | 377 | //capslock |
378 | XGrabKey(m_display, key, mod|m_capslock_mod, | 378 | XGrabKey(m_display, key, mod|m_capslock_mod, |
379 | root, True, | 379 | root, True, |
380 | GrabModeAsync, GrabModeAsync); | 380 | GrabModeAsync, GrabModeAsync); |
381 | 381 | ||
382 | //capslock+numlock | 382 | //capslock+numlock |
383 | XGrabKey(m_display, key, mod|m_capslock_mod|m_numlock_mod, | 383 | XGrabKey(m_display, key, mod|m_capslock_mod|m_numlock_mod, |
384 | root, True, | 384 | root, True, |
385 | GrabModeAsync, GrabModeAsync); | 385 | GrabModeAsync, GrabModeAsync); |
386 | 386 | ||
387 | //capslock+scrolllock | 387 | //capslock+scrolllock |
388 | XGrabKey(m_display, key, mod|m_capslock_mod|m_scrolllock_mod, | 388 | XGrabKey(m_display, key, mod|m_capslock_mod|m_scrolllock_mod, |
389 | root, True, | 389 | root, True, |
390 | GrabModeAsync, GrabModeAsync); | 390 | GrabModeAsync, GrabModeAsync); |
391 | 391 | ||
392 | //capslock+numlock+scrolllock | 392 | //capslock+numlock+scrolllock |
393 | XGrabKey(m_display, key, mod|m_capslock_mod|m_scrolllock_mod|m_numlock_mod, | 393 | XGrabKey(m_display, key, mod|m_capslock_mod|m_scrolllock_mod|m_numlock_mod, |
394 | root, True, | 394 | root, True, |
395 | GrabModeAsync, GrabModeAsync); | 395 | GrabModeAsync, GrabModeAsync); |
396 | 396 | ||
397 | //numlock+scrollLock | 397 | //numlock+scrollLock |
398 | XGrabKey(m_display, key, mod|m_numlock_mod|m_scrolllock_mod, | 398 | XGrabKey(m_display, key, mod|m_numlock_mod|m_scrolllock_mod, |
399 | root, True, | 399 | root, True, |
400 | GrabModeAsync, GrabModeAsync); | 400 | GrabModeAsync, GrabModeAsync); |
401 | 401 | ||
402 | } | 402 | } |
403 | 403 | ||
404 | } | 404 | } |
405 | 405 | ||
@@ -409,32 +409,32 @@ void Keys::grabKey(unsigned int key, unsigned int mod) { | |||
409 | // TODO fix more masks | 409 | // TODO fix more masks |
410 | //---------------------------------------- | 410 | //---------------------------------------- |
411 | unsigned int Keys::getModifier(const char *modstr) { | 411 | unsigned int Keys::getModifier(const char *modstr) { |
412 | if (!modstr) | 412 | if (!modstr) |
413 | return 0; | 413 | return 0; |
414 | struct t_modlist{ | 414 | struct t_modlist{ |
415 | char *string; | 415 | char *string; |
416 | unsigned int mask; | 416 | unsigned int mask; |
417 | bool operator == (const char *modstr) { | 417 | bool operator == (const char *modstr) { |
418 | return (strcasecmp(string, modstr) == 0 && mask !=0); | 418 | return (strcasecmp(string, modstr) == 0 && mask !=0); |
419 | } | 419 | } |
420 | } modlist[] = { | 420 | } modlist[] = { |
421 | {"SHIFT", ShiftMask}, | 421 | {"SHIFT", ShiftMask}, |
422 | {"CONTROL", ControlMask}, | 422 | {"CONTROL", ControlMask}, |
423 | {"MOD1", Mod1Mask}, | 423 | {"MOD1", Mod1Mask}, |
424 | {"MOD2", Mod2Mask}, | 424 | {"MOD2", Mod2Mask}, |
425 | {"MOD3", Mod3Mask}, | 425 | {"MOD3", Mod3Mask}, |
426 | {"MOD4", Mod4Mask}, | 426 | {"MOD4", Mod4Mask}, |
427 | {"MOD5", Mod5Mask}, | 427 | {"MOD5", Mod5Mask}, |
428 | {0, 0} | 428 | {0, 0} |
429 | }; | 429 | }; |
430 | 430 | ||
431 | // find mod mask string | 431 | // find mod mask string |
432 | for (unsigned int i=0; modlist[i].string!=0; i++) { | 432 | for (unsigned int i=0; modlist[i].string!=0; i++) { |
433 | if (modlist[i] == modstr) | 433 | if (modlist[i] == modstr) |
434 | return modlist[i].mask; | 434 | return modlist[i].mask; |
435 | } | 435 | } |
436 | 436 | ||
437 | return 0; | 437 | return 0; |
438 | } | 438 | } |
439 | 439 | ||
440 | //----------- getKey ---------------- | 440 | //----------- getKey ---------------- |
@@ -442,63 +442,63 @@ unsigned int Keys::getModifier(const char *modstr) { | |||
442 | // else it returns zero | 442 | // else it returns zero |
443 | //----------------------------------- | 443 | //----------------------------------- |
444 | unsigned int Keys::getKey(const char *keystr) { | 444 | unsigned int Keys::getKey(const char *keystr) { |
445 | if (!keystr) | 445 | if (!keystr) |
446 | return 0; | 446 | return 0; |
447 | return XKeysymToKeycode(m_display, | 447 | return XKeysymToKeycode(m_display, |
448 | XStringToKeysym(keystr)); | 448 | XStringToKeysym(keystr)); |
449 | } | 449 | } |
450 | 450 | ||
451 | //--------- getAction ----------------- | 451 | //--------- getAction ----------------- |
452 | // returns the KeyAction of the XKeyEvent | 452 | // returns the KeyAction of the XKeyEvent |
453 | //------------------------------------- | 453 | //------------------------------------- |
454 | Keys::KeyAction Keys::getAction(XKeyEvent *ke) { | 454 | Keys::KeyAction Keys::getAction(XKeyEvent *ke) { |
455 | static t_key *next_key = 0; | 455 | static t_key *next_key = 0; |
456 | //remove numlock, capslock and scrolllock | 456 | //remove numlock, capslock and scrolllock |
457 | ke->state &= ~Mod2Mask & ~Mod5Mask & ~LockMask; | 457 | ke->state &= ~Mod2Mask & ~Mod5Mask & ~LockMask; |
458 | 458 | ||
459 | if (m_abortkey && *m_abortkey==ke) { //abort current keychain | 459 | if (m_abortkey && *m_abortkey==ke) { //abort current keychain |
460 | next_key = 0; | 460 | next_key = 0; |
461 | return m_abortkey->action; | 461 | return m_abortkey->action; |
462 | } | 462 | } |
463 | 463 | ||
464 | if (!next_key) { | 464 | if (!next_key) { |
465 | 465 | ||
466 | for (unsigned int i=0; i<m_keylist.size(); i++) { | 466 | for (unsigned int i=0; i<m_keylist.size(); i++) { |
467 | if (*m_keylist[i] == ke) { | 467 | if (*m_keylist[i] == ke) { |
468 | if (m_keylist[i]->keylist.size()) { | 468 | if (m_keylist[i]->keylist.size()) { |
469 | next_key = m_keylist[i]; | 469 | next_key = m_keylist[i]; |
470 | break; //end for-loop | 470 | break; //end for-loop |
471 | } else { | 471 | } else { |
472 | if (m_keylist[i]->action == Keys::EXECUTE) | 472 | if (m_keylist[i]->action == Keys::EXECUTE) |
473 | m_execcmdstring = m_keylist[i]->execcommand; //update execcmdstring if action is grabExecute | 473 | m_execcmdstring = m_keylist[i]->execcommand; //update execcmdstring if action is grabExecute |
474 | m_param = m_keylist[i]->param; | 474 | m_param = m_keylist[i]->param; |
475 | return m_keylist[i]->action; | 475 | return m_keylist[i]->action; |
476 | } | 476 | } |
477 | } | 477 | } |
478 | } | 478 | } |
479 | 479 | ||
480 | } else { //check the nextkey | 480 | } else { //check the nextkey |
481 | t_key *temp_key = next_key->find(ke); | 481 | t_key *temp_key = next_key->find(ke); |
482 | if (temp_key) { | 482 | if (temp_key) { |
483 | if (temp_key->keylist.size()) { | 483 | if (temp_key->keylist.size()) { |
484 | next_key = temp_key; | 484 | next_key = temp_key; |
485 | } else { | 485 | } else { |
486 | next_key = 0; | 486 | next_key = 0; |
487 | if (temp_key->action == Keys::EXECUTE) | 487 | if (temp_key->action == Keys::EXECUTE) |
488 | m_execcmdstring = temp_key->execcommand; //update execcmdstring if action is grabExecute | 488 | m_execcmdstring = temp_key->execcommand; //update execcmdstring if action is grabExecute |
489 | return temp_key->action; | 489 | return temp_key->action; |
490 | } | 490 | } |
491 | } else { | 491 | } else { |
492 | temp_key = next_key; | 492 | temp_key = next_key; |
493 | next_key = 0; | 493 | next_key = 0; |
494 | if (temp_key->action == Keys::EXECUTE) | 494 | if (temp_key->action == Keys::EXECUTE) |
495 | m_execcmdstring = temp_key->execcommand; //update execcmdstring if action is grabExecute | 495 | m_execcmdstring = temp_key->execcommand; //update execcmdstring if action is grabExecute |
496 | return temp_key->action; | 496 | return temp_key->action; |
497 | } | 497 | } |
498 | 498 | ||
499 | } | 499 | } |
500 | 500 | ||
501 | return Keys::LASTKEYGRAB; | 501 | return Keys::LASTKEYGRAB; |
502 | } | 502 | } |
503 | 503 | ||
504 | //--------- reconfigure ------------- | 504 | //--------- reconfigure ------------- |
@@ -506,8 +506,8 @@ Keys::KeyAction Keys::getAction(XKeyEvent *ke) { | |||
506 | // returns true on success else false | 506 | // returns true on success else false |
507 | //----------------------------------- | 507 | //----------------------------------- |
508 | bool Keys::reconfigure(const char *filename) { | 508 | bool Keys::reconfigure(const char *filename) { |
509 | deleteTree(); | 509 | deleteTree(); |
510 | return load(filename); | 510 | return load(filename); |
511 | } | 511 | } |
512 | 512 | ||
513 | //------------- getActionStr ------------------ | 513 | //------------- getActionStr ------------------ |
@@ -516,12 +516,12 @@ bool Keys::reconfigure(const char *filename) { | |||
516 | // 0 on failure | 516 | // 0 on failure |
517 | //--------------------------------------------- | 517 | //--------------------------------------------- |
518 | const char *Keys::getActionStr(KeyAction action) { | 518 | const char *Keys::getActionStr(KeyAction action) { |
519 | for (unsigned int i=0; m_actionlist[i].string!=0 ; i++) { | 519 | for (unsigned int i=0; m_actionlist[i].string!=0 ; i++) { |
520 | if (m_actionlist[i].action == action) | 520 | if (m_actionlist[i].action == action) |
521 | return m_actionlist[i].string; | 521 | return m_actionlist[i].string; |
522 | } | 522 | } |
523 | 523 | ||
524 | return 0; | 524 | return 0; |
525 | } | 525 | } |
526 | 526 | ||
527 | #ifdef DEBUG | 527 | #ifdef DEBUG |
@@ -531,29 +531,29 @@ const char *Keys::getActionStr(KeyAction action) { | |||
531 | // rootlist | 531 | // rootlist |
532 | //------------------------------ | 532 | //------------------------------ |
533 | void Keys::showTree() { | 533 | void Keys::showTree() { |
534 | for (unsigned int i=0; i<m_keylist.size(); i++) { | 534 | for (unsigned int i=0; i<m_keylist.size(); i++) { |
535 | if (m_keylist[i]) { | 535 | if (m_keylist[i]) { |
536 | cerr<<i<<" "; | 536 | cerr<<i<<" "; |
537 | showKeyTree(m_keylist[i]); | 537 | showKeyTree(m_keylist[i]); |
538 | } else | 538 | } else |
539 | cerr<<"Null @ "<<i<<endl; | 539 | cerr<<"Null @ "<<i<<endl; |
540 | } | 540 | } |
541 | } | 541 | } |
542 | 542 | ||
543 | //---------- showKeyTree -------- | 543 | //---------- showKeyTree -------- |
544 | // Debug function to show t_key tree | 544 | // Debug function to show t_key tree |
545 | //------------------------------- | 545 | //------------------------------- |
546 | void Keys::showKeyTree(t_key *key, unsigned int w) { | 546 | void Keys::showKeyTree(t_key *key, unsigned int w) { |
547 | for (unsigned int i=0; i<w+1; i++) | 547 | for (unsigned int i=0; i<w+1; i++) |
548 | cerr<<"-"; | 548 | cerr<<"-"; |
549 | if (!key->keylist.empty()) { | 549 | if (!key->keylist.empty()) { |
550 | for (unsigned int i=0; i<key->keylist.size(); i++) { | 550 | for (unsigned int i=0; i<key->keylist.size(); i++) { |
551 | cerr<<"( "<<(int)key->key<<" "<<(int)key->mod<<" )"; | 551 | cerr<<"( "<<(int)key->key<<" "<<(int)key->mod<<" )"; |
552 | showKeyTree(key->keylist[i], 4); | 552 | showKeyTree(key->keylist[i], 4); |
553 | cerr<<endl; | 553 | cerr<<endl; |
554 | } | 554 | } |
555 | } else | 555 | } else |
556 | cerr<<"( "<<(int)key->key<<" "<<(int)key->mod<<" ) {"<<getActionStr(key->action)<<"}"<<endl; | 556 | cerr<<"( "<<(int)key->key<<" "<<(int)key->mod<<" ) {"<<getActionStr(key->action)<<"}"<<endl; |
557 | } | 557 | } |
558 | #endif //DEBUG | 558 | #endif //DEBUG |
559 | 559 | ||
@@ -562,113 +562,113 @@ void Keys::showKeyTree(t_key *key, unsigned int w) { | |||
562 | // Returns true on success else false. | 562 | // Returns true on success else false. |
563 | //--------------------------------------- | 563 | //--------------------------------------- |
564 | bool Keys::mergeTree(t_key *newtree, t_key *basetree) { | 564 | bool Keys::mergeTree(t_key *newtree, t_key *basetree) { |
565 | if (basetree==0) { | 565 | if (basetree==0) { |
566 | unsigned int baselist_i=0; | 566 | unsigned int baselist_i=0; |
567 | for (; baselist_i<m_keylist.size(); baselist_i++) { | 567 | for (; baselist_i<m_keylist.size(); baselist_i++) { |
568 | if (m_keylist[baselist_i]->mod == newtree->mod && | 568 | if (m_keylist[baselist_i]->mod == newtree->mod && |
569 | m_keylist[baselist_i]->key == newtree->key) { | 569 | m_keylist[baselist_i]->key == newtree->key) { |
570 | if (newtree->keylist.size() && m_keylist[baselist_i]->action == LASTKEYGRAB) { | 570 | if (newtree->keylist.size() && m_keylist[baselist_i]->action == LASTKEYGRAB) { |
571 | //assumes the newtree only have one branch | 571 | //assumes the newtree only have one branch |
572 | return mergeTree(newtree->keylist[0], m_keylist[baselist_i]); | 572 | return mergeTree(newtree->keylist[0], m_keylist[baselist_i]); |
573 | } else | 573 | } else |
574 | break; | 574 | break; |
575 | } | 575 | } |
576 | } | 576 | } |
577 | 577 | ||
578 | if (baselist_i == m_keylist.size()) { | 578 | if (baselist_i == m_keylist.size()) { |
579 | grabKey(newtree->key, newtree->mod); | 579 | grabKey(newtree->key, newtree->mod); |
580 | m_keylist.push_back(new t_key(newtree)); | 580 | m_keylist.push_back(new t_key(newtree)); |
581 | if (newtree->keylist.size()) | 581 | if (newtree->keylist.size()) |
582 | return mergeTree(newtree->keylist[0], m_keylist.back()); | 582 | return mergeTree(newtree->keylist[0], m_keylist.back()); |
583 | return true; | 583 | return true; |
584 | } | 584 | } |
585 | 585 | ||
586 | } else { | 586 | } else { |
587 | unsigned int baselist_i = 0; | 587 | unsigned int baselist_i = 0; |
588 | for (; baselist_i<basetree->keylist.size(); baselist_i++) { | 588 | for (; baselist_i<basetree->keylist.size(); baselist_i++) { |
589 | if (basetree->keylist[baselist_i]->mod == newtree->mod && | 589 | if (basetree->keylist[baselist_i]->mod == newtree->mod && |
590 | basetree->keylist[baselist_i]->key == newtree->key) { | 590 | basetree->keylist[baselist_i]->key == newtree->key) { |
591 | if (newtree->keylist.size()) { | 591 | if (newtree->keylist.size()) { |
592 | //assumes the newtree only have on branch | 592 | //assumes the newtree only have on branch |
593 | return mergeTree(newtree->keylist[0], basetree->keylist[baselist_i]); | 593 | return mergeTree(newtree->keylist[0], basetree->keylist[baselist_i]); |
594 | } else | 594 | } else |
595 | return false; | 595 | return false; |
596 | } | 596 | } |
597 | } | 597 | } |
598 | //if it wasn't in the list grab the key and add it to the list | 598 | //if it wasn't in the list grab the key and add it to the list |
599 | if (baselist_i==basetree->keylist.size()) { | 599 | if (baselist_i==basetree->keylist.size()) { |
600 | grabKey(newtree->key, newtree->mod); | 600 | grabKey(newtree->key, newtree->mod); |
601 | basetree->keylist.push_back(new t_key(newtree)); | 601 | basetree->keylist.push_back(new t_key(newtree)); |
602 | if (newtree->keylist.size()) | 602 | if (newtree->keylist.size()) |
603 | return mergeTree(newtree->keylist[0], basetree->keylist.back()); | 603 | return mergeTree(newtree->keylist[0], basetree->keylist.back()); |
604 | return true; | 604 | return true; |
605 | } | 605 | } |
606 | } | 606 | } |
607 | 607 | ||
608 | return false; | 608 | return false; |
609 | } | 609 | } |
610 | 610 | ||
611 | Keys::t_key::t_key(unsigned int key_, unsigned int mod_, KeyAction action_) { | 611 | Keys::t_key::t_key(unsigned int key_, unsigned int mod_, KeyAction action_) { |
612 | action = action_; | 612 | action = action_; |
613 | key = key_; | 613 | key = key_; |
614 | mod = mod_; | 614 | mod = mod_; |
615 | param = 0; | 615 | param = 0; |
616 | } | 616 | } |
617 | 617 | ||
618 | Keys::t_key::t_key(t_key *k) { | 618 | Keys::t_key::t_key(t_key *k) { |
619 | action = k->action; | 619 | action = k->action; |
620 | key = k->key; | 620 | key = k->key; |
621 | mod = k->mod; | 621 | mod = k->mod; |
622 | execcommand = k->execcommand; | 622 | execcommand = k->execcommand; |
623 | param = k-> param; | 623 | param = k-> param; |
624 | } | 624 | } |
625 | 625 | ||
626 | Keys::t_key::~t_key() { | 626 | Keys::t_key::~t_key() { |
627 | while (!keylist.empty()) { | 627 | while (!keylist.empty()) { |
628 | t_key *k = keylist.back(); | 628 | t_key *k = keylist.back(); |
629 | if (k != 0) { // make sure we don't have a bad key pointer | 629 | if (k != 0) { // make sure we don't have a bad key pointer |
630 | delete k; | 630 | delete k; |
631 | keylist.pop_back(); | 631 | keylist.pop_back(); |
632 | } | 632 | } |
633 | } | 633 | } |
634 | } | 634 | } |
635 | 635 | ||
636 | void Keys::determineModmap() { | 636 | void Keys::determineModmap() { |
637 | // mask to use for modifier | 637 | // mask to use for modifier |
638 | int mods[] = { | 638 | int mods[] = { |
639 | ShiftMask, | 639 | ShiftMask, |
640 | LockMask, | 640 | LockMask, |
641 | ControlMask, | 641 | ControlMask, |
642 | Mod1Mask, | 642 | Mod1Mask, |
643 | Mod2Mask, | 643 | Mod2Mask, |
644 | Mod3Mask, | 644 | Mod3Mask, |
645 | Mod4Mask, | 645 | Mod4Mask, |
646 | Mod5Mask, | 646 | Mod5Mask, |
647 | 0 | 647 | 0 |
648 | }; | 648 | }; |
649 | 649 | ||
650 | XModifierKeymap *map = XGetModifierMapping(m_display); | 650 | XModifierKeymap *map = XGetModifierMapping(m_display); |
651 | // find modifiers and set them | 651 | // find modifiers and set them |
652 | for (int i=0, realkey=0; i<8; ++i) { | 652 | for (int i=0, realkey=0; i<8; ++i) { |
653 | for (int key=0; key<map->max_keypermod; ++key, ++realkey) { | 653 | for (int key=0; key<map->max_keypermod; ++key, ++realkey) { |
654 | 654 | ||
655 | if (map->modifiermap[realkey] == 0) | 655 | if (map->modifiermap[realkey] == 0) |
656 | continue; | 656 | continue; |
657 | 657 | ||
658 | KeySym ks = XKeycodeToKeysym(m_display, map->modifiermap[realkey], 0); | 658 | KeySym ks = XKeycodeToKeysym(m_display, map->modifiermap[realkey], 0); |
659 | 659 | ||
660 | switch (ks) { | 660 | switch (ks) { |
661 | case XK_Caps_Lock: | 661 | case XK_Caps_Lock: |
662 | m_capslock_mod = mods[i]; | 662 | m_capslock_mod = mods[i]; |
663 | break; | 663 | break; |
664 | case XK_Scroll_Lock: | 664 | case XK_Scroll_Lock: |
665 | m_scrolllock_mod = mods[i]; | 665 | m_scrolllock_mod = mods[i]; |
666 | break; | 666 | break; |
667 | case XK_Num_Lock: | 667 | case XK_Num_Lock: |
668 | m_numlock_mod = mods[i]; | 668 | m_numlock_mod = mods[i]; |
669 | break; | 669 | break; |
670 | } | 670 | } |
671 | } | 671 | } |
672 | } | 672 | } |
673 | XFreeModifiermap(map); | 673 | XFreeModifiermap(map); |
674 | } | 674 | } |