2 * hooks.c - Lua hooks management
4 * Copyright © 2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #define HANDLE_HOOK(L, h) \
27 if(lua_gettop(L) == 1) \
28 luaA_registerfct(L, 1, &h); \
29 lua_rawgeti(L, LUA_REGISTRYINDEX, h); \
33 /** Set the function called each time a client gets focus. This function is
34 * called with the client object as argument.
35 * \param L The Lua VM state.
36 * \return The number of elements pushed on stack.
38 * \lparam A function to call each time a client gets focus.
41 luaA_hooks_focus(lua_State
*L
)
43 HANDLE_HOOK(L
, globalconf
.hooks
.focus
);
46 /** Set the function called each time a client loses focus. This function is
47 * called with the client object as argument.
48 * \param L The Lua VM state.
49 * \return The number of elements pushed on stack.
51 * \lparam A function to call each time a client loses focus.
54 luaA_hooks_unfocus(lua_State
*L
)
56 HANDLE_HOOK(L
, globalconf
.hooks
.unfocus
);
59 /** Set the function called each time a new client appears. This function is
60 * called with the client object as argument, plus a boolean argument which is
61 * true if the client is managed at startup.
62 * \param L The Lua VM state.
63 * \return The number of elements pushed on stack.
65 * \lparam A function to call on each new client.
68 luaA_hooks_manage(lua_State
*L
)
70 HANDLE_HOOK(L
, globalconf
.hooks
.manage
);
73 /** Set the function called each time a client goes away. This function is
74 * called with the client object as argument.
75 * \param L The Lua VM state.
76 * \return The number of elements pushed on stack.
78 * \lparam A function to call when a client goes away.
81 luaA_hooks_unmanage(lua_State
*L
)
83 HANDLE_HOOK(L
, globalconf
.hooks
.unmanage
);
86 /** Set the function called each time the mouse enter a window. This
87 * function is called with the client object as argument.
88 * \param L The Lua VM state.
89 * \return The number of elements pushed on stack.
91 * \lparam A function to call each time a client gets mouse over it.
94 luaA_hooks_mouse_enter(lua_State
*L
)
96 HANDLE_HOOK(L
, globalconf
.hooks
.mouse_enter
);
99 /** Set the function called each time the mouse leave a window. This
100 * function is called with the client object as argument.
101 * \param L The Lua VM state.
102 * \return The number of elements pushed on stack.
104 * \lparam A function to call each time a client gets mouse over it.
107 luaA_hooks_mouse_leave(lua_State
*L
)
109 HANDLE_HOOK(L
, globalconf
.hooks
.mouse_leave
);
112 /** Set the function called on each client list change.
113 * This function is called without any argument.
114 * \param L The Lua VM state.
115 * \return The number of elements pushed on stack.
117 * \lparam A function to call on each client list change.
120 luaA_hooks_clients(lua_State
*L
)
122 HANDLE_HOOK(L
, globalconf
.hooks
.clients
);
125 /** Set the function called on each screen tag list change.
126 * This function is called with a screen number as first argument,
127 * the tag object as second and the action (add, remove, select or unselect)
129 * \param L The Lua VM state.
130 * \return The number of elements pushed on stack.
132 * \lparam A function to call on each tag list change.
135 luaA_hooks_tags(lua_State
*L
)
137 HANDLE_HOOK(L
, globalconf
.hooks
.tags
);
140 /** Set the function called on each client's tags change.
141 * This function is called with the client and the tag as argument.
142 * \param L The Lua VM state.
143 * \return The number of elements pushed on stack.
145 * \lparam A function to call on each client's tags change.
148 luaA_hooks_tagged(lua_State
*L
)
150 HANDLE_HOOK(L
, globalconf
.hooks
.tagged
);
153 /** Set the function called on each client's property change.
154 * This function is called with the client object as argument and the
156 * \param L The Lua VM state.
157 * \return The number of elements pushed on stack.
159 * \lparam A function to call on each client property update.
162 luaA_hooks_property(lua_State
*L
)
164 HANDLE_HOOK(L
, globalconf
.hooks
.property
);
167 /** Set the function to be called every N seconds.
168 * \param L The Lua VM state.
169 * \return The number of elements pushed on stack.
171 * \lparam The number of seconds to run function every. Set 0 to disable.
172 * \lparam A function to call every N seconds (optional).
175 luaA_hooks_timer(lua_State
*L
)
177 if(lua_gettop(L
) >= 1)
179 globalconf
.timer
.repeat
= luaL_checknumber(L
, 1);
181 if(lua_gettop(L
) == 2 && !lua_isnil(L
, 2))
182 luaA_registerfct(L
, 2, &globalconf
.hooks
.timer
);
184 ev_timer_again(globalconf
.loop
, &globalconf
.timer
);
187 lua_rawgeti(L
, LUA_REGISTRYINDEX
, globalconf
.hooks
.timer
);
192 /** Set the function called on awesome exit
193 * \param L The Lua VM state.
194 * \return The number of elements pushed on stack.
196 * \lparam A function to call on awesome exit.
199 luaA_hooks_exit(lua_State
*L
)
201 HANDLE_HOOK(L
, globalconf
.hooks
.exit
);
204 const struct luaL_reg awesome_hooks_lib
[] =
206 { "focus", luaA_hooks_focus
},
207 { "unfocus", luaA_hooks_unfocus
},
208 { "manage", luaA_hooks_manage
},
209 { "unmanage", luaA_hooks_unmanage
},
210 { "mouse_enter", luaA_hooks_mouse_enter
},
211 { "mouse_leave", luaA_hooks_mouse_leave
},
212 { "property", luaA_hooks_property
},
213 { "clients", luaA_hooks_clients
},
214 { "tags", luaA_hooks_tags
},
215 { "tagged", luaA_hooks_tagged
},
216 { "timer", luaA_hooks_timer
},
217 { "exit", luaA_hooks_exit
},