awful.mouse/widget: enable drag'n'dropping clients on tags
[awesome.git] / hooks.c
blobf3826c1f6ad95720c4cb2601ced502cca953f8e1
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 extern awesome_t globalconf;
26 #define HANDLE_HOOK(L, h) \
27 do { \
28 if(lua_gettop(L) == 1) \
29 luaA_registerfct(L, 1, &h); \
30 lua_rawgeti(L, LUA_REGISTRYINDEX, h); \
31 return 1; \
32 } while(0)
34 /** Set the function called each time a client gets focus. This function is
35 * called with the client object as argument.
36 * \param L The Lua VM state.
37 * \return The number of elements pushed on stack.
38 * \luastack
39 * \lparam A function to call each time a client gets focus.
41 static int
42 luaA_hooks_focus(lua_State *L)
44 HANDLE_HOOK(L, globalconf.hooks.focus);
47 /** Set the function called each time a client loses focus. This function is
48 * called with the client object as argument.
49 * \param L The Lua VM state.
50 * \return The number of elements pushed on stack.
51 * \luastack
52 * \lparam A function to call each time a client loses focus.
54 static int
55 luaA_hooks_unfocus(lua_State *L)
57 HANDLE_HOOK(L, globalconf.hooks.unfocus);
60 /** Set the function called each time a new client appears. This function is
61 * called with the client object as argument.
62 * \param L The Lua VM state.
63 * \return The number of elements pushed on stack.
64 * \luastack
65 * \lparam A function to call on each new client.
67 static int
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.
77 * \luastack
78 * \lparam A function to call when a client goes away.
80 static int
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.
90 * \luastack
91 * \lparam A function to call each time a client gets mouse over it.
93 static int
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.
103 * \luastack
104 * \lparam A function to call each time a client gets mouse over it.
106 static int
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.
116 * \luastack
117 * \lparam A function to call on each client list change.
119 static int
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 or remove) as third.
128 * \param L The Lua VM state.
129 * \return The number of elements pushed on stack.
130 * \luastack
131 * \lparam A function to call on each tag list change.
133 static int
134 luaA_hooks_tags(lua_State *L)
136 HANDLE_HOOK(L, globalconf.hooks.tags);
139 /** Set the function called on each client's tags change.
140 * This function is called with the client and the tag as argument.
141 * \param L The Lua VM state.
142 * \return The number of elements pushed on stack.
143 * \luastack
144 * \lparam A function to call on each client's tags change.
146 static int
147 luaA_hooks_tagged(lua_State *L)
149 HANDLE_HOOK(L, globalconf.hooks.tagged);
152 /** Set the function called on each screen arrange. This function is called
153 * with the screen number as argument.
154 * \param L The Lua VM state.
155 * \return The number of elements pushed on stack.
156 * \luastack
157 * \lparam A function to call on each screen arrange.
159 static int
160 luaA_hooks_arrange(lua_State *L)
162 HANDLE_HOOK(L, globalconf.hooks.arrange);
165 /** Set the function called on each client's property change.
166 * This function is called with the client object as argument and the
167 * property name.
168 * \param L The Lua VM state.
169 * \return The number of elements pushed on stack.
170 * \luastack
171 * \lparam A function to call on each client property update.
173 static int
174 luaA_hooks_property(lua_State *L)
176 HANDLE_HOOK(L, globalconf.hooks.property);
179 /** Set the function to be called every N seconds.
180 * \param L The Lua VM state.
181 * \return The number of elements pushed on stack.
182 * \luastack
183 * \lparam The number of seconds to run function every. Set 0 to disable.
184 * \lparam A function to call every N seconds (optional).
186 static int
187 luaA_hooks_timer(lua_State *L)
189 if(lua_gettop(L) >= 1)
191 globalconf.timer.repeat = luaL_checknumber(L, 1);
193 if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
194 luaA_registerfct(L, 2, &globalconf.hooks.timer);
196 ev_timer_again(globalconf.loop, &globalconf.timer);
199 lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.hooks.timer);
201 return 1;
204 #ifdef WITH_DBUS
205 /** Set the function to be called when a D-Bus event is received.
206 * The first argument passed to this function is the type of the message we
207 * receive: signal, method_call, method_return or error.
208 * The second argument is the path.
209 * The other arguments are a variable list of arguments.
210 * The function can return values using pair of type, value.
211 * For example: return "s", "hello", "i", 32
212 * \param L The Lua VM state.
213 * \return The number of elements pushed on stack.
214 * \luastack
215 * \lparam A function to call on D-Bus events.
217 static int
218 luaA_hooks_dbus(lua_State *L)
220 HANDLE_HOOK(L, globalconf.hooks.dbus);
222 #endif
224 const struct luaL_reg awesome_hooks_lib[] =
226 { "focus", luaA_hooks_focus },
227 { "unfocus", luaA_hooks_unfocus },
228 { "manage", luaA_hooks_manage },
229 { "unmanage", luaA_hooks_unmanage },
230 { "mouse_enter", luaA_hooks_mouse_enter },
231 { "mouse_leave", luaA_hooks_mouse_leave },
232 { "property", luaA_hooks_property },
233 { "arrange", luaA_hooks_arrange },
234 { "clients", luaA_hooks_clients },
235 { "tags", luaA_hooks_tags },
236 { "tagged", luaA_hooks_tagged },
237 { "timer", luaA_hooks_timer },
238 #ifdef WITH_DBUS
239 { "dbus", luaA_hooks_dbus },
240 #endif
241 { NULL, NULL }