forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks.c
More file actions
256 lines (235 loc) · 7.59 KB
/
Copy pathhooks.c
File metadata and controls
256 lines (235 loc) · 7.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
* hooks.c - Lua hooks management
*
* Copyright © 2008 Julien Danjou <julien@danjou.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "structs.h"
#define HANDLE_HOOK(L, h) \
do { \
if(lua_gettop(L) == 1) \
luaA_registerfct(L, 1, &h); \
lua_rawgeti(L, LUA_REGISTRYINDEX, h); \
return 1; \
} while(0)
/** Set the function called each time a client gets focus. This function is
* called with the client object as argument.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call each time a client gets focus.
*/
static int
luaA_hooks_focus(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.focus);
}
/** Set the function called each time a client loses focus. This function is
* called with the client object as argument.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call each time a client loses focus.
*/
static int
luaA_hooks_unfocus(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.unfocus);
}
/** Set the function called each time a new client appears. This function is
* called with the client object as argument, plus a boolean argument which is
* true if the client is managed at startup.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call on each new client.
*/
static int
luaA_hooks_manage(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.manage);
}
/** Set the function called each time a client goes away. This function is
* called with the client object as argument.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call when a client goes away.
*/
static int
luaA_hooks_unmanage(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.unmanage);
}
/** Set the function called each time the mouse enter a window. This
* function is called with the client object as argument.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call each time a client gets mouse over it.
*/
static int
luaA_hooks_mouse_enter(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.mouse_enter);
}
/** Set the function called each time the mouse leave a window. This
* function is called with the client object as argument.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call each time a client gets mouse over it.
*/
static int
luaA_hooks_mouse_leave(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.mouse_leave);
}
/** Set the function called on each client list change.
* This function is called without any argument.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call on each client list change.
*/
static int
luaA_hooks_clients(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.clients);
}
/** Set the function called on each screen tag list change.
* This function is called with a screen number as first argument,
* the tag object as second and the action (add or remove) as third.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call on each tag list change.
*/
static int
luaA_hooks_tags(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.tags);
}
/** Set the function called on each client's tags change.
* This function is called with the client and the tag as argument.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call on each client's tags change.
*/
static int
luaA_hooks_tagged(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.tagged);
}
/** Set the function called on each screen arrange. This function is called
* with the screen number as argument.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call on each screen arrange.
*/
static int
luaA_hooks_arrange(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.arrange);
}
/** Set the function called on each client's property change.
* This function is called with the client object as argument and the
* property name.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call on each client property update.
*/
static int
luaA_hooks_property(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.property);
}
/** Set the function called on each startup-notification events
* This function is called with a table and various fields set to describe the
* vents.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call on each startup-notification event.
*/
static int
luaA_hooks_startup_notification(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.startup_notification);
}
/** Set the function to be called every N seconds.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam The number of seconds to run function every. Set 0 to disable.
* \lparam A function to call every N seconds (optional).
*/
static int
luaA_hooks_timer(lua_State *L)
{
if(lua_gettop(L) >= 1)
{
globalconf.timer.repeat = luaL_checknumber(L, 1);
if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
luaA_registerfct(L, 2, &globalconf.hooks.timer);
ev_timer_again(globalconf.loop, &globalconf.timer);
}
lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.hooks.timer);
return 1;
}
#ifdef WITH_DBUS
/** Set the function to be called when a D-Bus event is received.
* The first argument passed to this function is the type of the message we
* receive: signal, method_call, method_return or error.
* The second argument is the path.
* The other arguments are a variable list of arguments.
* The function can return values using pair of type, value.
* For example: return "s", "hello", "i", 32
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam A function to call on D-Bus events.
*/
static int
luaA_hooks_dbus(lua_State *L)
{
HANDLE_HOOK(L, globalconf.hooks.dbus);
}
#endif
const struct luaL_reg awesome_hooks_lib[] =
{
{ "focus", luaA_hooks_focus },
{ "unfocus", luaA_hooks_unfocus },
{ "manage", luaA_hooks_manage },
{ "unmanage", luaA_hooks_unmanage },
{ "mouse_enter", luaA_hooks_mouse_enter },
{ "mouse_leave", luaA_hooks_mouse_leave },
{ "property", luaA_hooks_property },
{ "arrange", luaA_hooks_arrange },
{ "clients", luaA_hooks_clients },
{ "tags", luaA_hooks_tags },
{ "tagged", luaA_hooks_tagged },
{ "startup_notification", luaA_hooks_startup_notification },
{ "timer", luaA_hooks_timer },
#ifdef WITH_DBUS
{ "dbus", luaA_hooks_dbus },
#endif
{ NULL, NULL }
};