00001
00002
00003
00004
00005
00006
00007 #ifndef __BINDER_H
00008 #define __BINDER_H
00009
00010 #include "singleton.h"
00011
00012 extern "C" {
00013 #include <X11/Xlib.h>
00014 }
00015
00016 #include <list>
00017 #include <map>
00018 #include <set>
00019
00020 #ifdef POSIX_REGEX
00021 #include <stack>
00022 #include "logger.h"
00023 #include <regex.h>
00024 #endif
00025
00026 #include <string>
00027 #include "ncwm.h"
00028
00029
00030 class Action;
00031 class Binder;
00032 class Group;
00033 class Kernel;
00034 class Shortcut;
00035
00036 typedef set<string> Sstring;
00037 typedef map<string, Action *, less<string> > MBindings;
00038 typedef list<Action *> LAction;
00039
00043 class Binder : public Singleton<Binder>
00044 {
00045
00046 public:
00047
00049 Binder();
00050
00051 ~Binder();
00052
00054 void initKeys(Window window);
00055
00057 void handleKey(Window window, XKeyEvent *e);
00058
00060 void handleButton(Window window, XButtonEvent *e);
00061
00063 void grabShortcut(Shortcut *shortcut, Window window);
00064
00066 void ungrabShortcut(Shortcut *shortcut, Window window);
00067
00069 void grabButtons(Window window, unsigned long modMask);
00070
00072 void ungrabButtons(Window window);
00073
00075 string prettyPrintKeyBindings();
00076
00083 string queryActionKeysForPattern(string pattern, Sstring *actionKeys);
00084
00086 string queryActionKeysWithoutValidationForPattern(string pattern,
00087 Sstring *actionKeys);
00088
00089
00091 string queryExternChainActionsForPattern(
00092 string pattern, Sstring *actionKeys);
00093
00100 string queryCommandForPattern(string pattern, Sstring *expands);
00101
00108 string queryWorkspacesForPattern(string pattern, Sstring *workspaces);
00109
00116 string queryMonitorsForPattern(string pattern, Sstring *monitors);
00117
00124 string queryClientsForPattern(string pattern, Sstring *clients);
00125
00132 string queryDetachedClientsForPattern(string pattern, Sstring *clients);
00133
00135 string queryClientIdsForPattern(string pattern, Sstring *clients);
00136
00143 string queryFramesForPattern(string pattern, Sstring *sFrames);
00144
00145 unsigned int validModMask() const;
00146
00147 #ifdef POSIX_REGEX
00148 string popRegexPattern(){
00149 string result;
00150 if (!regexPattern_.empty()) regexPattern_.pop();
00151 if (regexPattern_.empty()){
00152 result = "";
00153 }else{
00154 result = regexPattern_.top();
00155 }
00156
00157 return result;
00158 }
00159
00160 void pushRegexPattern(string pattern){
00161 regexPattern_.push(pattern);
00162
00163 stack<string> temp = regexPattern_;
00164 string res;
00165 while (!temp.empty()){
00166 res= res + temp.top() + " --- " ;
00167 temp.pop();
00168 }
00169 LOGDEBUG("STACK: " + res);
00170
00171 }
00172 void clearRegexPattern(){
00173 while (!regexPattern_.empty()) regexPattern_.pop();
00174 }
00175 #endif
00176
00177 private:
00178
00180 void handleShortcut(Window window, unsigned long modMask,
00181 KeyCode keyCode, unsigned int button);
00182
00185 void handleShortcutChains(Window window, Shortcut *prefix,
00186 LAction *grabbedActions);
00188 void nextKeystroke(unsigned long *modMask, KeyCode *keyCode);
00189
00191 void emulateKeyPress(unsigned long modMask, KeyCode keyCode);
00192
00194 void initLockModifiers();
00195
00200 string absolutePattern(string pattern, Sstring *names, unsigned int offset);
00201
00209 void matchPattern(string digest, string pattern, Sstring *strings,
00210 unsigned int patternLength);
00211
00212 void initRegex(string);
00213
00214 #ifdef POSIX_REGEX
00215 bool regex_first_match(const string& pattern, const string& haystack,
00216 int& begin, int& end);
00217 bool regex_match(const string& pattern, const string& haystack);
00218 void regex_prepare(){regcomp(&temp_regex_, "", REG_EXTENDED); temp_pattern_="";}
00219 string temp_pattern_;
00220 regex_t temp_regex_;
00221 bool doRegex_;
00222 stack<string> regexPattern_;
00223 #endif
00224
00225
00226 MBindings *actionBindings_;
00227
00228 unsigned int numLockMask_;
00229 unsigned int scrollLockMask_;
00230 unsigned int validModMask_;
00231 };
00232
00233 #endif // __BINDER_H