diff options
Diffstat (limited to 'src/Keys.hh')
-rw-r--r-- | src/Keys.hh | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/Keys.hh b/src/Keys.hh index 6602d49..0365cf8 100644 --- a/src/Keys.hh +++ b/src/Keys.hh | |||
@@ -38,6 +38,21 @@ | |||
38 | class Keys:private FbTk::NotCopyable { | 38 | class Keys:private FbTk::NotCopyable { |
39 | public: | 39 | public: |
40 | 40 | ||
41 | // contexts for events | ||
42 | // it's ok if there is overlap; it will be worked out in t_key::find() | ||
43 | // eventHandlers should submit bitwise-or of contexts the event happened in | ||
44 | enum { | ||
45 | GLOBAL = 0x01, | ||
46 | ON_DESKTOP = 0x02, | ||
47 | ON_TOOLBAR = 0x04, | ||
48 | ON_ICONBUTTON = 0x08, | ||
49 | ON_TITLEBAR = 0x10, | ||
50 | ON_WINDOW = 0x20, | ||
51 | ON_TAB = 0x40, | ||
52 | ON_SLIT = 0x80 | ||
53 | // and so on... | ||
54 | }; | ||
55 | |||
41 | /** | 56 | /** |
42 | Constructor | 57 | Constructor |
43 | @param display display connection | 58 | @param display display connection |
@@ -65,7 +80,7 @@ public: | |||
65 | /** | 80 | /** |
66 | do action from XKeyEvent; return false if not bound to anything | 81 | do action from XKeyEvent; return false if not bound to anything |
67 | */ | 82 | */ |
68 | bool doAction(XKeyEvent &ke); | 83 | bool doAction(int type, unsigned int mods, unsigned int key); |
69 | 84 | ||
70 | /** | 85 | /** |
71 | Reload configuration from filename | 86 | Reload configuration from filename |
@@ -79,6 +94,8 @@ private: | |||
79 | 94 | ||
80 | void grabKey(unsigned int key, unsigned int mod); | 95 | void grabKey(unsigned int key, unsigned int mod); |
81 | void ungrabKeys(); | 96 | void ungrabKeys(); |
97 | void grabButton(unsigned int button, unsigned int mod); | ||
98 | void ungrabButtons(); | ||
82 | 99 | ||
83 | std::string m_filename; | 100 | std::string m_filename; |
84 | 101 | ||
@@ -87,33 +104,27 @@ private: | |||
87 | 104 | ||
88 | class t_key { | 105 | class t_key { |
89 | public: | 106 | public: |
90 | t_key(unsigned int key, unsigned int mod, | 107 | t_key(int type, unsigned int mod, unsigned int key, int context, |
91 | FbTk::RefCount<FbTk::Command> command = FbTk::RefCount<FbTk::Command>(0)); | 108 | FbTk::RefCount<FbTk::Command> command = FbTk::RefCount<FbTk::Command>(0)); |
92 | t_key(t_key *k); | 109 | t_key(t_key *k); |
93 | ~t_key(); | 110 | ~t_key(); |
94 | 111 | ||
95 | t_key *find(unsigned int key_, unsigned int mod_) { | 112 | t_key *find(int type_, unsigned int mod_, unsigned int key_, |
96 | for (size_t i = 0; i < keylist.size(); i++) { | 113 | int context_) { |
97 | if (keylist[i]->key == key_ && keylist[i]->mod == FbTk::KeyUtil::instance().isolateModifierMask(mod_)) | ||
98 | return keylist[i]; | ||
99 | } | ||
100 | return 0; | ||
101 | } | ||
102 | t_key *find(XKeyEvent &ke) { | ||
103 | for (size_t i = 0; i < keylist.size(); i++) { | 114 | for (size_t i = 0; i < keylist.size(); i++) { |
104 | if (keylist[i]->key == ke.keycode && | 115 | if (keylist[i]->type == type_ && keylist[i]->key == key_ && |
105 | keylist[i]->mod == FbTk::KeyUtil::instance().isolateModifierMask(ke.state)) | 116 | (keylist[i]->context & context_) > 0 && keylist[i]->mod == |
117 | FbTk::KeyUtil::instance().isolateModifierMask(mod_)) | ||
106 | return keylist[i]; | 118 | return keylist[i]; |
107 | } | 119 | } |
108 | return 0; | 120 | return 0; |
109 | } | 121 | } |
110 | 122 | ||
111 | bool operator == (XKeyEvent &ke) const { | ||
112 | return (mod == FbTk::KeyUtil::instance().isolateModifierMask(ke.state) && key == ke.keycode); | ||
113 | } | ||
114 | 123 | ||
115 | FbTk::RefCount<FbTk::Command> m_command; | 124 | FbTk::RefCount<FbTk::Command> m_command; |
116 | unsigned int key; | 125 | int context; // ON_TITLEBAR, etc.: bitwise-or of all desired contexts |
126 | int type; // KeyPress or ButtonPress | ||
127 | unsigned int key; // key code or button number | ||
117 | unsigned int mod; | 128 | unsigned int mod; |
118 | keylist_t keylist; | 129 | keylist_t keylist; |
119 | }; | 130 | }; |