From 24b7682033412123b3927aa4c1b7a92aef3a1a43 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Mon, 30 Jun 2003 14:57:14 +0000 Subject: using new CommandParser and Commands instead of enum actions --- src/Keys.cc | 302 +++++++----------------------------------------------------- src/Keys.hh | 87 ++++------------- 2 files changed, 51 insertions(+), 338 deletions(-) diff --git a/src/Keys.cc b/src/Keys.cc index 64ca79d..7de7d33 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -19,13 +19,15 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -//$Id: Keys.cc,v 1.31 2003/06/15 11:38:35 rathnor Exp $ +//$Id: Keys.cc,v 1.32 2003/06/30 14:57:14 fluxgen Exp $ #include "Keys.hh" #include "StringUtil.hh" #include "App.hh" +#include "Command.hh" +#include "CommandParser.hh" #ifdef HAVE_CONFIG_H #include "config.h" @@ -69,80 +71,6 @@ using namespace std; -Keys::t_actionstr Keys::m_actionlist[] = { - {"Minimize", ICONIFY}, - {"Raise", RAISE}, - {"Lower", LOWER}, - {"RaiseLayer", RAISELAYER}, - {"LowerLayer", LOWERLAYER}, - {"TopLayer", TOPLAYER}, - {"BottomLayer", BOTTOMLAYER}, - {"AlwaysOnTop", TOPLAYER}, - {"AlwaysOnBottom", BOTTOMLAYER}, - {"Close", CLOSE}, - {"AbortKeychain", ABORTKEYCHAIN}, - {"Workspace", WORKSPACE}, - {"Workspace1", WORKSPACE1}, - {"Workspace2", WORKSPACE2}, - {"Workspace3", WORKSPACE3}, - {"Workspace4", WORKSPACE4}, - {"Workspace5", WORKSPACE5}, - {"Workspace6", WORKSPACE6}, - {"Workspace7", WORKSPACE7}, - {"Workspace8", WORKSPACE8}, - {"Workspace9", WORKSPACE9}, - {"Workspace10", WORKSPACE10}, - {"Workspace11", WORKSPACE11}, - {"Workspace12", WORKSPACE12}, - {"SendToWorkspace", SENDTOWORKSPACE}, - {"NextWorkspace", NEXTWORKSPACE}, - {"PrevWorkspace", PREVWORKSPACE}, - {"LeftWorkspace", LEFTWORKSPACE}, - {"RightWorkspace", RIGHTWORKSPACE}, - {"KillWindow", KILLWINDOW}, - {"NextWindow", NEXTWINDOW}, - {"PrevWindow", PREVWINDOW}, - {"NextGroup", NEXTGROUP}, - {"PrevGroup", PREVGROUP}, - {"NextTab", NEXTTAB}, - {"PrevTab", PREVTAB}, - {"FirstTab", FIRSTTAB}, - {"LastTab", LASTTAB}, - {"MoveTabPrev", MOVETABPREV}, - {"MoveTabNext", MOVETABNEXT}, - {"AttachLast", ATTACHLAST}, - {"DetachClient", DETACHCLIENT}, - {"FocusUp", FOCUSUP}, - {"FocusDown", FOCUSDOWN}, - {"FocusLeft", FOCUSLEFT}, - {"FocusRight", FOCUSRIGHT}, - {"ShadeWindow", SHADE}, - {"MaximizeWindow", MAXIMIZE}, - {"StickWindow", STICK}, - {"ExecCommand", EXECUTE}, - {"MaximizeVertical", VERTMAX}, - {"MaximizeHorizontal", HORIZMAX}, - {"NudgeRight", NUDGERIGHT}, - {"NudgeLeft", NUDGELEFT}, - {"NudgeUp", NUDGEUP}, - {"NudgeDown", NUDGEDOWN}, - {"BigNudgeRight", BIGNUDGERIGHT}, - {"BigNudgeLeft", BIGNUDGELEFT}, - {"BigNudgeUp", BIGNUDGEUP}, - {"BigNudgeDown", BIGNUDGEDOWN}, - {"HorizontalIncrement", HORIZINC}, - {"VerticalIncrement", VERTINC}, - {"HorizontalDecrement", HORIZDEC}, - {"VerticalDecrement", VERTDEC}, - {"ToggleDecor", TOGGLEDECOR}, - {"ToggleTab", TOGGLETAB}, - {"RootMenu", ROOTMENU}, - {"Reconfigure", RECONFIGURE}, - {"Restart", RESTART}, - {"Quit", QUIT}, - {0, LASTKEYGRAB} -}; - Keys::Keys(const char *filename): m_capslock_mod(0), m_numlock_mod(0), @@ -232,7 +160,7 @@ bool Keys::load(const char *filename) { for (unsigned int argc=0; argckey, current_key->mod, ABORTKEYCHAIN); - - delete current_key; - current_key = 0; - last_key = 0; - break; //break out and read next line - } - - last_key->action = m_actionlist[i].action; - - switch(last_key->action) { - case Keys::RESTART: - case Keys::EXECUTE: { - // skip past the command - const char *str = - FbTk::StringUtil::strcasestr( - linebuffer.c_str(), - getActionStr(last_key->action)) - + strlen(getActionStr(last_key->action)); - - int i=0; - // skip past any trailing whitespace - while (str[i] == ' ' || str[i] == '\t') - ++i; - - last_key->execcommand = str + i; - } break; - case WORKSPACE: - case SENDTOWORKSPACE: - if (argc + 1 < val.size()) - last_key->param = atoi( val[argc+1].c_str()); - else - last_key->param = 0; - break; - case NEXTGROUP: - case PREVGROUP: - if (argc + 1 < val.size()) - last_key->param = atoi( val[argc+1].c_str()) ^ 1; - else - last_key->param = 1; - break; - case NEXTWINDOW: - case PREVWINDOW: - if (argc + 1 < val.size()) - last_key->param = atoi( val[argc+1].c_str()); - else - last_key->param = 0; - break; - case LEFTWORKSPACE: - case RIGHTWORKSPACE: - case NEXTWORKSPACE: - case PREVWORKSPACE: - if (argc + 1 < val.size()) - last_key->param = atoi( val[argc+1].c_str()); - else - last_key->param = 1; - break; - case NUDGERIGHT: - case NUDGELEFT: - case NUDGEUP: - case NUDGEDOWN: - if (argc + 1 < val.size()) - last_key->param = atoi( val[argc+1].c_str()); - else - last_key->param = 2; - break; - default: - break; - } + // +1 to remove the first ':' + last_key->m_command = CommandParser::instance().parseLine(val[argc].c_str() + 1); - //add the keychain to list + if (*last_key->m_command == 0) { + cerr<<"File: "< "<keylist.empty()) { - for (unsigned int i=0; ikeylist.size(); i++) { - cerr<<"( "<<(int)key->key<<" "<<(int)key->mod<<" )"; - showKeyTree(key->keylist[i], 4); - cerr<key<<" "<<(int)key->mod<<" ) {"<action)<<"}"<mod == newtree->mod && m_keylist[baselist_i]->key == newtree->key) { - if (newtree->keylist.size() && m_keylist[baselist_i]->action == LASTKEYGRAB) { + if (newtree->keylist.size() && *m_keylist[baselist_i]->m_command == 0) { //assumes the newtree only have one branch return mergeTree(newtree->keylist[0], m_keylist[baselist_i]); } else @@ -642,19 +412,16 @@ bool Keys::mergeTree(t_key *newtree, t_key *basetree) { return false; } -Keys::t_key::t_key(unsigned int key_, unsigned int mod_, KeyAction action_) { - action = action_; +Keys::t_key::t_key(unsigned int key_, unsigned int mod_, FbTk::RefCount command) { key = key_; mod = mod_; - param = 0; + m_command = command; } Keys::t_key::t_key(t_key *k) { - action = k->action; key = k->key; mod = k->mod; - execcommand = k->execcommand; - param = k-> param; + m_command = k->m_command; } Keys::t_key::~t_key() { @@ -665,6 +432,7 @@ Keys::t_key::~t_key() { keylist.pop_back(); } } + } /** diff --git a/src/Keys.hh b/src/Keys.hh index 99bc48d..a296200 100644 --- a/src/Keys.hh +++ b/src/Keys.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Keys.hh,v 1.25 2003/06/15 11:38:35 rathnor Exp $ +// $Id: Keys.hh,v 1.26 2003/06/30 14:57:14 fluxgen Exp $ #ifndef KEYS_HH #define KEYS_HH @@ -29,47 +29,14 @@ #include #include "NotCopyable.hh" +#include "RefCount.hh" +namespace FbTk { +class Command; +}; class Keys:private FbTk::NotCopyable { public: - /** - Key actions - */ - enum KeyAction{ - ICONIFY=0, - RAISE, LOWER, - RAISELAYER, LOWERLAYER, TOPLAYER, BOTTOMLAYER, - ALWAYSONTOP, ALWAYSONBOTTOM, // aliases for TOPLAYER, etc - CLOSE, - ABORTKEYCHAIN, - WORKSPACE, - WORKSPACE1, WORKSPACE2, WORKSPACE3, WORKSPACE4, - WORKSPACE5, WORKSPACE6, WORKSPACE7, WORKSPACE8, - WORKSPACE9, WORKSPACE10, WORKSPACE11, WORKSPACE12, - SENDTOWORKSPACE, // Send window to a workspace - NEXTWORKSPACE, PREVWORKSPACE, - LEFTWORKSPACE, RIGHTWORKSPACE, - KILLWINDOW, NEXTWINDOW, PREVWINDOW, - NEXTGROUP, PREVGROUP, - NEXTTAB, PREVTAB, FIRSTTAB, LASTTAB, MOVETABPREV, MOVETABNEXT, - ATTACHLAST, DETACHCLIENT, - FOCUSUP, FOCUSDOWN, FOCUSLEFT, FOCUSRIGHT, - SHADE, MAXIMIZE, - STICK, // Make Sticky - EXECUTE, // Run command - VERTMAX, // Maximize vertical - HORIZMAX, // Maximize horizontal - NUDGERIGHT, NUDGELEFT,NUDGEUP, NUDGEDOWN, - BIGNUDGERIGHT, BIGNUDGELEFT, BIGNUDGEUP, BIGNUDGEDOWN, - HORIZINC, VERTINC, HORIZDEC, VERTDEC, - TOGGLEDECOR,// toggle visibility of decor (title, frame, handles) - TOGGLETAB, // toggle visibilty of tab - ROOTMENU, // pop up rootmenu - RECONFIGURE, // reload configuration - RESTART, // restart fluxbox - QUIT, // Die, quit, logout, shutdown - LASTKEYGRAB //mark end of keygrabbs - }; + /** Constructor @param display display connection @@ -96,29 +63,14 @@ public: */ bool load(const char *filename=0); /** - Determine action from XKeyEvent - @return KeyAction value + do action from XKeyEvent */ - KeyAction getAction(XKeyEvent *ke); + void doAction(XKeyEvent &ke); /** Reload configuration from filename @return true on success, else false */ bool reconfigure(const char *filename); - /** - Get string value of the KeyAction enum value - @return string of action - */ - const char *getActionStr(KeyAction action); - /** - Get command to execute (key action EXECUTE/RESTART) - @return string to command - */ - const std::string &getExecCommand() { return m_execcmdstring; } - /** - @return number of parameters - */ - int getParam() const { return m_param; } private: void deleteTree(); @@ -144,7 +96,8 @@ private: class t_key { public: - t_key(unsigned int key, unsigned int mod, KeyAction action_ = Keys::LASTKEYGRAB); + t_key(unsigned int key, unsigned int mod, + FbTk::RefCount command = FbTk::RefCount(0)); t_key(t_key *k); ~t_key(); @@ -155,25 +108,24 @@ private: } return 0; } - inline t_key *find(XKeyEvent *ke) { + inline t_key *find(XKeyEvent &ke) { for (unsigned int i=0; ikey == ke->keycode && keylist[i]->mod == ke->state) + if (keylist[i]->key == ke.keycode && keylist[i]->mod == ke.state) return keylist[i]; } return 0; } - inline bool operator == (XKeyEvent *ke) { - return (mod == ke->state && key == ke->keycode); + inline bool operator == (XKeyEvent &ke) const { + return (mod == ke.state && key == ke.keycode); } - KeyAction action; + FbTk::RefCount m_command; unsigned int key; unsigned int mod; std::vector keylist; - std::string execcommand; - int param; // parameter to comands }; + /** merge two linked list @return true on success, else false @@ -187,15 +139,8 @@ private: void showKeyTree(t_key *key, unsigned int w=0); #endif //DEBUG - struct t_actionstr{ - const char *string; - KeyAction action; - }; - int m_capslock_mod, m_numlock_mod, m_scrolllock_mod; ///< modifiers - static t_actionstr m_actionlist[]; - std::vector m_keylist; t_key *m_abortkey; ///< abortkey for keygrabbing chain std::string m_execcmdstring; ///< copy of the execcommandstring -- cgit v0.11.2