Hi people, the first attached patch adds a mouse_enter and mouse_leave function to wiboxes which can be used in the same way as those on widgets.
The second patch fixes the assignment of buttons for menu entries to allow
clicking on any part of the entry to run its assigned function.
--
Gregor Best
From b89a6db3c4587e8266f33b6992f8eac37cf83036 Mon Sep 17 00:00:00 2001 From: Gregor Best <[email protected]> Date: Fri, 13 Feb 2009 21:19:14 +0100 Subject: [PATCH 1/2] event.c / wibox.c: add mouse_enter and mouse_leave for wibox Signed-off-by: Gregor Best <[email protected]> --- event.c | 20 +++++++++++++------- structs.h | 2 ++ wibox.c | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/event.c b/event.c index dc2a7b1..03973af 100644 --- a/event.c +++ b/event.c @@ -472,6 +472,10 @@ event_handle_leavenotify(void *data __attribute__ ((unused)), } wibox->mouse_over = NULL; } + else if(wibox->mouse_leave != LUA_REFNIL) + { + luaA_dofunction(globalconf.L, wibox->mouse_leave, 0, 0); + } } return 0; @@ -489,25 +493,27 @@ event_handle_enternotify(void *data __attribute__ ((unused)), { client_t *c; xembed_window_t *emwin; - wibox_t *wibox; widget_t *w; + wibox_t *wibox = wibox_getbywin(ev->event); if(ev->mode != XCB_NOTIFY_MODE_NORMAL || (ev->root_x == globalconf.pointer_x && ev->root_y == globalconf.pointer_y)) return 0; - - 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) && (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); } + else if((wibox) && (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 04cd495..69e18a6 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 a2bb534..788fd7c 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) { -- 1.6.1.2
From 631de5d4fed8b52c8493b58b0ad8a59fafdf000a Mon Sep 17 00:00:00 2001 From: Gregor Best <[email protected]> Date: Fri, 13 Feb 2009 21:20:23 +0100 Subject: [PATCH 2/2] lib/awful/menu.lua: fix item buttons Signed-off-by: Gregor Best <[email protected]> --- lib/awful/menu.lua.in | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/lib/awful/menu.lua.in b/lib/awful/menu.lua.in index 1aa91d3..c268edb 100644 --- a/lib/awful/menu.lua.in +++ b/lib/awful/menu.lua.in @@ -134,10 +134,14 @@ local function add_item(data, num, item_info) end label:buttons(bindings) + item:buttons(bindings) function label.mouse_enter() mouse_enter(item, data.theme) end function label.mouse_leave() mouse_leave(item, data.theme) end + function item.mouse_enter() mouse_enter(item, data.theme) end + function item.mouse_leave() mouse_leave(item, data.theme) end + -- Create the submenu icon widget local submenu if type(item_info[2]) == "table" then -- 1.6.1.2
signature.asc
Description: PGP signature
