From f9311b1e006728af72698afc4c8d32b955542a2f Mon Sep 17 00:00:00 2001 From: koniu Date: Sat, 23 May 2009 16:56:41 +0100 Subject: [PATCH] hooks: add exit hook Signed-off-by: koniu Signed-off-by: Julien Danjou --- awesome.c | 3 +++ hooks.c | 13 +++++++++++++ luaa.c | 1 + structs.h | 2 ++ 4 files changed, 19 insertions(+) diff --git a/awesome.c b/awesome.c index ec748d368..646facb83 100644 --- a/awesome.c +++ b/awesome.c @@ -63,6 +63,9 @@ awesome_atexit(void) { int screen_nbr, nscreens; + if(globalconf.hooks.exit != LUA_REFNIL) + luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.exit, 0, 0); + a_dbus_cleanup(); /* reparent systray windows, otherwise they may die with their master */ diff --git a/hooks.c b/hooks.c index 1e8b74b7d..af8e51a3b 100644 --- a/hooks.c +++ b/hooks.c @@ -214,6 +214,18 @@ luaA_hooks_timer(lua_State *L) return 1; } +/** Set the function called on awesome exit + * \param L The Lua VM state. + * \return The number of elements pushed on stack. + * \luastack + * \lparam A function to call on awesome exit. + */ +static int +luaA_hooks_exit(lua_State *L) +{ + HANDLE_HOOK(L, globalconf.hooks.exit); +} + #ifdef WITH_DBUS /** Set the function to be called when a D-Bus event is received. * The first argument passed to this function is the type of the message we @@ -249,6 +261,7 @@ const struct luaL_reg awesome_hooks_lib[] = { "tagged", luaA_hooks_tagged }, { "startup_notification", luaA_hooks_startup_notification }, { "timer", luaA_hooks_timer }, + { "exit", luaA_hooks_exit }, #ifdef WITH_DBUS { "dbus", luaA_hooks_dbus }, #endif diff --git a/luaa.c b/luaa.c index e07b63b85..062fce611 100644 --- a/luaa.c +++ b/luaa.c @@ -743,6 +743,7 @@ luaA_init(xdgHandle* xdg) globalconf.hooks.property = LUA_REFNIL; globalconf.hooks.startup_notification = LUA_REFNIL; globalconf.hooks.timer = LUA_REFNIL; + globalconf.hooks.exit = LUA_REFNIL; #ifdef WITH_DBUS globalconf.hooks.dbus = LUA_REFNIL; #endif diff --git a/structs.h b/structs.h index 45195e9ff..a27fb2b87 100644 --- a/structs.h +++ b/structs.h @@ -122,6 +122,8 @@ struct awesome_t luaA_ref property; /** Command to run on time */ luaA_ref timer; + /** Command to run on awesome exit */ + luaA_ref exit; /** Startup notification hooks */ luaA_ref startup_notification; #ifdef WITH_DBUS