awful.menu: rewrite to be more object compliant
[awesome.git] / hooks.c
blob64e31f3b7aeaee30d7d343478c134f3f6f996a29
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 /** Set the function called each time a client gets focus. This function is
27 * called with the client object as argument.
28 * \param L The Lua VM state.
29 * \return The number of elements pushed on stack.
30 * \luastack
31 * \lparam A function to call each time a client gets focus.
33 static int
34 luaA_hooks_focus(lua_State *L)
36 return luaA_registerfct(L, 1, &globalconf.hooks.focus);
39 /** Set the function called each time a client loses focus. This function is
40 * called with the client object as argument.
41 * \param L The Lua VM state.
42 * \return The number of elements pushed on stack.
43 * \luastack
44 * \lparam A function to call each time a client loses focus.
46 static int
47 luaA_hooks_unfocus(lua_State *L)
49 return luaA_registerfct(L, 1, &globalconf.hooks.unfocus);
52 /** Set the function called each time a new client appears. This function is
53 * called with the client object as argument.
54 * \param L The Lua VM state.
55 * \return The number of elements pushed on stack.
56 * \luastack
57 * \lparam A function to call on each new client.
59 static int
60 luaA_hooks_manage(lua_State *L)
62 return luaA_registerfct(L, 1, &globalconf.hooks.manage);
65 /** Set the function called each time a client goes away. This function is
66 * called with the client object as argument.
67 * \param L The Lua VM state.
68 * \return The number of elements pushed on stack.
69 * \luastack
70 * \lparam A function to call when a client goes away.
72 static int
73 luaA_hooks_unmanage(lua_State *L)
75 return luaA_registerfct(L, 1, &globalconf.hooks.unmanage);
78 /** Set the function called each time the mouse enter a new window. This
79 * function is called with the client object as argument.
80 * \param L The Lua VM state.
81 * \return The number of elements pushed on stack.
82 * \luastack
83 * \lparam A function to call each time a client gets mouse over it.
85 static int
86 luaA_hooks_mouse_enter(lua_State *L)
88 return luaA_registerfct(L, 1, &globalconf.hooks.mouse_enter);
91 /** Set the function called each time the mouse enter a new window. This
92 * function is called with the client object as argument. (DEPRECATED)
93 * \param L The Lua VM state.
94 * \return The number of elements pushed on stack.
95 * \luastack
96 * \lparam A function to call each time a client gets mouse over it.
98 static int
99 luaA_hooks_mouseover(lua_State *L)
101 deprecate(L);
102 return luaA_hooks_mouse_enter(L);
105 /** Set the function called on each client list change.
106 * This function is called without any argument.
107 * \param L The Lua VM state.
108 * \return The number of elements pushed on stack.
109 * \luastack
110 * \lparam A function to call on each client list change.
112 static int
113 luaA_hooks_clients(lua_State *L)
115 return luaA_registerfct(L, 1, &globalconf.hooks.clients);
118 /** Set the function called on each screen tag list change.
119 * This function is called with a screen number as argument.
120 * \param L The Lua VM state.
121 * \return The number of elements pushed on stack.
122 * \luastack
123 * \lparam A function to call on each tag list change.
125 static int
126 luaA_hooks_tags(lua_State *L)
128 return luaA_registerfct(L, 1, &globalconf.hooks.tags);
131 /** Set the function called on each client's tags change.
132 * This function is called with the client and the tag as argument.
133 * \param L The Lua VM state.
134 * \return The number of elements pushed on stack.
135 * \luastack
136 * \lparam A function to call on each client's tags change.
138 static int
139 luaA_hooks_tagged(lua_State *L)
141 return luaA_registerfct(L, 1, &globalconf.hooks.tagged);
144 /** Set the function called on each screen arrange. This function is called
145 * with the screen number as argument.
146 * \param L The Lua VM state.
147 * \return The number of elements pushed on stack.
148 * \luastack
149 * \lparam A function to call on each screen arrange.
151 static int
152 luaA_hooks_arrange(lua_State *L)
154 return luaA_registerfct(L, 1, &globalconf.hooks.arrange);
157 /** Set the function called on each client's property change.
158 * This function is called with the client object as argument and the
159 * property name.
160 * \param L The Lua VM state.
161 * \return The number of elements pushed on stack.
162 * \luastack
163 * \lparam A function to call on each client property update.
165 static int
166 luaA_hooks_property(lua_State *L)
168 return luaA_registerfct(L, 1, &globalconf.hooks.property);
171 /** Set the function to be called every N seconds.
172 * \param L The Lua VM state.
173 * \return The number of elements pushed on stack.
174 * \luastack
175 * \lparam The number of seconds to run function every. Set 0 to disable.
176 * \lparam A function to call every N seconds (optional).
178 static int
179 luaA_hooks_timer(lua_State *L)
181 globalconf.timer.repeat = luaL_checknumber(L, 1);
183 if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
184 luaA_registerfct(L, 2, &globalconf.hooks.timer);
186 ev_timer_again(globalconf.loop, &globalconf.timer);
187 return 0;
190 const struct luaL_reg awesome_hooks_lib[] =
192 { "focus", luaA_hooks_focus },
193 { "unfocus", luaA_hooks_unfocus },
194 { "manage", luaA_hooks_manage },
195 { "unmanage", luaA_hooks_unmanage },
196 { "mouse_enter", luaA_hooks_mouse_enter },
197 { "property", luaA_hooks_property },
198 { "arrange", luaA_hooks_arrange },
199 { "clients", luaA_hooks_clients },
200 { "tags", luaA_hooks_tags },
201 { "tagged", luaA_hooks_tagged },
202 { "timer", luaA_hooks_timer },
203 /* deprecated */
204 { "mouseover", luaA_hooks_mouseover },
205 { NULL, NULL }