From 2765d34a196cf204db2c5d57d63e254cc2b90d8e Mon Sep 17 00:00:00 2001 From: fluxgen Date: Mon, 7 Jan 2002 23:44:09 +0000 Subject: Removed Fluxbox and ScreenInfo dep, moved from strtok to StringUtil::stringtok --- src/Keys.cc | 140 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 74 insertions(+), 66 deletions(-) diff --git a/src/Keys.cc b/src/Keys.cc index 59a8789..8b15f69 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -19,6 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +//$Id: Keys.cc,v 1.4 2002/01/07 23:44:09 fluxgen Exp $ #ifdef HAVE_CONFIG_H # include "config.h" @@ -26,9 +27,7 @@ #include "Keys.hh" -#ifndef _FLUXBOX_HH_ -# include "fluxbox.hh" -#endif +#include "StringUtil.hh" #ifdef HAVE_STDIO_H # include @@ -70,6 +69,8 @@ #include #include +#include +#include using namespace std; @@ -122,13 +123,18 @@ Keys::t_actionstr Keys::m_actionlist[] = { {0, LASTKEYGRAB} }; -Keys::Keys(char *filename) { - m_abortkey=0; - load(filename); +Keys::Keys(Display *display, char *filename): +m_abortkey(0), +m_display(display) +{ + assert(display); + if (filename) + load(filename); } Keys::~Keys() { deleteTree(); + ungrabKeys(); } //--------- deleteTree ----------- @@ -146,27 +152,29 @@ void Keys::deleteTree() { } } +//-------- ungrabKeys --------- +// Ungrabs the keys +//----------------------------- +void Keys::ungrabKeys() { + for (int screen=0; screengetXDisplay(); - ScreenInfo *screeninfo=0; //ungrab all keys - int screen=0; - while ((screeninfo = fluxbox->getScreenInfo(screen++)) ) { - XUngrabKey(display, AnyKey, AnyModifier, - screeninfo->getRootWindow()); - } - - XSync(display, False); + ungrabKeys(); + + XSync(m_display, False); //open the file ifstream infile(filename); @@ -174,35 +182,41 @@ bool Keys::load(char *filename) { return false; - char *linebuffer = new char[1024]; - int line=0; - int linepos=0; //position in the line + auto_ptr linebuffer(new char[1024]); + + int line=0;//current line, so we can tell the user where the fault is while (!infile.eof()) { - infile.getline(linebuffer, 1024); + + infile.getline(linebuffer.get(), 1024); line++; - char *val = strtok(linebuffer, " "); - linepos = (val==0 ? 0 : strlen(val) + 1); - - int numarg = 1; + vector val; + //Parse arguments + StringUtil::stringtok(val, linebuffer.get()); + //must have at least 1 argument + if (val.size()<=0) + continue; + + unsigned int key=0, mod=0; char keyarg=0; t_key *current_key=0, *last_key=0; - while (val) { + for (unsigned int argc=0; argc1) { //keyarg=0; - int tmpmod=getModifier(val); - if(tmpmod) mod|=tmpmod; //If it's a modifier + int tmpmod=getModifier(val[argc].c_str()); + if(tmpmod) + mod|=tmpmod; //If it's a modifier else{ - key = getKey(val); // else get the key + key = getKey(val[argc].c_str()); // else get the key if (!current_key) { current_key = new t_key(key, mod); last_key = current_key; @@ -216,19 +230,18 @@ bool Keys::load(char *filename) { } else { - val++; //ignore the ':' - unsigned int i=0; for (i=0; i< LASTKEYGRAB; i++) { - if (strcasecmp(m_actionlist[i].string, val) == 0) + // +1 on the val[argc] because we dont want to compare the ':' + if (strcasecmp(m_actionlist[i].string, val[argc].c_str()+1) == 0) break; } if (i < LASTKEYGRAB ) { if (!current_key) { cerr<<"Error on line: "<action = m_actionlist[i].action; if (last_key->action == Keys::EXECUTE) - last_key->execcommand = &linebuffer[linepos]; + last_key->execcommand = + static_cast(strcasestr(linebuffer.get(), getActionStr(Keys::EXECUTE))+ + strlen(getActionStr(Keys::EXECUTE))); //add the keychain to list if (!mergeTree(current_key)) @@ -261,8 +276,9 @@ bool Keys::load(char *filename) { #ifdef DEBUG if (m_actionlist[i].action == Keys::EXECUTE) { - cerr<<"linepos:"<(strcasestr(linebuffer.get(), getActionStr(Keys::EXECUTE))+ + strlen(getActionStr(Keys::EXECUTE)))<execcommand<getXDisplay(); - #ifdef DEBUG cerr<<__FILE__<<"("<<__LINE__<<"): keycode "<getScreenInfo(i++)) ) { - Window root = screeninfo->getRootWindow(); - XGrabKey(display, key, mod, + for (int screen=0; screengetXDisplay(), - XStringToKeysym - (keystr)); + return XKeysymToKeycode(m_display, + XStringToKeysym(keystr)); } //--------- getAction ----------------- -- cgit v0.11.2