keygrabber: add stop() method
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
4e37a6cde2
commit
ce99ab2a3a
4
event.c
4
event.c
|
@ -496,10 +496,10 @@ event_handle_keypress(void *data __attribute__ ((unused)),
|
||||||
if(lua_pcall(globalconf.L, 2, 1, 0))
|
if(lua_pcall(globalconf.L, 2, 1, 0))
|
||||||
{
|
{
|
||||||
warn("error running function: %s", lua_tostring(globalconf.L, -1));
|
warn("error running function: %s", lua_tostring(globalconf.L, -1));
|
||||||
keygrabber_ungrab();
|
luaA_keygrabber_stop(globalconf.L);
|
||||||
}
|
}
|
||||||
else if(!lua_isboolean(globalconf.L, -1) || !lua_toboolean(globalconf.L, -1))
|
else if(!lua_isboolean(globalconf.L, -1) || !lua_toboolean(globalconf.L, -1))
|
||||||
keygrabber_ungrab();
|
luaA_keygrabber_stop(globalconf.L);
|
||||||
}
|
}
|
||||||
lua_pop(globalconf.L, 1); /* pop returned value or function if not called */
|
lua_pop(globalconf.L, 1); /* pop returned value or function if not called */
|
||||||
}
|
}
|
||||||
|
|
33
keygrabber.c
33
keygrabber.c
|
@ -639,16 +639,6 @@ keygrabber_grab(void)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Ungrab the keyboard.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
keygrabber_ungrab(void)
|
|
||||||
{
|
|
||||||
xcb_ungrab_keyboard(globalconf.connection, XCB_CURRENT_TIME);
|
|
||||||
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, globalconf.keygrabber);
|
|
||||||
globalconf.keygrabber = LUA_REFNIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Handle keypress event.
|
/** Handle keypress event.
|
||||||
* \param L Lua stack to push the key pressed.
|
* \param L Lua stack to push the key pressed.
|
||||||
* \param e Received XKeyEvent.
|
* \param e Received XKeyEvent.
|
||||||
|
@ -701,6 +691,7 @@ keygrabber_handlekpress(lua_State *L, xcb_key_press_event_t *e)
|
||||||
* a table containing modifiers keys and a string, the key pressed.
|
* a table containing modifiers keys and a string, the key pressed.
|
||||||
*
|
*
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
|
* \return The number of elements pushed on stack.
|
||||||
*
|
*
|
||||||
* \luastack
|
* \luastack
|
||||||
*
|
*
|
||||||
|
@ -712,18 +703,32 @@ luaA_keygrabber_run(lua_State *L)
|
||||||
if(globalconf.keygrabber != LUA_REFNIL)
|
if(globalconf.keygrabber != LUA_REFNIL)
|
||||||
luaL_error(L, "keygrabber already running");
|
luaL_error(L, "keygrabber already running");
|
||||||
|
|
||||||
luaA_checkfunction(L, 1);
|
luaA_registerfct(L, 1, &globalconf.keygrabber);
|
||||||
|
|
||||||
globalconf.keygrabber = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
||||||
|
|
||||||
if(!keygrabber_grab())
|
if(!keygrabber_grab())
|
||||||
|
{
|
||||||
|
luaA_unregister(L, &globalconf.keygrabber);
|
||||||
luaL_error(L, "unable to grab keyboard");
|
luaL_error(L, "unable to grab keyboard");
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Stop grabbing the keyboard.
|
||||||
|
* \param L The Lua VM state.
|
||||||
|
* \return The number of elements pushed on stack.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
luaA_keygrabber_stop(lua_State *L)
|
||||||
|
{
|
||||||
|
xcb_ungrab_keyboard(globalconf.connection, XCB_CURRENT_TIME);
|
||||||
|
luaA_unregister(L, &globalconf.keygrabber);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const struct luaL_reg awesome_keygrabber_lib[] =
|
const struct luaL_reg awesome_keygrabber_lib[] =
|
||||||
{
|
{
|
||||||
{"run", luaA_keygrabber_run },
|
{ "run", luaA_keygrabber_run },
|
||||||
|
{ "stop", luaA_keygrabber_stop },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
|
|
||||||
void keygrabber_ungrab(void);
|
int luaA_keygrabber_stop(lua_State *);
|
||||||
bool keygrabber_handlekpress(lua_State *L, xcb_key_press_event_t *);
|
bool keygrabber_handlekpress(lua_State *, xcb_key_press_event_t *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
Loading…
Reference in New Issue