diff options
Diffstat (limited to 'src/Keys.hh')
-rw-r--r-- | src/Keys.hh | 182 |
1 files changed, 95 insertions, 87 deletions
diff --git a/src/Keys.hh b/src/Keys.hh index 3b19aaa..014f5a1 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,107 @@ | |||
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.31 2003/12/20 17:37:20 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 "FbTk/NotCopyable.hh" |
32 | #include "FbTk/RefCount.hh" | ||
33 | #include "FbTk/Command.hh" | ||
34 | |||
35 | class Keys:private FbTk::NotCopyable { | ||
29 | public: | 36 | public: |
30 | enum KeyAction{ | 37 | |
31 | grabIconify=0, | 38 | /** |
32 | grabRaise, | 39 | Constructor |
33 | grabLower, | 40 | @param display display connection |
34 | grabClose, | 41 | @param filename file to load, default none |
35 | grabAbortKeychain, | 42 | */ |
36 | grabWorkspace1, grabWorkspace2, grabWorkspace3, grabWorkspace4, grabWorkspace5, | 43 | explicit Keys(const char *filename=0); |
37 | grabWorkspace6, grabWorkspace7, grabWorkspace8, grabWorkspace9, grabWorkspace10, | 44 | /// destructor |
38 | grabWorkspace11, grabWorkspace12, grabNextWorkspace, grabPrevWorkspace, | 45 | ~Keys(); |
39 | grabLeftWorkspace, grabRightWorkspace, | 46 | |
40 | grabKillWindow, grabNextWindow, grabPrevWindow, | 47 | /** |
41 | grabNextTab, grabPrevTab, | 48 | Load configuration from file |
42 | grabShade, grabMaximize, grabStick, grabExecute, grabVertMax, | 49 | @return true on success, else false |
43 | grabHorizMax, grabNudgeRight, grabNudgeLeft,grabNudgeUp, | 50 | */ |
44 | grabNudgeDown, grabBigNudgeRight, grabBigNudgeLeft, | 51 | bool load(const char *filename = 0); |
45 | grabBigNudgeUp, grabBigNudgeDown, | 52 | /** |
46 | grabHorizInc, grabVertInc, grabHorizDec, grabVertDec, | 53 | Save keybindings to a file |
47 | grabToggleDecor, | 54 | Note: the file will be overwritten |
48 | lastKeygrab | 55 | @return true on success, else false |
49 | }; | 56 | */ |
50 | 57 | bool save(const char *filename = 0) const; | |
51 | Keys(char *filename); | 58 | /// bind a key action from a string |
52 | ~Keys(); | 59 | /// @return false on failure |
53 | bool load(char *filename=0); | 60 | bool addBinding(const std::string &binding); |
54 | KeyAction getAction(XKeyEvent *ke); | 61 | |
55 | bool reconfigure(char *filename); | 62 | /** |
56 | const char *getActionStr(KeyAction action); | 63 | do action from XKeyEvent |
57 | std::string getExecCommand() { return m_execcmdstring; } | 64 | */ |
65 | void doAction(XKeyEvent &ke); | ||
66 | |||
67 | /** | ||
68 | Reload configuration from filename | ||
69 | @return true on success, else false | ||
70 | */ | ||
71 | bool reconfigure(const char *filename); | ||
72 | const std::string filename() const { return m_filename; } | ||
58 | private: | 73 | private: |
59 | void deleteTree(); | 74 | void deleteTree(); |
60 | 75 | ||
61 | void bindKey(unsigned int key, unsigned int mod); | 76 | void bindKey(unsigned int key, unsigned int mod); |
62 | unsigned int getModifier(char *modstr); | 77 | |
63 | unsigned int getKey(char *keystr); | 78 | std::string m_filename; |
64 | void grabKey(unsigned int key, unsigned int mod); | ||
65 | std::string filename; | ||
66 | 79 | ||
67 | class t_key { | 80 | class t_key { |
68 | public: | 81 | public: |
69 | t_key(unsigned int key, unsigned int mod, KeyAction action_ = lastKeygrab); | 82 | t_key(unsigned int key, unsigned int mod, |
70 | t_key(t_key *k); | 83 | FbTk::RefCount<FbTk::Command> command = FbTk::RefCount<FbTk::Command>(0)); |
71 | ~t_key(); | 84 | t_key(t_key *k); |
85 | ~t_key(); | ||
72 | 86 | ||
73 | inline t_key *find(unsigned int key_, unsigned int mod_) { | 87 | inline t_key *find(unsigned int key_, unsigned int mod_) { |
74 | for (unsigned int i=0; i<keylist.size(); i++) { | 88 | for (unsigned int i=0; i<keylist.size(); i++) { |
75 | if (keylist[i]->key == key_ && keylist[i]->mod == mod_) | 89 | if (keylist[i]->key == key_ && keylist[i]->mod == mod_) |
76 | return keylist[i]; | 90 | return keylist[i]; |
77 | } | 91 | } |
78 | return 0; | 92 | return 0; |
79 | } | 93 | } |
80 | inline t_key *find(XKeyEvent *ke) { | 94 | inline t_key *find(XKeyEvent &ke) { |
81 | for (unsigned int i=0; i<keylist.size(); i++) { | 95 | for (unsigned int i=0; i<keylist.size(); i++) { |
82 | if (keylist[i]->key == ke->keycode && keylist[i]->mod == ke->state) | 96 | if (keylist[i]->key == ke.keycode && keylist[i]->mod == ke.state) |
83 | return keylist[i]; | 97 | return keylist[i]; |
84 | } | 98 | } |
85 | return 0; | 99 | return 0; |
86 | } | 100 | } |
87 | 101 | ||
88 | inline bool operator == (XKeyEvent *ke) { | 102 | inline bool operator == (XKeyEvent &ke) const { |
89 | return (mod == ke->state && key == ke->keycode); | 103 | return (mod == ke.state && key == ke.keycode); |
90 | } | 104 | } |
91 | 105 | ||
92 | KeyAction action; | 106 | FbTk::RefCount<FbTk::Command> m_command; |
93 | unsigned int key; | 107 | unsigned int key; |
94 | unsigned int mod; | 108 | unsigned int mod; |
95 | std::vector<t_key *> keylist; | 109 | std::vector<t_key *> keylist; |
96 | std::string execcommand; | 110 | }; |
97 | }; | 111 | |
98 | 112 | /** | |
99 | bool mergeTree(t_key *newtree, t_key *basetree=0); | 113 | merge two linked list |
100 | #ifdef DEBUG | 114 | @return true on success, else false |
101 | //debug functions | 115 | */ |
102 | void showTree(); | 116 | bool mergeTree(t_key *newtree, t_key *basetree=0); |
103 | void showKeyTree(t_key *key, unsigned int w=0); | 117 | |
104 | #endif //DEBUG | 118 | std::vector<t_key *> m_keylist; |
105 | struct t_actionstr{ | 119 | |
106 | const char *string; | 120 | Display *m_display; ///< display connection |
107 | KeyAction action; | 121 | unsigned int m_current_line; |
108 | }; | ||
109 | static t_actionstr m_actionlist[]; | ||
110 | |||
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 | }; | 122 | }; |
115 | 123 | ||
116 | #endif // _KEYS_HH_ | 124 | #endif // KEYS_HH |