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 b148b97..5667854 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);
@@ -415,6 +420,18 @@ Keys::~Keys() {
415 delete m_reloader; 420 delete m_reloader;
416} 421}
417 422
423int Keys::setKeyModeWrapper(lua::state *l) {
424 try {
425 l->checkargno(1);
426 const RefKey &k = *l->checkudata<RefKey>(1, keymode_metatable);
427 Fluxbox::instance()->keys()->setKeyMode(k);
428 }
429 catch(std::runtime_error &e) {
430 cerr << "activate: " << e.what() << endl;
431 }
432 return 0;
433}
434
418/// Destroys the keytree 435/// Destroys the keytree
419void Keys::deleteTree() { 436void Keys::deleteTree() {
420 437
@@ -503,9 +520,12 @@ void Keys::reload() {
503 lua::stack_sentry s(l); 520 lua::stack_sentry s(l);
504 521
505 deleteTree(); 522 deleteTree();
523
506 l.getglobal(default_keymode); 524 l.getglobal(default_keymode);
507 assert(l.isuserdata(-1)); 525 assert(l.isuserdata(-1));
508 RefKey t = *static_cast<RefKey *>(l.touserdata(-1)); 526 RefKey t = *static_cast<RefKey *>(l.touserdata(-1)) = RefKey(new t_key);
527 l.pop();
528
509 next_key.reset(); 529 next_key.reset();
510 saved_keymode.reset(); 530 saved_keymode.reset();
511 531
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);