/** Grab the mouse pointer and list motions, calling callback function at each * motion. The callback function must return a boolean value: true to * continue grabbing, false to stop. * The function is called with one argument: * a table containing modifiers pointer coordinates. * * \param L The Lua VM state. * \return The number of elements pushed on stack. * * \luastack * * \lparam A callback function as described above. */ static int luaA_mousegrabber_run(lua_State *L) { if(globalconf.mousegrabber != LUA_REFNIL) luaL_error(L, "mousegrabber already running"); uint16_t cfont = xcursor_font_fromstr(luaL_checkstring(L, 2)); if(cfont) { xcb_cursor_t cursor = xcursor_new(globalconf.display, cfont); luaA_registerfct(L, 1, &globalconf.mousegrabber); if(!mousegrabber_grab(cursor)) { luaA_unregister(L, &globalconf.mousegrabber); luaL_error(L, "unable to grab mouse pointer"); } } else luaA_warn(L, "invalid cursor"); return 0; }
/** Define a global key binding. This key binding will always be available. * \param L The Lua VM state. * * \luastack * \lparam A table with modifier keys. * \lparam A key name. * \lparam A function to execute. * \lreturn The keybinding. */ static int luaA_keybinding_new(lua_State *L) { size_t i, len; keybinding_t *k; const char *key; /* arg 2 is key mod table */ luaA_checktable(L, 2); /* arg 3 is key */ key = luaL_checklstring(L, 3, &len); /* arg 4 is cmd to run */ luaA_checkfunction(L, 4); /* get the last arg as function */ k = p_new(keybinding_t, 1); luaA_keystore(k, key, len); luaA_registerfct(L, 4, &k->fct); len = lua_objlen(L, 2); for(i = 1; i <= len; i++) { size_t blen; lua_rawgeti(L, 2, i); key = luaL_checklstring(L, -1, &blen); k->mod |= xutil_key_mask_fromstr(key, blen); } return luaA_keybinding_userdata_new(L, k); }
/** Grab keyboard and read pressed keys, calling callback function at each key * pressed. The callback function must return a boolean value: true to * continue grabbing, false to stop. * The function is called with 2 arguments: * a table containing modifiers keys and a string, the key pressed. * * \param L The Lua VM state. * \return The number of elements pushed on stack. * * \luastack * * \lparam A callback function as described above. */ static int luaA_keygrabber_run(lua_State *L) { if(globalconf.keygrabber != LUA_REFNIL) luaL_error(L, "keygrabber already running"); luaA_registerfct(L, 1, &globalconf.keygrabber); if(!keygrabber_grab()) { luaA_unregister(L, &globalconf.keygrabber); luaL_error(L, "unable to grab keyboard"); } return 0; }
/** Set the function to be called every N seconds. * \param L The Lua VM state. * \return The number of elements pushed on stack. * \luastack * \lparam The number of seconds to run function every. Set 0 to disable. * \lparam A function to call every N seconds (optional). */ static int luaA_hooks_timer(lua_State *L) { if(lua_gettop(L) >= 1) { globalconf.timer.repeat = luaL_checknumber(L, 1); if(lua_gettop(L) == 2 && !lua_isnil(L, 2)) luaA_registerfct(L, 2, &globalconf.hooks.timer); ev_timer_again(globalconf.loop, &globalconf.timer); } lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.hooks.timer); return 1; }