aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Keys.cc56
-rw-r--r--src/Keys.hh6
2 files changed, 44 insertions, 18 deletions
diff --git a/src/Keys.cc b/src/Keys.cc
index 3a9c41d..f2b2bb4 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, 151 t_key(int type = 0, unsigned int mod = 0, unsigned int key = 0,
@@ -199,18 +200,9 @@ int Keys::t_key::addBindingWrapper(lua::state *l)
199 l->checkstack(2); 200 l->checkstack(2);
200 201
201 try { 202 try {
202 if(l->gettop() != 3) { 203 l->checkargno(3);
203 throw KeyError(_FB_CONSOLETEXT(Keys, WrongArgNo, "Wrong number of arguments.",
204 "Wrong number of arguments to a function"));
205 }
206 204
207 l->getmetatable(1); l->rawgetfield(lua::REGISTRYINDEX, keymode_metatable); { 205 const RefKey &k = *l->checkudata<RefKey>(1, keymode_metatable);
208 if(! l->rawequal(-1, -2)) {
209 throw KeyError(_FB_CONSOLETEXT(Keys, Bad1stArg, "1st argument is not a keymode.",
210 "1st argument is not a keymode."));
211 }
212 } l->pop(2);
213 const RefKey &k = *static_cast<RefKey *>(l->touserdata(1));
214 206
215 if(! l->isstring(2)) { 207 if(! l->isstring(2)) {
216 throw KeyError(_FB_CONSOLETEXT(Keys, Bad2ndArg, "2nd argument is not a string.", 208 throw KeyError(_FB_CONSOLETEXT(Keys, Bad2ndArg, "2nd argument is not a string.",
@@ -240,24 +232,37 @@ int Keys::t_key::addBindingWrapper(lua::state *l)
240 return 0; 232 return 0;
241} 233}
242 234
235int Keys::t_key::newKeyMode(lua::state *l) {
236 l->checkstack(2);
237
238 l->createuserdata<RefKey>(new t_key()); {
239 l->rawgetfield(lua::REGISTRYINDEX, keymode_metatable);
240 l->setmetatable(-2);
241 } return 1;
242}
243
243void Keys::t_key::initKeys(FbTk::Lua &l) { 244void Keys::t_key::initKeys(FbTk::Lua &l) {
244 l.checkstack(3); 245 l.checkstack(3);
245 lua::stack_sentry s(l); 246 lua::stack_sentry s(l);
246 247
247 l.newtable(); { 248 l.newmetatable(keymode_metatable); {
248 l.pushdestructor<RefKey>(); 249 l.pushdestructor<RefKey>();
249 l.rawsetfield(-2, "__gc"); 250 l.rawsetfield(-2, "__gc");
250 251
251 l.newtable(); { 252 l.newtable(); {
252 l.pushfunction(&addBindingWrapper); 253 l.pushfunction(&addBindingWrapper);
253 l.rawsetfield(-2, "addBinding"); 254 l.rawsetfield(-2, "addBinding");
255
256 l.pushfunction(&setKeyModeWrapper);
257 l.rawsetfield(-2, "activate");
254 } l.rawsetfield(-2, "__index"); 258 } l.rawsetfield(-2, "__index");
255 } l.rawsetfield(lua::REGISTRYINDEX, keymode_metatable); 259 } l.pop();
256 260
257 l.pushstring(default_keymode); l.createuserdata<RefKey>(new t_key()); { 261 newKeyMode(&l);
258 l.rawgetfield(lua::REGISTRYINDEX, keymode_metatable); 262 l.readOnlySetField(lua::GLOBALSINDEX, default_keymode);
259 l.setmetatable(-2); 263
260 } l.readOnlySet(lua::GLOBALSINDEX); 264 l.pushfunction(&newKeyMode);
265 l.readOnlySetField(lua::GLOBALSINDEX, "newKeyMode");
261} 266}
262 267
263FbTk::Lua::RegisterInitFunction Keys::t_key::registerInitKeys(&Keys::t_key::initKeys); 268FbTk::Lua::RegisterInitFunction Keys::t_key::registerInitKeys(&Keys::t_key::initKeys);
@@ -413,6 +418,18 @@ Keys::~Keys() {
413 delete m_reloader; 418 delete m_reloader;
414} 419}
415 420
421int Keys::setKeyModeWrapper(lua::state *l) {
422 try {
423 l->checkargno(1);
424 const RefKey &k = *l->checkudata<RefKey>(1, keymode_metatable);
425 Fluxbox::instance()->keys()->setKeyMode(k);
426 }
427 catch(std::runtime_error &e) {
428 cerr << "activate: " << e.what() << endl;
429 }
430 return 0;
431}
432
416/// Destroys the keytree 433/// Destroys the keytree
417void Keys::deleteTree() { 434void Keys::deleteTree() {
418 435
@@ -501,9 +518,12 @@ void Keys::reload() {
501 lua::stack_sentry s(l); 518 lua::stack_sentry s(l);
502 519
503 deleteTree(); 520 deleteTree();
521
504 l.getglobal(default_keymode); 522 l.getglobal(default_keymode);
505 assert(l.isuserdata(-1)); 523 assert(l.isuserdata(-1));
506 RefKey t = *static_cast<RefKey *>(l.touserdata(-1)); 524 RefKey t = *static_cast<RefKey *>(l.touserdata(-1)) = RefKey(new t_key);
525 l.pop();
526
507 next_key.reset(); 527 next_key.reset();
508 saved_keymode.reset(); 528 saved_keymode.reset();
509 529
diff --git a/src/Keys.hh b/src/Keys.hh
index 9e31f0e..dfa4539 100644
--- a/src/Keys.hh
+++ b/src/Keys.hh
@@ -32,6 +32,10 @@
32 32
33class WinClient; 33class WinClient;
34 34
35namespace lua {
36 class state;
37}
38
35namespace FbTk { 39namespace FbTk {
36 class EventHandler; 40 class EventHandler;
37 class AutoReloadHelper; 41 class AutoReloadHelper;
@@ -91,6 +95,8 @@ private:
91 typedef std::map<Window, int> WindowMap; 95 typedef std::map<Window, int> WindowMap;
92 typedef std::map<Window, FbTk::EventHandler*> HandlerMap; 96 typedef std::map<Window, FbTk::EventHandler*> HandlerMap;
93 97
98 static int setKeyModeWrapper(lua::state *l);
99
94 void deleteTree(); 100 void deleteTree();
95 101
96 void grabKey(unsigned int key, unsigned int mod); 102 void grabKey(unsigned int key, unsigned int mod);