src/Keys.hh (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
// Keys.hh for Fluxbox - an X11 Window manager // Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen at linuxmail.org) // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // $Id: Keys.hh,v 1.24 2003/06/08 14:32:28 rathnor Exp $ #ifndef KEYS_HH #define KEYS_HH #include <string> #include <vector> #include <X11/Xlib.h> #include "NotCopyable.hh" 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, 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 @param filename file to load, default none */ explicit Keys(const char *filename=0); /// destructor ~Keys(); /** Strip out modifiers we want to ignore @return the cleaned state number */ static unsigned int cleanMods(unsigned int mods) //remove numlock, capslock and scrolllock { return mods & (~Mod2Mask & ~Mod5Mask & ~LockMask);} unsigned int keycodeToModmask(unsigned int keycode); void loadModmap(); /** Load configuration from file @return true on success, else false */ bool load(const char *filename=0); /** Determine action from XKeyEvent @return KeyAction value */ KeyAction getAction(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(); void ungrabKeys(); void bindKey(unsigned int key, unsigned int mod); /** @param modstr modifier string (i.e Mod4, Mod5) @return modifier number that match modstr */ unsigned int getModifier(const char *modstr); /** @param keystr a key string (i.e F1, Enter) @return key number that match keystr */ unsigned int getKey(const char *keystr); /** grab a key @param key the key @param mod the modifier */ void grabKey(unsigned int key, unsigned int mod); std::string filename; class t_key { public: t_key(unsigned int key, unsigned int mod, KeyAction action_ = Keys::LASTKEYGRAB); t_key(t_key *k); ~t_key(); inline t_key *find(unsigned int key_, unsigned int mod_) { for (unsigned int i=0; i<keylist.size(); i++) { if (keylist[i]->key == key_ && keylist[i]->mod == mod_) return keylist[i]; } return 0; } inline t_key *find(XKeyEvent *ke) { for (unsigned int i=0; i<keylist.size(); i++) { 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); } KeyAction action; unsigned int key; unsigned int mod; std::vector<t_key *> keylist; std::string execcommand; int param; // parameter to comands }; /** merge two linked list @return true on success, else false */ bool mergeTree(t_key *newtree, t_key *basetree=0); #ifdef DEBUG /// debug function void showTree(); /// debug function 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<t_key *> m_keylist; t_key *m_abortkey; ///< abortkey for keygrabbing chain std::string m_execcmdstring; ///< copy of the execcommandstring int m_param; ///< copy of the param argument Display *m_display; ///< display connection XModifierKeymap *m_modmap; // Modifier->keycode mapping }; #endif // _KEYS_HH_ |