From 10bfb36d4bd17336f1f8f00b7ded56d186f52c21 Mon Sep 17 00:00:00 2001 From: Gregor Best Date: Fri, 13 Feb 2009 21:19:14 +0100 Subject: [PATCH] wibox: add mouse_enter and mouse_leave for wibox Signed-off-by: Gregor Best Signed-off-by: Julien Danjou --- event.c | 26 +++++++++++++++++--------- structs.h | 2 ++ wibox.c | 24 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/event.c b/event.c index dc2a7b1b..57886c1f 100644 --- a/event.c +++ b/event.c @@ -472,6 +472,9 @@ event_handle_leavenotify(void *data __attribute__ ((unused)), } wibox->mouse_over = NULL; } + + if(wibox->mouse_leave != LUA_REFNIL) + luaA_dofunction(globalconf.L, wibox->mouse_leave, 0, 0); } return 0; @@ -489,7 +492,6 @@ event_handle_enternotify(void *data __attribute__ ((unused)), { client_t *c; xembed_window_t *emwin; - wibox_t *wibox; widget_t *w; if(ev->mode != XCB_NOTIFY_MODE_NORMAL @@ -497,16 +499,22 @@ event_handle_enternotify(void *data __attribute__ ((unused)), && ev->root_y == globalconf.pointer_y)) return 0; + wibox_t *wibox = wibox_getbywin(ev->event); - if((wibox = wibox_getbywin(ev->event)) - && (w = widget_getbycoords(wibox->position, &wibox->widgets, - wibox->sw.geometry.width, - wibox->sw.geometry.height, - &ev->event_x, &ev->event_y))) + if(wibox) { - globalconf.pointer_x = ev->root_x; - globalconf.pointer_y = ev->root_y; - event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w); + if((w = widget_getbycoords(wibox->position, &wibox->widgets, + wibox->sw.geometry.width, + wibox->sw.geometry.height, + &ev->event_x, &ev->event_y))) + { + globalconf.pointer_x = ev->root_x; + globalconf.pointer_y = ev->root_y; + event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w); + } + + if(wibox->mouse_enter != LUA_REFNIL) + luaA_dofunction(globalconf.L, wibox->mouse_enter, 0, 0); } else if((c = client_getbytitlebarwin(ev->event)) || (c = client_getbywin(ev->event))) diff --git a/structs.h b/structs.h index 04cd495f..69e18a61 100644 --- a/structs.h +++ b/structs.h @@ -102,6 +102,8 @@ typedef struct luaA_ref widgets_table; /** Widget the mouse is over */ widget_t *mouse_over; + /** Mouse over event handler */ + luaA_ref mouse_enter, mouse_leave; /** Need update */ bool need_update; /** Cursor */ diff --git a/wibox.c b/wibox.c index a2bb5347..788fd7ce 100644 --- a/wibox.c +++ b/wibox.c @@ -467,6 +467,8 @@ wibox_delete(wibox_t **wibox) simplewindow_wipe(&(*wibox)->sw); button_array_wipe(&(*wibox)->buttons); luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*wibox)->widgets_table); + luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*wibox)->mouse_enter); + luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*wibox)->mouse_leave); widget_node_array_wipe(&(*wibox)->widgets); p_delete(wibox); } @@ -736,6 +738,8 @@ luaA_wibox_new(lua_State *L) w->isvisible = true; w->cursor = a_strdup("left_ptr"); + w->mouse_enter = w->mouse_leave = LUA_REFNIL; + for(i = 0; i <= reqs_nbr; i++) xcolor_init_reply(reqs[i]); @@ -816,6 +820,8 @@ luaA_wibox_invalidate_byitem(lua_State *L, const void *item) * \lfield position The position. * \lfield ontop On top of other windows. * \lfield cursor The mouse cursor. + * \lfield mouse_enter A function to execute when the mouse enter the widget. + * \lfield mouse_leave A function to execute when the mouse leave the widget. */ static int luaA_wibox_index(lua_State *L) @@ -886,6 +892,18 @@ luaA_wibox_index(lua_State *L) return 0; } break; + case A_TK_MOUSE_ENTER: + if((*wibox)->mouse_enter != LUA_REFNIL) + lua_rawgeti(L, LUA_REGISTRYINDEX, (*wibox)->mouse_enter); + else + return 0; + return 1; + case A_TK_MOUSE_LEAVE: + if((*wibox)->mouse_leave != LUA_REFNIL) + lua_rawgeti(L, LUA_REGISTRYINDEX, (*wibox)->mouse_leave); + else + return 0; + return 1; default: return 0; } @@ -1082,6 +1100,12 @@ luaA_wibox_newindex(lua_State *L) window_opacity_set((*wibox)->sw.window, d); } break; + case A_TK_MOUSE_ENTER: + luaA_registerfct(L, 3, &(*wibox)->mouse_enter); + return 0; + case A_TK_MOUSE_LEAVE: + luaA_registerfct(L, 3, &(*wibox)->mouse_leave); + return 0; default: switch((*wibox)->type) {