keygrabber: use XStringToKeysym()
[awesome.git] / hooks.c
blob1e8b74b7d912432047fda863ce406bda11daac87
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 called on each startup-notification events
179 * This function is called with a table and various fields set to describe the
180 * vents.
181 * \param L The Lua VM state.
182 * \return The number of elements pushed on stack.
183 * \luastack
184 * \lparam A function to call on each startup-notification event.
186 static int
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.
195 * \luastack
196 * \lparam The number of seconds to run function every. Set 0 to disable.
197 * \lparam A function to call every N seconds (optional).
199 static int
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);
214 return 1;
217 #ifdef WITH_DBUS
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.
227 * \luastack
228 * \lparam A function to call on D-Bus events.
230 static int
231 luaA_hooks_dbus(lua_State *L)
233 HANDLE_HOOK(L, globalconf.hooks.dbus);
235 #endif
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 },
252 #ifdef WITH_DBUS
253 { "dbus", luaA_hooks_dbus },
254 #endif
255 { NULL, NULL }