2008-10-26 18:54:22 +01:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2008-11-27 16:00:13 +01:00
|
|
|
#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)
|
|
|
|
|
2008-10-26 18:54:22 +01:00
|
|
|
/** 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)
|
|
|
|
{
|
2008-11-27 16:00:13 +01:00
|
|
|
HANDLE_HOOK(L, globalconf.hooks.focus);
|
2008-10-26 18:54:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 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)
|
|
|
|
{
|
2008-11-27 16:00:13 +01:00
|
|
|
HANDLE_HOOK(L, globalconf.hooks.unfocus);
|
2008-10-26 18:54:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the function called each time a new client appears. This function is
|
2008-12-29 12:23:37 +01:00
|
|
|
* called with the client object as argument, plus a boolean argument which is
|
|
|
|
* true if the client is managed at startup.
|
2008-10-26 18:54:22 +01:00
|
|
|
* \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)
|
|
|
|
{
|
2008-11-27 16:00:13 +01:00
|
|
|
HANDLE_HOOK(L, globalconf.hooks.manage);
|
2008-10-26 18:54:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 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)
|
|
|
|
{
|
2008-11-27 16:00:13 +01:00
|
|
|
HANDLE_HOOK(L, globalconf.hooks.unmanage);
|
2008-10-26 18:54:22 +01:00
|
|
|
}
|
|
|
|
|
2008-12-01 15:43:16 +01:00
|
|
|
/** Set the function called each time the mouse enter a window. This
|
2008-10-26 18:54:22 +01:00
|
|
|
* 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)
|
|
|
|
{
|
2008-11-27 16:00:13 +01:00
|
|
|
HANDLE_HOOK(L, globalconf.hooks.mouse_enter);
|
2008-10-26 18:54:22 +01:00
|
|
|
}
|
|
|
|
|
2008-12-01 15:43:16 +01:00
|
|
|
/** 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);
|
|
|
|
}
|
|
|
|
|
2008-10-26 18:54:22 +01:00
|
|
|
/** 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)
|
|
|
|
{
|
2008-11-27 16:00:13 +01:00
|
|
|
HANDLE_HOOK(L, globalconf.hooks.clients);
|
2008-10-26 18:54:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the function called on each screen tag list change.
|
2008-11-27 14:22:26 +01:00
|
|
|
* This function is called with a screen number as first argument,
|
|
|
|
* the tag object as second and the action (add or remove) as third.
|
2008-10-26 18:54:22 +01:00
|
|
|
* \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)
|
|
|
|
{
|
2008-11-27 16:00:13 +01:00
|
|
|
HANDLE_HOOK(L, globalconf.hooks.tags);
|
2008-10-26 18:54:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 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)
|
|
|
|
{
|
2008-11-27 16:00:13 +01:00
|
|
|
HANDLE_HOOK(L, globalconf.hooks.tagged);
|
2008-10-26 18:54:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 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)
|
|
|
|
{
|
2008-11-27 16:00:13 +01:00
|
|
|
HANDLE_HOOK(L, globalconf.hooks.arrange);
|
2008-10-26 18:54:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 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)
|
|
|
|
{
|
2008-11-27 16:00:13 +01:00
|
|
|
HANDLE_HOOK(L, globalconf.hooks.property);
|
2008-10-26 18:54:22 +01:00
|
|
|
}
|
|
|
|
|
2009-04-03 16:30:18 +02:00
|
|
|
/** 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);
|
|
|
|
}
|
|
|
|
|
2008-10-26 18:54:22 +01:00
|
|
|
/** 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)
|
|
|
|
{
|
2008-11-27 16:00:13 +01:00
|
|
|
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);
|
|
|
|
}
|
2008-10-26 18:54:22 +01:00
|
|
|
|
2008-11-27 16:00:13 +01:00
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.hooks.timer);
|
2008-10-26 18:54:22 +01:00
|
|
|
|
2008-11-27 16:00:13 +01:00
|
|
|
return 1;
|
2008-10-26 18:54:22 +01:00
|
|
|
}
|
|
|
|
|
2008-11-19 02:22:05 +01:00
|
|
|
#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.
|
2008-11-19 02:21:11 +01:00
|
|
|
* The function can return values using pair of type, value.
|
|
|
|
* For example: return "s", "hello", "i", 32
|
2008-11-19 02:22:05 +01:00
|
|
|
* \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)
|
|
|
|
{
|
2008-11-27 16:00:13 +01:00
|
|
|
HANDLE_HOOK(L, globalconf.hooks.dbus);
|
2008-11-19 02:22:05 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-26 18:54:22 +01:00
|
|
|
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 },
|
2008-12-01 15:43:16 +01:00
|
|
|
{ "mouse_leave", luaA_hooks_mouse_leave },
|
2008-10-26 18:54:22 +01:00
|
|
|
{ "property", luaA_hooks_property },
|
|
|
|
{ "arrange", luaA_hooks_arrange },
|
|
|
|
{ "clients", luaA_hooks_clients },
|
|
|
|
{ "tags", luaA_hooks_tags },
|
|
|
|
{ "tagged", luaA_hooks_tagged },
|
2009-04-03 16:30:18 +02:00
|
|
|
{ "startup_notification", luaA_hooks_startup_notification },
|
2008-10-26 18:54:22 +01:00
|
|
|
{ "timer", luaA_hooks_timer },
|
2008-11-19 02:22:05 +01:00
|
|
|
#ifdef WITH_DBUS
|
|
|
|
{ "dbus", luaA_hooks_dbus },
|
|
|
|
#endif
|
2008-10-26 18:54:22 +01:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|