diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-25 13:44:55 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-07-25 13:44:55 (GMT) |
commit | bac3668d83d90727b81f40b2b57e2f9f8e24454c (patch) | |
tree | 96cd9ed93fadc957f858a06eea743f555f8d1296 /src/Keys.cc | |
parent | 93fe0b36b768a5e681bf5bf0943ba3e98aa12c1d (diff) | |
download | fluxbox_pavel-bac3668d83d90727b81f40b2b57e2f9f8e24454c.zip fluxbox_pavel-bac3668d83d90727b81f40b2b57e2f9f8e24454c.tar.bz2 |
Reintroduce support for multiple keymodes
new keymodes are created (in lua) by calling newKeyMode() and activated by calling
keymode:activate()
Diffstat (limited to 'src/Keys.cc')
-rw-r--r-- | src/Keys.cc | 56 |
1 files changed, 38 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 | ||