From 26de388c4cf24bcc14bbc169ca5d02f72b2984a4 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 1 Dec 2008 15:43:16 +0100 Subject: [PATCH] client: add mouse_leave hook Signed-off-by: Julien Danjou --- client.c | 1 + event.c | 26 +++++++++++++++++++------- hooks.c | 16 +++++++++++++++- luaa.c | 1 + structs.h | 2 ++ 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/client.c b/client.c index babddda95..243da82ff 100644 --- a/client.c +++ b/client.c @@ -445,6 +445,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_ENTER_WINDOW + | XCB_EVENT_MASK_LEAVE_WINDOW }; diff --git a/event.c b/event.c index 6c5804223..17ce7a7b9 100644 --- a/event.c +++ b/event.c @@ -459,17 +459,29 @@ event_handle_leavenotify(void *data __attribute__ ((unused)), xcb_connection_t *connection, xcb_leave_notify_event_t *ev) { - wibox_t *wibox = wibox_getbywin(ev->event); + wibox_t *wibox; + client_t *c = client_getbywin(ev->event); - if(wibox && wibox->mouse_over) + if(c) { - if(wibox->mouse_over->mouse_leave != LUA_REFNIL) + if(globalconf.hooks.mouse_leave != LUA_REFNIL) { - /* call mouse leave function on widget the mouse was over */ - luaA_wibox_userdata_new(globalconf.L, wibox); - luaA_dofunction(globalconf.L, wibox->mouse_over->mouse_leave, 1, 0); + luaA_client_userdata_new(globalconf.L, c); + luaA_dofunction(globalconf.L, globalconf.hooks.mouse_leave, 1, 0); + } + } + else if((wibox = wibox_getbywin(ev->event))) + { + if(wibox->mouse_over) + { + if(wibox->mouse_over->mouse_leave != LUA_REFNIL) + { + /* call mouse leave function on widget the mouse was over */ + luaA_wibox_userdata_new(globalconf.L, wibox); + luaA_dofunction(globalconf.L, wibox->mouse_over->mouse_leave, 1, 0); + } + wibox->mouse_over = NULL; } - wibox->mouse_over = NULL; } return 0; diff --git a/hooks.c b/hooks.c index 42611013c..f3826c1f6 100644 --- a/hooks.c +++ b/hooks.c @@ -83,7 +83,7 @@ luaA_hooks_unmanage(lua_State *L) HANDLE_HOOK(L, globalconf.hooks.unmanage); } -/** Set the function called each time the mouse enter a new window. This +/** 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. @@ -96,6 +96,19 @@ 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. @@ -215,6 +228,7 @@ const struct luaL_reg awesome_hooks_lib[] = { "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 }, diff --git a/luaa.c b/luaa.c index 6022a3355..23cdb43b9 100644 --- a/luaa.c +++ b/luaa.c @@ -820,6 +820,7 @@ luaA_init(void) globalconf.hooks.focus = LUA_REFNIL; globalconf.hooks.unfocus = LUA_REFNIL; globalconf.hooks.mouse_enter = LUA_REFNIL; + globalconf.hooks.mouse_leave = LUA_REFNIL; globalconf.hooks.arrange = LUA_REFNIL; globalconf.hooks.clients = LUA_REFNIL; globalconf.hooks.tags = LUA_REFNIL; diff --git a/structs.h b/structs.h index 92ab082ec..f23b78727 100644 --- a/structs.h +++ b/structs.h @@ -350,6 +350,8 @@ struct awesome_t luaA_ref unfocus; /** Command to run when mouse enter a client */ luaA_ref mouse_enter; + /** Command to run when mouse leave a client */ + luaA_ref mouse_leave; /** Command to run on arrange */ luaA_ref arrange; /** Command to run when client list changes */