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.
24 #define HANDLE_HOOK(L, h) \
26 if(lua_gettop(L) == 1) \
27 luaA_registerfct(L, 1, &h); \
28 lua_rawgeti(L, LUA_REGISTRYINDEX, h); \
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.
37 * \lparam A function to call each time a client gets focus.
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.
50 * \lparam A function to call each time a client loses focus.
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.
64 * \lparam A function to call on each new client.
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.
77 * \lparam A function to call when a client goes away.
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.
90 * \lparam A function to call each time a client gets mouse over it.
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.
103 * \lparam A function to call each time a client gets mouse over it.
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.
116 * \lparam A function to call on each client list change.
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.
130 * \lparam A function to call on each tag list change.
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.
143 * \lparam A function to call on each client's tags change.
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.
156 * \lparam A function to call on each screen arrange.
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
167 * \param L The Lua VM state.
168 * \return The number of elements pushed on stack.
170 * \lparam A function to call on each client property update.
173 luaA_hooks_property(lua_State
*L
)
175 HANDLE_HOOK(L
, globalconf
.hooks
.property
);
178 /** Set the function called on each startup-notification events
179 * This function is called with a table and various fields set to describe the
181 * \param L The Lua VM state.
182 * \return The number of elements pushed on stack.
184 * \lparam A function to call on each startup-notification event.
187 luaA_hooks_startup_notification(lua_State
*L
)
189 HANDLE_HOOK(L
, globalconf
.hooks
.startup_notification
);
192 /** Set the function to be called every N seconds.
193 * \param L The Lua VM state.
194 * \return The number of elements pushed on stack.
196 * \lparam The number of seconds to run function every. Set 0 to disable.
197 * \lparam A function to call every N seconds (optional).
200 luaA_hooks_timer(lua_State
*L
)
202 if(lua_gettop(L
) >= 1)
204 globalconf
.timer
.repeat
= luaL_checknumber(L
, 1);
206 if(lua_gettop(L
) == 2 && !lua_isnil(L
, 2))
207 luaA_registerfct(L
, 2, &globalconf
.hooks
.timer
);
209 ev_timer_again(globalconf
.loop
, &globalconf
.timer
);
212 lua_rawgeti(L
, LUA_REGISTRYINDEX
, globalconf
.hooks
.timer
);
218 /** Set the function to be called when a D-Bus event is received.
219 * The first argument passed to this function is the type of the message we
220 * receive: signal, method_call, method_return or error.
221 * The second argument is the path.
222 * The other arguments are a variable list of arguments.
223 * The function can return values using pair of type, value.
224 * For example: return "s", "hello", "i", 32
225 * \param L The Lua VM state.
226 * \return The number of elements pushed on stack.
228 * \lparam A function to call on D-Bus events.
231 luaA_hooks_dbus(lua_State
*L
)
233 HANDLE_HOOK(L
, globalconf
.hooks
.dbus
);
237 const struct luaL_reg awesome_hooks_lib
[] =
239 { "focus", luaA_hooks_focus
},
240 { "unfocus", luaA_hooks_unfocus
},
241 { "manage", luaA_hooks_manage
},
242 { "unmanage", luaA_hooks_unmanage
},
243 { "mouse_enter", luaA_hooks_mouse_enter
},
244 { "mouse_leave", luaA_hooks_mouse_leave
},
245 { "property", luaA_hooks_property
},
246 { "arrange", luaA_hooks_arrange
},
247 { "clients", luaA_hooks_clients
},
248 { "tags", luaA_hooks_tags
},
249 { "tagged", luaA_hooks_tagged
},
250 { "startup_notification", luaA_hooks_startup_notification
},
251 { "timer", luaA_hooks_timer
},
253 { "dbus", luaA_hooks_dbus
},