aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Keys.cc109
1 files changed, 52 insertions, 57 deletions
diff --git a/src/Keys.cc b/src/Keys.cc
index 5343634..20677cd 100644
--- a/src/Keys.cc
+++ b/src/Keys.cc
@@ -19,12 +19,13 @@
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.22 2003/02/02 16:32:37 rathnor Exp $ 22//$Id: Keys.cc,v 1.23 2003/02/28 23:55:37 fluxgen Exp $
23 23
24 24
25#include "Keys.hh" 25#include "Keys.hh"
26 26
27#include "StringUtil.hh" 27#include "StringUtil.hh"
28#include "App.hh"
28 29
29#ifdef HAVE_CONFIG_H 30#ifdef HAVE_CONFIG_H
30#include "../config.h" 31#include "../config.h"
@@ -132,15 +133,14 @@ Keys::t_actionstr Keys::m_actionlist[] = {
132 {0, LASTKEYGRAB} 133 {0, LASTKEYGRAB}
133}; 134};
134 135
135Keys::Keys(Display *display, const char *filename): 136Keys::Keys(const char *filename):
136 m_capslock_mod(0), 137 m_capslock_mod(0),
137 m_numlock_mod(0), 138 m_numlock_mod(0),
138 m_scrolllock_mod(0), 139 m_scrolllock_mod(0),
139 m_abortkey(0), 140 m_abortkey(0),
140 m_display(display) 141 m_display(FbTk::App::instance()->display())
141{ 142{
142 determineModmap(); 143 determineModmap();
143 assert(display);
144 if (filename != 0) 144 if (filename != 0)
145 load(filename); 145 load(filename);
146} 146}
@@ -150,9 +150,7 @@ Keys::~Keys() {
150 deleteTree(); 150 deleteTree();
151} 151}
152 152
153//--------- deleteTree ----------- 153/// Destroys the keytree and m_abortkey
154// Destroys the keytree and m_abortkey
155//--------------------------------
156void Keys::deleteTree() { 154void Keys::deleteTree() {
157 while (!m_keylist.empty()) { 155 while (!m_keylist.empty()) {
158 if (m_keylist.back() && m_keylist.back() != 0) 156 if (m_keylist.back() && m_keylist.back() != 0)
@@ -165,9 +163,7 @@ void Keys::deleteTree() {
165 } 163 }
166} 164}
167 165
168//-------- ungrabKeys --------- 166/// Ungrabs the keys
169// Ungrabs the keys
170//-----------------------------
171void Keys::ungrabKeys() { 167void Keys::ungrabKeys() {
172 for (int screen=0; screen<ScreenCount(m_display); screen++) { 168 for (int screen=0; screen<ScreenCount(m_display); screen++) {
173 XUngrabKey(m_display, AnyKey, AnyModifier, 169 XUngrabKey(m_display, AnyKey, AnyModifier,
@@ -175,11 +171,11 @@ void Keys::ungrabKeys() {
175 } 171 }
176} 172}
177 173
178//-------------- load ---------------- 174/**
179// Load and grab keys 175 Load and grab keys
180// Returns true on success else false 176 TODO: error checking
181// TODO: error checking 177 @return true on success else false
182//------------------------------------ 178*/
183bool Keys::load(const char *filename) { 179bool Keys::load(const char *filename) {
184 if (!filename) 180 if (!filename)
185 return false; 181 return false;
@@ -222,14 +218,14 @@ bool Keys::load(const char *filename) {
222 218
223 for (unsigned int argc=0; argc<val.size(); argc++) { 219 for (unsigned int argc=0; argc<val.size(); argc++) {
224 220
225 if (val[argc][0]!=':') { 221 if (val[argc][0] != ':') {
226 keyarg++; 222 keyarg++;
227 if (keyarg==1) //first arg is modifier 223 if (keyarg==1) //first arg is modifier
228 mod = getModifier(val[argc].c_str()); 224 mod = getModifier(val[argc].c_str());
229 else if (keyarg>1) { 225 else if (keyarg>1) {
230 226
231 //keyarg=0; 227 //keyarg=0;
232 int tmpmod=getModifier(val[argc].c_str()); 228 int tmpmod = getModifier(val[argc].c_str());
233 if(tmpmod) 229 if(tmpmod)
234 mod|=tmpmod; //If it's a modifier 230 mod|=tmpmod; //If it's a modifier
235 else { 231 else {
@@ -351,17 +347,17 @@ bool Keys::load(const char *filename) {
351 } 347 }
352 348
353 break; //dont process this linebuffer more 349 break; //dont process this linebuffer more
354 } 350 } // end if
355 } 351 } // end for
356 } 352 } // end while
357 353
358 return true; 354 return true;
359} 355}
360 356
361//--------- grabKey --------------------- 357/**
362// Grabs a key with the modifier 358 Grabs a key with the modifier
363// and with numlock,capslock and scrollock 359 and with numlock,capslock and scrollock
364//---------------------------------------- 360*/
365void Keys::grabKey(unsigned int key, unsigned int mod) { 361void Keys::grabKey(unsigned int key, unsigned int mod) {
366 362
367 for (int screen=0; screen<ScreenCount(m_display); screen++) { 363 for (int screen=0; screen<ScreenCount(m_display); screen++) {
@@ -411,11 +407,10 @@ void Keys::grabKey(unsigned int key, unsigned int mod) {
411 407
412} 408}
413 409
414//------------ getModifier --------------- 410/**
415// Returns the modifier for the modstr 411 @return the modifier for the modstr else zero on failure.
416// else zero on failure. 412 TODO fix more masks
417// TODO fix more masks 413*/
418//----------------------------------------
419unsigned int Keys::getModifier(const char *modstr) { 414unsigned int Keys::getModifier(const char *modstr) {
420 if (!modstr) 415 if (!modstr)
421 return 0; 416 return 0;
@@ -445,10 +440,9 @@ unsigned int Keys::getModifier(const char *modstr) {
445 return 0; 440 return 0;
446} 441}
447 442
448//----------- getKey ---------------- 443/**
449// Returns keycode of keystr on success 444 @return keycode of keystr on success else 0
450// else it returns zero 445*/
451//-----------------------------------
452unsigned int Keys::getKey(const char *keystr) { 446unsigned int Keys::getKey(const char *keystr) {
453 if (!keystr) 447 if (!keystr)
454 return 0; 448 return 0;
@@ -456,9 +450,9 @@ unsigned int Keys::getKey(const char *keystr) {
456 XStringToKeysym(keystr)); 450 XStringToKeysym(keystr));
457} 451}
458 452
459//--------- getAction ----------------- 453/**
460// returns the KeyAction of the XKeyEvent 454 @return the KeyAction of the XKeyEvent
461//------------------------------------- 455*/
462Keys::KeyAction Keys::getAction(XKeyEvent *ke) { 456Keys::KeyAction Keys::getAction(XKeyEvent *ke) {
463 static t_key *next_key = 0; 457 static t_key *next_key = 0;
464 //remove numlock, capslock and scrolllock 458 //remove numlock, capslock and scrolllock
@@ -509,20 +503,19 @@ Keys::KeyAction Keys::getAction(XKeyEvent *ke) {
509 return Keys::LASTKEYGRAB; 503 return Keys::LASTKEYGRAB;
510} 504}
511 505
512//--------- reconfigure ------------- 506/**
513// deletes the tree and load configuration 507 deletes the tree and load configuration
514// returns true on success else false 508 returns true on success else false
515//----------------------------------- 509*/
516bool Keys::reconfigure(const char *filename) { 510bool Keys::reconfigure(const char *filename) {
517 deleteTree(); 511 deleteTree();
518 return load(filename); 512 return load(filename);
519} 513}
520 514
521//------------- getActionStr ------------------ 515/**
522// Tries to find the action for the key 516 Tries to find the action for the key
523// Returns actionstring on success else 517 @return actionstring on success else 0 on failure
524// 0 on failure 518*/
525//---------------------------------------------
526const char *Keys::getActionStr(KeyAction action) { 519const char *Keys::getActionStr(KeyAction action) {
527 for (unsigned int i=0; m_actionlist[i].string!=0 ; i++) { 520 for (unsigned int i=0; m_actionlist[i].string!=0 ; i++) {
528 if (m_actionlist[i].action == action) 521 if (m_actionlist[i].action == action)
@@ -533,11 +526,10 @@ const char *Keys::getActionStr(KeyAction action) {
533} 526}
534 527
535#ifdef DEBUG 528#ifdef DEBUG
536//--------- showTree ----------- 529/*
537// Debug function that show the 530 Debug function that show the
538// keytree. Starts with the 531 keytree. Starts with the rootlist
539// rootlist 532*/
540//------------------------------
541void Keys::showTree() { 533void Keys::showTree() {
542 for (unsigned int i=0; i<m_keylist.size(); i++) { 534 for (unsigned int i=0; i<m_keylist.size(); i++) {
543 if (m_keylist[i]) { 535 if (m_keylist[i]) {
@@ -548,9 +540,9 @@ void Keys::showTree() {
548 } 540 }
549} 541}
550 542
551//---------- showKeyTree -------- 543/**
552// Debug function to show t_key tree 544 Debug function to show t_key tree
553//------------------------------- 545*/
554void Keys::showKeyTree(t_key *key, unsigned int w) { 546void Keys::showKeyTree(t_key *key, unsigned int w) {
555 for (unsigned int i=0; i<w+1; i++) 547 for (unsigned int i=0; i<w+1; i++)
556 cerr<<"-"; 548 cerr<<"-";
@@ -565,10 +557,10 @@ void Keys::showKeyTree(t_key *key, unsigned int w) {
565} 557}
566#endif //DEBUG 558#endif //DEBUG
567 559
568//------------ mergeTree --------------- 560/**
569// Merges two chains and binds new keys 561 Merges two chains and binds new keys
570// Returns true on success else false. 562 @return true on success else false.
571//--------------------------------------- 563*/
572bool Keys::mergeTree(t_key *newtree, t_key *basetree) { 564bool Keys::mergeTree(t_key *newtree, t_key *basetree) {
573 if (basetree==0) { 565 if (basetree==0) {
574 unsigned int baselist_i=0; 566 unsigned int baselist_i=0;
@@ -641,6 +633,9 @@ Keys::t_key::~t_key() {
641 } 633 }
642} 634}
643 635
636/**
637 determines modifier mapping for caps, num and scroll lock
638*/
644void Keys::determineModmap() { 639void Keys::determineModmap() {
645 // mask to use for modifier 640 // mask to use for modifier
646 int mods[] = { 641 int mods[] = {