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 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.
31 * \lparam A function to call each time a client gets focus.
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.
44 * \lparam A function to call each time a client loses focus.
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.
57 * \lparam A function to call on each new client.
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.
70 * \lparam A function to call when a client goes away.
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.
83 * \lparam A function to call each time a client gets mouse over it.
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.
96 * \lparam A function to call each time a client gets mouse over it.
99 luaA_hooks_mouseover(lua_State
*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.
110 * \lparam A function to call on each client list change.
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.
123 * \lparam A function to call on each tag list change.
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.
136 * \lparam A function to call on each client's tags change.
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.
149 * \lparam A function to call on each screen arrange.
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
160 * \param L The Lua VM state.
161 * \return The number of elements pushed on stack.
163 * \lparam A function to call on each client property update.
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.
175 * \lparam The number of seconds to run function every. Set 0 to disable.
176 * \lparam A function to call every N seconds (optional).
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
);
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
},
204 { "mouseover", luaA_hooks_mouseover
},