aboutsummaryrefslogtreecommitdiff
path: root/src/Keys.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/Keys.hh')
-rw-r--r--src/Keys.hh257
1 files changed, 172 insertions, 85 deletions
diff --git a/src/Keys.hh b/src/Keys.hh
index 3b19aaa..57e826c 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 linuxmail.org)
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,186 @@
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.22 2003/04/15 00:50:24 rathnor 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>
27class Keys 30
28{ 31#include "NotCopyable.hh"
32
33class Keys:private FbTk::NotCopyable {
29public: 34public:
30enum KeyAction{ 35 /**
31 grabIconify=0, 36 Key actions
32 grabRaise, 37 */
33 grabLower, 38 enum KeyAction{
34 grabClose, 39 ICONIFY=0,
35 grabAbortKeychain, 40 RAISE, LOWER,
36 grabWorkspace1, grabWorkspace2, grabWorkspace3, grabWorkspace4, grabWorkspace5, 41 RAISELAYER, LOWERLAYER, TOPLAYER, BOTTOMLAYER,
37 grabWorkspace6, grabWorkspace7, grabWorkspace8, grabWorkspace9, grabWorkspace10, 42 ALWAYSONTOP, ALWAYSONBOTTOM, // aliases for TOPLAYER, etc
38 grabWorkspace11, grabWorkspace12, grabNextWorkspace, grabPrevWorkspace, 43 CLOSE,
39 grabLeftWorkspace, grabRightWorkspace, 44 ABORTKEYCHAIN,
40 grabKillWindow, grabNextWindow, grabPrevWindow, 45 WORKSPACE,
41 grabNextTab, grabPrevTab, 46 WORKSPACE1, WORKSPACE2, WORKSPACE3, WORKSPACE4,
42 grabShade, grabMaximize, grabStick, grabExecute, grabVertMax, 47 WORKSPACE5, WORKSPACE6, WORKSPACE7, WORKSPACE8,
43 grabHorizMax, grabNudgeRight, grabNudgeLeft,grabNudgeUp, 48 WORKSPACE9, WORKSPACE10, WORKSPACE11, WORKSPACE12,
44 grabNudgeDown, grabBigNudgeRight, grabBigNudgeLeft, 49 SENDTOWORKSPACE, // Send window to a workspace
45 grabBigNudgeUp, grabBigNudgeDown, 50 NEXTWORKSPACE, PREVWORKSPACE,
46 grabHorizInc, grabVertInc, grabHorizDec, grabVertDec, 51 LEFTWORKSPACE, RIGHTWORKSPACE,
47 grabToggleDecor, 52 KILLWINDOW, NEXTWINDOW, PREVWINDOW,
48 lastKeygrab 53 NEXTTAB, PREVTAB, FIRSTTAB, LASTTAB, MOVETABPREV, MOVETABNEXT,
49 }; 54 ATTACHLAST, DETACHCLIENT,
50 55 SHADE, MAXIMIZE,
51 Keys(char *filename); 56 STICK, // Make Sticky
52 ~Keys(); 57 EXECUTE, // Run command
53 bool load(char *filename=0); 58 VERTMAX, // Maximize vertical
54 KeyAction getAction(XKeyEvent *ke); 59 HORIZMAX, // Maximize horizontal
55 bool reconfigure(char *filename); 60 NUDGERIGHT, NUDGELEFT,NUDGEUP, NUDGEDOWN,
56 const char *getActionStr(KeyAction action); 61 BIGNUDGERIGHT, BIGNUDGELEFT, BIGNUDGEUP, BIGNUDGEDOWN,
57 std::string getExecCommand() { return m_execcmdstring; } 62 HORIZINC, VERTINC, HORIZDEC, VERTDEC,
63 TOGGLEDECOR,// toggle visibility of decor (title, frame, handles)
64 TOGGLETAB, // toggle visibilty of tab
65 ROOTMENU, // pop up rootmenu
66 QUIT, // Die, quit, logout, shutdown
67 LASTKEYGRAB //mark end of keygrabbs
68 };
69 /**
70 Constructor
71 @param display display connection
72 @param filename file to load, default none
73 */
74 explicit Keys(const char *filename=0);
75 /// destructor
76 ~Keys();
77
78 /**
79 Strip out modifiers we want to ignore
80 @return the cleaned state number
81 */
82 static unsigned int cleanMods(unsigned int mods)
83 //remove numlock, capslock and scrolllock
84 { return mods & (~Mod2Mask & ~Mod5Mask & ~LockMask);}
85
86 unsigned int keycodeToModmask(unsigned int keycode);
87 void loadModmap();
88
89 /**
90 Load configuration from file
91 @return true on success, else false
92 */
93 bool load(const char *filename=0);
94 /**
95 Determine action from XKeyEvent
96 @return KeyAction value
97 */
98 KeyAction getAction(XKeyEvent *ke);
99 /**
100 Reload configuration from filename
101 @return true on success, else false
102 */
103 bool reconfigure(const char *filename);
104 /**
105 Get string value of the KeyAction enum value
106 @return string of action
107 */
108 const char *getActionStr(KeyAction action);
109 /**
110 Get command to execute (key action EXECUTE)
111 @return string to command
112 */
113 const std::string &getExecCommand() { return m_execcmdstring; }
114 /**
115 @return number of parameters
116 */
117 int getParam() const { return m_param; }
118
58private: 119private:
59 void deleteTree(); 120 void deleteTree();
121 void ungrabKeys();
122 void bindKey(unsigned int key, unsigned int mod);
123 /**
124 @param modstr modifier string (i.e Mod4, Mod5)
125 @return modifier number that match modstr
126 */
127 unsigned int getModifier(const char *modstr);
128 /**
129 @param keystr a key string (i.e F1, Enter)
130 @return key number that match keystr
131 */
132 unsigned int getKey(const char *keystr);
133 /**
134 grab a key
135 @param key the key
136 @param mod the modifier
137 */
138 void grabKey(unsigned int key, unsigned int mod);
139 std::string filename;
60 140
61 void bindKey(unsigned int key, unsigned int mod); 141 class t_key {
62 unsigned int getModifier(char *modstr); 142 public:
63 unsigned int getKey(char *keystr); 143 t_key(unsigned int key, unsigned int mod, KeyAction action_ = Keys::LASTKEYGRAB);
64 void grabKey(unsigned int key, unsigned int mod); 144 t_key(t_key *k);
65 std::string filename; 145 ~t_key();
66
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 146
73 inline t_key *find(unsigned int key_, unsigned int mod_) { 147 inline t_key *find(unsigned int key_, unsigned int mod_) {
74 for (unsigned int i=0; i<keylist.size(); i++) { 148 for (unsigned int i=0; i<keylist.size(); i++) {
75 if (keylist[i]->key == key_ && keylist[i]->mod == mod_) 149 if (keylist[i]->key == key_ && keylist[i]->mod == mod_)
76 return keylist[i]; 150 return keylist[i];
77 } 151 }
78 return 0; 152 return 0;
79 } 153 }
80 inline t_key *find(XKeyEvent *ke) { 154 inline t_key *find(XKeyEvent *ke) {
81 for (unsigned int i=0; i<keylist.size(); i++) { 155 for (unsigned int i=0; i<keylist.size(); i++) {
82 if (keylist[i]->key == ke->keycode && keylist[i]->mod == ke->state) 156 if (keylist[i]->key == ke->keycode && keylist[i]->mod == ke->state)
83 return keylist[i]; 157 return keylist[i];
84 } 158 }
85 return 0; 159 return 0;
86 } 160 }
87 161
88 inline bool operator == (XKeyEvent *ke) { 162 inline bool operator == (XKeyEvent *ke) {
89 return (mod == ke->state && key == ke->keycode); 163 return (mod == ke->state && key == ke->keycode);
90 } 164 }
91 165
92 KeyAction action; 166 KeyAction action;
93 unsigned int key; 167 unsigned int key;
94 unsigned int mod; 168 unsigned int mod;
95 std::vector<t_key *> keylist; 169 std::vector<t_key *> keylist;
96 std::string execcommand; 170 std::string execcommand;
97 }; 171 int param; // parameter to comands
98 172 };
99 bool mergeTree(t_key *newtree, t_key *basetree=0); 173 /**
100 #ifdef DEBUG 174 merge two linked list
101 //debug functions 175 @return true on success, else false
102 void showTree(); 176 */
103 void showKeyTree(t_key *key, unsigned int w=0); 177 bool mergeTree(t_key *newtree, t_key *basetree=0);
104 #endif //DEBUG 178
105 struct t_actionstr{ 179#ifdef DEBUG
106 const char *string; 180 /// debug function
107 KeyAction action; 181 void showTree();
108 }; 182 /// debug function
109 static t_actionstr m_actionlist[]; 183 void showKeyTree(t_key *key, unsigned int w=0);
184#endif //DEBUG
185
186 struct t_actionstr{
187 const char *string;
188 KeyAction action;
189 };
190
191 int m_capslock_mod, m_numlock_mod, m_scrolllock_mod; ///< modifiers
192
193 static t_actionstr m_actionlist[];
110 194
111 std::vector<t_key *> m_keylist; 195 std::vector<t_key *> m_keylist;
112 t_key *m_abortkey; //abortkey for keygrabbing chain 196 t_key *m_abortkey; ///< abortkey for keygrabbing chain
113 std::string m_execcmdstring; //copy of the execcommandstring 197 std::string m_execcmdstring; ///< copy of the execcommandstring
198 int m_param; ///< copy of the param argument
199 Display *m_display; ///< display connection
200 XModifierKeymap *m_modmap; // Modifier->keycode mapping
114}; 201};
115 202
116#endif // _KEYS_HH_ 203#endif // _KEYS_HH_