diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Keys.cc | 56 | ||||
-rw-r--r-- | src/Keys.hh | 6 |
2 files changed, 44 insertions, 18 deletions
diff --git a/src/Keys.cc b/src/Keys.cc index 6becfa2..7b927ca 100644 --- a/src/Keys.cc +++ b/src/Keys.cc | |||
@@ -145,6 +145,7 @@ public: | |||
145 | 145 | ||
146 | static void initKeys(FbTk::Lua &l); | 146 | static void initKeys(FbTk::Lua &l); |
147 | static int addBindingWrapper(lua::state *l); | 147 | static int addBindingWrapper(lua::state *l); |
148 | static int newKeyMode(lua::state *l); | ||
148 | 149 | ||
149 | // constructor / destructor | 150 | // constructor / destructor |
150 | t_key(int type = 0, unsigned int mod = 0, unsigned int key = 0, int context = 0, | 151 | t_key(int type = 0, unsigned int mod = 0, unsigned int key = 0, int context = 0, |
@@ -197,18 +198,9 @@ int Keys::t_key::addBindingWrapper(lua::state *l) | |||
197 | l->checkstack(2); | 198 | l->checkstack(2); |
198 | 199 | ||
199 | try { | 200 | try { |
200 | if(l->gettop() != 3) { | 201 | l->checkargno(3); |
201 | throw KeyError(_FB_CONSOLETEXT(Keys, WrongArgNo, "Wrong number of arguments.", | ||
202 | "Wrong number of arguments to a function")); | ||
203 | } | ||
204 | 202 | ||
205 | l->getmetatable(1); l->rawgetfield(lua::REGISTRYINDEX, keymode_metatable); { | 203 | const RefKey &k = *l->checkudata<RefKey>(1, keymode_metatable); |
206 | if(! l->rawequal(-1, -2)) { | ||
207 | throw KeyError(_FB_CONSOLETEXT(Keys, Bad1stArg, "1st argument is not a keymode.", | ||
208 | "1st argument is not a keymode.")); | ||
209 | } | ||
210 | } l->pop(2); | ||
211 | const RefKey &k = *static_cast<RefKey *>(l->touserdata(1)); | ||
212 | 204 | ||
213 | if(! l->isstring(2)) { | 205 | if(! l->isstring(2)) { |
214 | throw KeyError(_FB_CONSOLETEXT(Keys, Bad2ndArg, "2nd argument is not a string.", | 206 | throw KeyError(_FB_CONSOLETEXT(Keys, Bad2ndArg, "2nd argument is not a string.", |
@@ -238,24 +230,37 @@ int Keys::t_key::addBindingWrapper(lua::state *l) | |||
238 | return 0; | 230 | return 0; |
239 | } | 231 | } |
240 | 232 | ||
233 | int Keys::t_key::newKeyMode(lua::state *l) { | ||
234 | l->checkstack(2); | ||
235 | |||
236 | l->createuserdata<RefKey>(new t_key()); { | ||
237 | l->rawgetfield(lua::REGISTRYINDEX, keymode_metatable); | ||
238 | l->setmetatable(-2); | ||
239 | } return 1; | ||
240 | } | ||
241 | |||
241 | void Keys::t_key::initKeys(FbTk::Lua &l) { | 242 | void Keys::t_key::initKeys(FbTk::Lua &l) { |
242 | l.checkstack(3); | 243 | l.checkstack(3); |
243 | lua::stack_sentry s(l); | 244 | lua::stack_sentry s(l); |
244 | 245 | ||
245 | l.newtable(); { | 246 | l.newmetatable(keymode_metatable); { |
246 | l.pushdestructor<RefKey>(); | 247 | l.pushdestructor<RefKey>(); |
247 | l.rawsetfield(-2, "__gc"); | 248 | l.rawsetfield(-2, "__gc"); |
248 | 249 | ||
249 | l.newtable(); { | 250 | l.newtable(); { |
250 | l.pushfunction(&addBindingWrapper); | 251 | l.pushfunction(&addBindingWrapper); |
251 | l.rawsetfield(-2, "addBinding"); | 252 | l.rawsetfield(-2, "addBinding"); |
253 | |||
254 | l.pushfunction(&setKeyModeWrapper); | ||
255 | l.rawsetfield(-2, "activate"); | ||
252 | } l.rawsetfield(-2, "__index"); | 256 | } l.rawsetfield(-2, "__index"); |
253 | } l.rawsetfield(lua::REGISTRYINDEX, keymode_metatable); | 257 | } l.pop(); |
254 | 258 | ||
255 | l.pushstring(default_keymode); l.createuserdata<RefKey>(new t_key()); { | 259 | newKeyMode(&l); |
256 | l.rawgetfield(lua::REGISTRYINDEX, keymode_metatable); | 260 | l.readOnlySetField(lua::GLOBALSINDEX, default_keymode); |
257 | l.setmetatable(-2); | 261 | |
258 | } l.readOnlySet(lua::GLOBALSINDEX); | 262 | l.pushfunction(&newKeyMode); |
263 | l.readOnlySetField(lua::GLOBALSINDEX, "newKeyMode"); | ||
259 | } | 264 | } |
260 | 265 | ||
261 | FbTk::Lua::RegisterInitFunction Keys::t_key::registerInitKeys(&Keys::t_key::initKeys); | 266 | FbTk::Lua::RegisterInitFunction Keys::t_key::registerInitKeys(&Keys::t_key::initKeys); |
@@ -406,6 +411,18 @@ Keys::~Keys() { | |||
406 | delete m_reloader; | 411 | delete m_reloader; |
407 | } | 412 | } |
408 | 413 | ||
414 | int Keys::setKeyModeWrapper(lua::state *l) { | ||
415 | try { | ||
416 | l->checkargno(1); | ||
417 | const RefKey &k = *l->checkudata<RefKey>(1, keymode_metatable); | ||
418 | Fluxbox::instance()->keys()->setKeyMode(k); | ||
419 | } | ||
420 | catch(std::runtime_error &e) { | ||
421 | cerr << "activate: " << e.what() << endl; | ||
422 | } | ||
423 | return 0; | ||
424 | } | ||
425 | |||
409 | /// Destroys the keytree | 426 | /// Destroys the keytree |
410 | void Keys::deleteTree() { | 427 | void Keys::deleteTree() { |
411 | 428 | ||
@@ -494,9 +511,12 @@ void Keys::reload() { | |||
494 | lua::stack_sentry s(l); | 511 | lua::stack_sentry s(l); |
495 | 512 | ||
496 | deleteTree(); | 513 | deleteTree(); |
514 | |||
497 | l.getglobal(default_keymode); | 515 | l.getglobal(default_keymode); |
498 | assert(l.isuserdata(-1)); | 516 | assert(l.isuserdata(-1)); |
499 | RefKey t = *static_cast<RefKey *>(l.touserdata(-1)); | 517 | RefKey t = *static_cast<RefKey *>(l.touserdata(-1)) = RefKey(new t_key); |
518 | l.pop(); | ||
519 | |||
500 | next_key.reset(); | 520 | next_key.reset(); |
501 | saved_keymode.reset(); | 521 | saved_keymode.reset(); |
502 | 522 | ||
diff --git a/src/Keys.hh b/src/Keys.hh index 33aa398..6cff6b6 100644 --- a/src/Keys.hh +++ b/src/Keys.hh | |||
@@ -31,6 +31,10 @@ | |||
31 | 31 | ||
32 | class WinClient; | 32 | class WinClient; |
33 | 33 | ||
34 | namespace lua { | ||
35 | class state; | ||
36 | } | ||
37 | |||
34 | namespace FbTk { | 38 | namespace FbTk { |
35 | class EventHandler; | 39 | class EventHandler; |
36 | class AutoReloadHelper; | 40 | class AutoReloadHelper; |
@@ -90,6 +94,8 @@ private: | |||
90 | typedef std::map<Window, int> WindowMap; | 94 | typedef std::map<Window, int> WindowMap; |
91 | typedef std::map<Window, FbTk::EventHandler*> HandlerMap; | 95 | typedef std::map<Window, FbTk::EventHandler*> HandlerMap; |
92 | 96 | ||
97 | static int setKeyModeWrapper(lua::state *l); | ||
98 | |||
93 | void deleteTree(); | 99 | void deleteTree(); |
94 | 100 | ||
95 | void grabKey(unsigned int key, unsigned int mod); | 101 | void grabKey(unsigned int key, unsigned int mod); |