naughty: add opacity option
[awesome.git] / hooks.c
bloba4409454e460fb19fc891f09b1a821d7531eab54
1 /*
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.
22 #include "structs.h"
24 #define HANDLE_HOOK(L, h) \
25 do { \
26 if(lua_gettop(L) == 1) \
27 luaA_registerfct(L, 1, &h); \
28 lua_rawgeti(L, LUA_REGISTRYINDEX, h); \
29 return 1; \
30 } while(0)
32 /** Set the function called each time a client gets focus. This function is
33 * called with the client object as argument.
34 * \param L The Lua VM state.
35 * \return The number of elements pushed on stack.
36 * \luastack
37 * \lparam A function to call each time a client gets focus.
39 static int
40 luaA_hooks_focus(lua_State *L)
42 HANDLE_HOOK(L, globalconf.hooks.focus);
45 /** Set the function called each time a client loses focus. This function is
46 * called with the client object as argument.
47 * \param L The Lua VM state.
48 * \return The number of elements pushed on stack.
49 * \luastack
50 * \lparam A function to call each time a client loses focus.
52 static int
53 luaA_hooks_unfocus(lua_State *L)
55 HANDLE_HOOK(L, globalconf.hooks.unfocus);
58 /** Set the function called each time a new client appears. This function is
59 * called with the client object as argument, plus a boolean argument which is
60 * true if the client is managed at startup.
61 * \param L The Lua VM state.
62 * \return The number of elements pushed on stack.
63 * \luastack
64 * \lparam A function to call on each new client.
66 static int
67 luaA_hooks_manage(lua_State *L)
69 HANDLE_HOOK(L, globalconf.hooks.manage);
72 /** Set the function called each time a client goes away. This function is
73 * called with the client object as argument.
74 * \param L The Lua VM state.
75 * \return The number of elements pushed on stack.
76 * \luastack
77 * \lparam A function to call when a client goes away.
79 static int
80 luaA_hooks_unmanage(lua_State *L)
82 HANDLE_HOOK(L, globalconf.hooks.unmanage);
85 /** Set the function called each time the mouse enter a window. This
86 * function is called with the client object as argument.
87 * \param L The Lua VM state.
88 * \return The number of elements pushed on stack.
89 * \luastack
90 * \lparam A function to call each time a client gets mouse over it.
92 static int
93 luaA_hooks_mouse_enter(lua_State *L)
95 HANDLE_HOOK(L, globalconf.hooks.mouse_enter);
98 /** Set the function called each time the mouse leave a window. This
99 * function is called with the client object as argument.
100 * \param L The Lua VM state.
101 * \return The number of elements pushed on stack.
102 * \luastack
103 * \lparam A function to call each time a client gets mouse over it.
105 static int
106 luaA_hooks_mouse_leave(lua_State *L)
108 HANDLE_HOOK(L, globalconf.hooks.mouse_leave);
111 /** Set the function called on each client list change.
112 * This function is called without any argument.
113 * \param L The Lua VM state.
114 * \return The number of elements pushed on stack.
115 * \luastack
116 * \lparam A function to call on each client list change.
118 static int
119 luaA_hooks_clients(lua_State *L)
121 HANDLE_HOOK(L, globalconf.hooks.clients);
124 /** Set the function called on each screen tag list change.
125 * This function is called with a screen number as first argument,
126 * the tag object as second and the action (add or remove) as third.
127 * \param L The Lua VM state.
128 * \return The number of elements pushed on stack.
129 * \luastack
130 * \lparam A function to call on each tag list change.
132 static int
133 luaA_hooks_tags(lua_State *L)
135 HANDLE_HOOK(L, globalconf.hooks.tags);
138 /** Set the function called on each client's tags change.
139 * This function is called with the client and the tag as argument.
140 * \param L The Lua VM state.
141 * \return The number of elements pushed on stack.
142 * \luastack
143 * \lparam A function to call on each client's tags change.
145 static int
146 luaA_hooks_tagged(lua_State *L)
148 HANDLE_HOOK(L, globalconf.hooks.tagged);
151 /** Set the function called on each screen arrange. This function is called
152 * with the screen number as argument.
153 * \param L The Lua VM state.
154 * \return The number of elements pushed on stack.
155 * \luastack
156 * \lparam A function to call on each screen arrange.
158 static int
159 luaA_hooks_arrange(lua_State *L)
161 HANDLE_HOOK(L, globalconf.hooks.arrange);
164 /** Set the function called on each client's property change.
165 * This function is called with the client object as argument and the
166 * property name.
167 * \param L The Lua VM state.
168 * \return The number of elements pushed on stack.
169 * \luastack
170 * \lparam A function to call on each client property update.
172 static int
173 luaA_hooks_property(lua_State *L)
175 HANDLE_HOOK(L, globalconf.hooks.property);
178 /** Set the function to be called every N seconds.
179 * \param L The Lua VM state.
180 * \return The number of elements pushed on stack.
181 * \luastack
182 * \lparam The number of seconds to run function every. Set 0 to disable.
183 * \lparam A function to call every N seconds (optional).
185 static int
186 luaA_hooks_timer(lua_State *L)
188 if(lua_gettop(L) >= 1)
190 globalconf.timer.repeat = luaL_checknumber(L, 1);
192 if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
193 luaA_registerfct(L, 2, &globalconf.hooks.timer);
195 ev_timer_again(globalconf.loop, &globalconf.timer);
198 lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.hooks.timer);
200 return 1;
203 #ifdef WITH_DBUS
204 /** Set the function to be called when a D-Bus event is received.
205 * The first argument passed to this function is the type of the message we
206 * receive: signal, method_call, method_return or error.
207 * The second argument is the path.
208 * The other arguments are a variable list of arguments.
209 * The function can return values using pair of type, value.
210 * For example: return "s", "hello", "i", 32
211 * \param L The Lua VM state.
212 * \return The number of elements pushed on stack.
213 * \luastack
214 * \lparam A function to call on D-Bus events.
216 static int
217 luaA_hooks_dbus(lua_State *L)
219 HANDLE_HOOK(L, globalconf.hooks.dbus);
221 #endif
223 const struct luaL_reg awesome_hooks_lib[] =
225 { "focus", luaA_hooks_focus },
226 { "unfocus", luaA_hooks_unfocus },
227 { "manage", luaA_hooks_manage },
228 { "unmanage", luaA_hooks_unmanage },
229 { "mouse_enter", luaA_hooks_mouse_enter },
230 { "mouse_leave", luaA_hooks_mouse_leave },
231 { "property", luaA_hooks_property },
232 { "arrange", luaA_hooks_arrange },
233 { "clients", luaA_hooks_clients },
234 { "tags", luaA_hooks_tags },
235 { "tagged", luaA_hooks_tagged },
236 { "timer", luaA_hooks_timer },
237 #ifdef WITH_DBUS
238 { "dbus", luaA_hooks_dbus },
239 #endif
240 { NULL, NULL }