root: Add support for setting a miss handler.
This will allow to port some functions from C to Lua, such as supporting `awful.key` directly when setting the buttons.
This commit is contained in:
parent
3aafa64ea7
commit
95500ea71c
6
luaa.c
6
luaa.c
|
@ -80,9 +80,10 @@ extern const struct luaL_Reg awesome_dbus_lib[];
|
||||||
#endif
|
#endif
|
||||||
extern const struct luaL_Reg awesome_keygrabber_lib[];
|
extern const struct luaL_Reg awesome_keygrabber_lib[];
|
||||||
extern const struct luaL_Reg awesome_mousegrabber_lib[];
|
extern const struct luaL_Reg awesome_mousegrabber_lib[];
|
||||||
extern const struct luaL_Reg awesome_root_lib[];
|
|
||||||
extern const struct luaL_Reg awesome_mouse_methods[];
|
extern const struct luaL_Reg awesome_mouse_methods[];
|
||||||
extern const struct luaL_Reg awesome_mouse_meta[];
|
extern const struct luaL_Reg awesome_mouse_meta[];
|
||||||
|
extern const struct luaL_Reg awesome_root_methods[];
|
||||||
|
extern const struct luaL_Reg awesome_root_meta[];
|
||||||
|
|
||||||
/** A call into the Lua code aborted with an error.
|
/** A call into the Lua code aborted with an error.
|
||||||
*
|
*
|
||||||
|
@ -995,8 +996,7 @@ luaA_init(xdgHandle* xdg, string_array_t *searchpath)
|
||||||
setup_awesome_signals(L);
|
setup_awesome_signals(L);
|
||||||
|
|
||||||
/* Export root lib */
|
/* Export root lib */
|
||||||
luaA_registerlib(L, "root", awesome_root_lib);
|
luaA_openlib(L, "root", awesome_root_methods, awesome_root_meta);
|
||||||
lua_pop(L, 1); /* luaA_registerlib() leaves the table on stack */
|
|
||||||
|
|
||||||
#ifdef WITH_DBUS
|
#ifdef WITH_DBUS
|
||||||
/* Export D-Bus lib */
|
/* Export D-Bus lib */
|
||||||
|
|
75
root.c
75
root.c
|
@ -31,6 +31,7 @@
|
||||||
#include "common/xcursor.h"
|
#include "common/xcursor.h"
|
||||||
#include "common/xutil.h"
|
#include "common/xutil.h"
|
||||||
#include "objects/button.h"
|
#include "objects/button.h"
|
||||||
|
#include "common/luaclass.h"
|
||||||
#include "xwindow.h"
|
#include "xwindow.h"
|
||||||
|
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
@ -39,6 +40,10 @@
|
||||||
#include <xcb/xcb_aux.h>
|
#include <xcb/xcb_aux.h>
|
||||||
#include <cairo-xcb.h>
|
#include <cairo-xcb.h>
|
||||||
|
|
||||||
|
static int miss_index_handler = LUA_REFNIL;
|
||||||
|
static int miss_newindex_handler = LUA_REFNIL;
|
||||||
|
static int miss_call_handler = LUA_REFNIL;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
root_set_wallpaper_pixmap(xcb_connection_t *c, xcb_pixmap_t p)
|
root_set_wallpaper_pixmap(xcb_connection_t *c, xcb_pixmap_t p)
|
||||||
{
|
{
|
||||||
|
@ -525,7 +530,62 @@ luaA_root_tags(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct luaL_Reg awesome_root_lib[] =
|
/**
|
||||||
|
* Add a custom call handler.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
luaA_root_set_call_handler(lua_State *L)
|
||||||
|
{
|
||||||
|
return luaA_registerfct(L, 1, &miss_call_handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a custom property handler (getter).
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
luaA_root_set_index_miss_handler(lua_State *L)
|
||||||
|
{
|
||||||
|
return luaA_registerfct(L, 1, &miss_index_handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a custom property handler (setter).
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
luaA_root_set_newindex_miss_handler(lua_State *L)
|
||||||
|
{
|
||||||
|
return luaA_registerfct(L, 1, &miss_newindex_handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Root library.
|
||||||
|
* \param L The Lua VM state.
|
||||||
|
* \return The number of elements pushed on stack.
|
||||||
|
* \luastack
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
luaA_root_index(lua_State *L)
|
||||||
|
{
|
||||||
|
if (miss_index_handler != LUA_REFNIL)
|
||||||
|
return luaA_call_handler(L, miss_index_handler);
|
||||||
|
|
||||||
|
return luaA_default_index(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Newindex for root.
|
||||||
|
* \param L The Lua VM state.
|
||||||
|
* \return The number of elements pushed on stack.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
luaA_root_newindex(lua_State *L)
|
||||||
|
{
|
||||||
|
/* Call the lua root property handler */
|
||||||
|
if (miss_newindex_handler != LUA_REFNIL)
|
||||||
|
return luaA_call_handler(L, miss_newindex_handler);
|
||||||
|
|
||||||
|
return luaA_default_newindex(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct luaL_Reg awesome_root_methods[] =
|
||||||
{
|
{
|
||||||
{ "buttons", luaA_root_buttons },
|
{ "buttons", luaA_root_buttons },
|
||||||
{ "keys", luaA_root_keys },
|
{ "keys", luaA_root_keys },
|
||||||
|
@ -536,8 +596,17 @@ const struct luaL_Reg awesome_root_lib[] =
|
||||||
{ "size", luaA_root_size },
|
{ "size", luaA_root_size },
|
||||||
{ "size_mm", luaA_root_size_mm },
|
{ "size_mm", luaA_root_size_mm },
|
||||||
{ "tags", luaA_root_tags },
|
{ "tags", luaA_root_tags },
|
||||||
{ "__index", luaA_default_index },
|
{ "__index", luaA_root_index },
|
||||||
{ "__newindex", luaA_default_newindex },
|
{ "__newindex", luaA_root_newindex },
|
||||||
|
{ "set_index_miss_handler", luaA_root_set_index_miss_handler},
|
||||||
|
{ "set_call_handler", luaA_root_set_call_handler},
|
||||||
|
{ "set_newindex_miss_handler", luaA_root_set_newindex_miss_handler},
|
||||||
|
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct luaL_Reg awesome_root_meta[] =
|
||||||
|
{
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -174,6 +174,15 @@ function root._write_string(string, c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function root.set_newindex_miss_handler(h)
|
||||||
|
rawset(mouse, "_ni_handler", h)
|
||||||
|
end
|
||||||
|
|
||||||
|
function root.set_index_miss_handler(h)
|
||||||
|
rawset(mouse, "_i_handler", h)
|
||||||
|
end
|
||||||
|
|
||||||
return root
|
return root
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
Loading…
Reference in New Issue