and the patch :P
From 625468d430714577ae6ec5a87004442ca7348117 Mon Sep 17 00:00:00 2001
From: koniu <gkusni...@gmail.com>
Date: Sat, 23 May 2009 16:56:41 +0100
Subject: [PATCH] hooks: add exit hook

Signed-off-by: koniu <gkusni...@gmail.com>
---
 awesome.c |    5 +++++
 hooks.c   |   13 +++++++++++++
 luaa.c    |    1 +
 structs.h |    2 ++
 4 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/awesome.c b/awesome.c
index 5035a72..630820b 100644
--- a/awesome.c
+++ b/awesome.c
@@ -62,6 +62,11 @@ 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 b2ec266..f124193 100644
--- a/hooks.c
+++ b/hooks.c
@@ -202,6 +202,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
@@ -236,6 +248,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 9b5d4c1..9a69743 100644
--- a/luaa.c
+++ b/luaa.c
@@ -742,6 +742,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 56d4d17..3a11872 100644
--- a/structs.h
+++ b/structs.h
@@ -120,6 +120,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
-- 
1.6.3.1

Reply via email to