diff options
Diffstat (limited to 'src/Keys.hh')
-rw-r--r-- | src/Keys.hh | 202 |
1 files changed, 115 insertions, 87 deletions
diff --git a/src/Keys.hh b/src/Keys.hh index 3b19aaa..efd6331 100644 --- a/src/Keys.hh +++ b/src/Keys.hh | |||
@@ -1,5 +1,5 @@ | |||
1 | // Key2.hh for Fluxbox - an X11 Window manager | 1 | // Keys.hh for Fluxbox - an X11 Window manager |
2 | // Copyright (c) 2001 Henrik Kinnunen (fluxgen@linuxmail.org) | 2 | // Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) |
3 | // | 3 | // |
4 | // Permission is hereby granted, free of charge, to any person obtaining a | 4 | // Permission is hereby granted, free of charge, to any person obtaining a |
5 | // copy of this software and associated documentation files (the "Software"), | 5 | // copy of this software and associated documentation files (the "Software"), |
@@ -18,99 +18,127 @@ | |||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
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 | #ifndef _KEYS_HH_ | 21 | |
22 | #define _KEYS_HH_ | 22 | // $Id: Keys.hh,v 1.27 2003/08/19 16:18:54 fluxgen Exp $ |
23 | |||
24 | #ifndef KEYS_HH | ||
25 | #define KEYS_HH | ||
23 | 26 | ||
24 | #include <string> | 27 | #include <string> |
25 | #include <vector> | 28 | #include <vector> |
26 | 29 | #include <X11/Xlib.h> | |
27 | class Keys | 30 | |
28 | { | 31 | #include "NotCopyable.hh" |
32 | #include "RefCount.hh" | ||
33 | namespace FbTk { | ||
34 | class Command; | ||
35 | }; | ||
36 | |||
37 | class Keys:private FbTk::NotCopyable { | ||
29 | public: | 38 | public: |
30 | enum KeyAction{ | 39 | |
31 | grabIconify=0, | 40 | /** |
32 | grabRaise, | 41 | Constructor |
33 | grabLower, | 42 | @param display display connection |
34 | grabClose, | 43 | @param filename file to load, default none |
35 | grabAbortKeychain, | 44 | */ |
36 | grabWorkspace1, grabWorkspace2, grabWorkspace3, grabWorkspace4, grabWorkspace5, | 45 | explicit Keys(const char *filename=0); |
37 | grabWorkspace6, grabWorkspace7, grabWorkspace8, grabWorkspace9, grabWorkspace10, | 46 | /// destructor |
38 | grabWorkspace11, grabWorkspace12, grabNextWorkspace, grabPrevWorkspace, | 47 | ~Keys(); |
39 | grabLeftWorkspace, grabRightWorkspace, | 48 | |
40 | grabKillWindow, grabNextWindow, grabPrevWindow, | 49 | /** |
41 | grabNextTab, grabPrevTab, | 50 | Strip out modifiers we want to ignore |
42 | grabShade, grabMaximize, grabStick, grabExecute, grabVertMax, | 51 | @return the cleaned state number |
43 | grabHorizMax, grabNudgeRight, grabNudgeLeft,grabNudgeUp, | 52 | */ |
44 | grabNudgeDown, grabBigNudgeRight, grabBigNudgeLeft, | 53 | static unsigned int cleanMods(unsigned int mods) |
45 | grabBigNudgeUp, grabBigNudgeDown, | 54 | //remove numlock, capslock and scrolllock |
46 | grabHorizInc, grabVertInc, grabHorizDec, grabVertDec, | 55 | { return mods & (~s_capslock_mod & ~s_numlock_mod & ~s_scrolllock_mod); } |
47 | grabToggleDecor, | 56 | |
48 | lastKeygrab | 57 | unsigned int keycodeToModmask(unsigned int keycode); |
49 | }; | 58 | void loadModmap(); |
50 | 59 | ||
51 | Keys(char *filename); | 60 | /** |
52 | ~Keys(); | 61 | Load configuration from file |
53 | bool load(char *filename=0); | 62 | @return true on success, else false |
54 | KeyAction getAction(XKeyEvent *ke); | 63 | */ |
55 | bool reconfigure(char *filename); | 64 | bool load(const char *filename=0); |
56 | const char *getActionStr(KeyAction action); | 65 | /** |
57 | std::string getExecCommand() { return m_execcmdstring; } | 66 | do action from XKeyEvent |
67 | */ | ||
68 | void doAction(XKeyEvent &ke); | ||
69 | /** | ||
70 | Reload configuration from filename | ||
71 | @return true on success, else false | ||
72 | */ | ||
73 | bool reconfigure(const char *filename); | ||
74 | |||
58 | private: | 75 | private: |
59 | void deleteTree(); | 76 | void deleteTree(); |
77 | void ungrabKeys(); | ||
78 | void bindKey(unsigned int key, unsigned int mod); | ||
79 | /** | ||
80 | @param modstr modifier string (i.e Mod4, Mod5) | ||
81 | @return modifier number that match modstr | ||
82 | */ | ||
83 | unsigned int getModifier(const char *modstr); | ||
84 | /** | ||
85 | @param keystr a key string (i.e F1, Enter) | ||
86 | @return key number that match keystr | ||
87 | */ | ||
88 | unsigned int getKey(const char *keystr); | ||
89 | /** | ||
90 | grab a key | ||
91 | @param key the key | ||
92 | @param mod the modifier | ||
93 | */ | ||
94 | void grabKey(unsigned int key, unsigned int mod); | ||
95 | std::string filename; | ||
60 | 96 | ||
61 | void bindKey(unsigned int key, unsigned int mod); | 97 | class t_key { |
62 | unsigned int getModifier(char *modstr); | 98 | public: |
63 | unsigned int getKey(char *keystr); | 99 | t_key(unsigned int key, unsigned int mod, |
64 | void grabKey(unsigned int key, unsigned int mod); | 100 | FbTk::RefCount<FbTk::Command> command = FbTk::RefCount<FbTk::Command>(0)); |
65 | std::string filename; | 101 | t_key(t_key *k); |
66 | 102 | ~t_key(); | |
67 | class t_key { | ||
68 | public: | ||
69 | t_key(unsigned int key, unsigned int mod, KeyAction action_ = lastKeygrab); | ||
70 | t_key(t_key *k); | ||
71 | ~t_key(); | ||
72 | 103 | ||
73 | inline t_key *find(unsigned int key_, unsigned int mod_) { | 104 | inline t_key *find(unsigned int key_, unsigned int mod_) { |
74 | for (unsigned int i=0; i<keylist.size(); i++) { | 105 | for (unsigned int i=0; i<keylist.size(); i++) { |
75 | if (keylist[i]->key == key_ && keylist[i]->mod == mod_) | 106 | if (keylist[i]->key == key_ && keylist[i]->mod == mod_) |
76 | return keylist[i]; | 107 | return keylist[i]; |
77 | } | 108 | } |
78 | return 0; | 109 | return 0; |
79 | } | 110 | } |
80 | inline t_key *find(XKeyEvent *ke) { | 111 | inline t_key *find(XKeyEvent &ke) { |
81 | for (unsigned int i=0; i<keylist.size(); i++) { | 112 | for (unsigned int i=0; i<keylist.size(); i++) { |
82 | if (keylist[i]->key == ke->keycode && keylist[i]->mod == ke->state) | 113 | if (keylist[i]->key == ke.keycode && keylist[i]->mod == ke.state) |
83 | return keylist[i]; | 114 | return keylist[i]; |
84 | } | 115 | } |
85 | return 0; | 116 | return 0; |
86 | } | 117 | } |
87 | 118 | ||
88 | inline bool operator == (XKeyEvent *ke) { | 119 | inline bool operator == (XKeyEvent &ke) const { |
89 | return (mod == ke->state && key == ke->keycode); | 120 | return (mod == ke.state && key == ke.keycode); |
90 | } | 121 | } |
91 | 122 | ||
92 | KeyAction action; | 123 | FbTk::RefCount<FbTk::Command> m_command; |
93 | unsigned int key; | 124 | unsigned int key; |
94 | unsigned int mod; | 125 | unsigned int mod; |
95 | std::vector<t_key *> keylist; | 126 | std::vector<t_key *> keylist; |
96 | std::string execcommand; | 127 | }; |
97 | }; | 128 | |
98 | 129 | /** | |
99 | bool mergeTree(t_key *newtree, t_key *basetree=0); | 130 | merge two linked list |
100 | #ifdef DEBUG | 131 | @return true on success, else false |
101 | //debug functions | 132 | */ |
102 | void showTree(); | 133 | bool mergeTree(t_key *newtree, t_key *basetree=0); |
103 | void showKeyTree(t_key *key, unsigned int w=0); | 134 | |
104 | #endif //DEBUG | 135 | static int s_capslock_mod, s_numlock_mod, s_scrolllock_mod; ///< modifiers |
105 | struct t_actionstr{ | 136 | |
106 | const char *string; | 137 | std::vector<t_key *> m_keylist; |
107 | KeyAction action; | 138 | std::string m_execcmdstring; ///< copy of the execcommandstring |
108 | }; | 139 | int m_param; ///< copy of the param argument |
109 | static t_actionstr m_actionlist[]; | 140 | Display *m_display; ///< display connection |
110 | 141 | XModifierKeymap *m_modmap; ///< Modifier->keycode mapping | |
111 | std::vector<t_key *> m_keylist; | ||
112 | t_key *m_abortkey; //abortkey for keygrabbing chain | ||
113 | std::string m_execcmdstring; //copy of the execcommandstring | ||
114 | }; | 142 | }; |
115 | 143 | ||
116 | #endif // _KEYS_HH_ | 144 | #endif // KEYS_HH |