widget: emit signals on mouse enter and leave

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-08-17 15:43:32 +02:00
parent 59c991ace0
commit 9c40168f02
5 changed files with 23 additions and 30 deletions

25
event.c
View File

@ -350,25 +350,19 @@ event_handle_widget_motionnotify(void *object,
if(widget != *mouse_over) if(widget != *mouse_over)
{ {
if(*mouse_over) if(*mouse_over)
{
if((*mouse_over)->mouse_leave)
{ {
/* call mouse leave function on old widget */ /* call mouse leave function on old widget */
luaA_object_push(globalconf.L, *mouse_over); luaA_object_push(globalconf.L, *mouse_over);
luaA_object_push_item(globalconf.L, -1, (*mouse_over)->mouse_leave); luaA_object_emit_signal(globalconf.L, -1, "mouse::leave", 0);
luaA_dofunction(globalconf.L, 1, 0); lua_pop(globalconf.L, 1);
}
} }
if(widget) if(widget)
{ {
/* call mouse enter function on new widget and register it */ /* emit mouse::enter signal on new widget and register it */
*mouse_over = widget; *mouse_over = widget;
if(widget->mouse_enter)
{
luaA_object_push(globalconf.L, widget); luaA_object_push(globalconf.L, widget);
luaA_object_push_item(globalconf.L, -1, widget->mouse_enter); luaA_object_emit_signal(globalconf.L, -1, "mouse::enter", 0);
luaA_dofunction(globalconf.L, 1, 0); lua_pop(globalconf.L, 1);
}
} }
} }
} }
@ -428,13 +422,10 @@ event_handle_leavenotify(void *data __attribute__ ((unused)),
{ {
if(wibox->mouse_over) if(wibox->mouse_over)
{ {
if(wibox->mouse_over->mouse_leave)
{
/* call mouse leave function on widget the mouse was over */
luaA_object_push(globalconf.L, wibox->mouse_over); luaA_object_push(globalconf.L, wibox->mouse_over);
luaA_object_push_item(globalconf.L, -1, wibox->mouse_over->mouse_leave); /* emit mouse::leave signal on widget the mouse was over */
luaA_dofunction(globalconf.L, 1, 0); luaA_object_emit_signal(globalconf.L, -1, "mouse::leave", 0);
} lua_pop(globalconf.L, 1);
wibox->mouse_over = NULL; wibox->mouse_over = NULL;
} }

View File

@ -202,8 +202,10 @@ local function add_item(data, num, item_info)
item:buttons(bindings) item:buttons(bindings)
function label.mouse_enter() item_enter(data, num, true) end local mouse_enter_func = function () item_enter(data, num, true) end
function item.mouse_enter() item_enter(data, num, true) end
label:add_signal("mouse::enter", mouse_enter_func)
item.mouse_enter = mouse_enter_func
-- Create the submenu icon widget -- Create the submenu icon widget
local submenu local submenu
@ -212,7 +214,7 @@ local function add_item(data, num, item_info)
submenu.image = data.theme.submenu_icon and image(data.theme.submenu_icon) submenu.image = data.theme.submenu_icon and image(data.theme.submenu_icon)
submenu:buttons(bindings) submenu:buttons(bindings)
function submenu.mouse_enter() item_enter(data, num, true) end submenu:add_signal("mouse::enter", mouse_enter_func)
end end
-- Add widgets to the wibox -- Add widgets to the wibox

View File

@ -33,8 +33,10 @@ function new(args)
local w = capi.widget(args) local w = capi.widget(args)
w.image = img_release w.image = img_release
w:buttons(button({}, 1, function () w.image = img_press end, function () w.image = img_release end)) w:buttons(button({}, 1, function () w.image = img_press end, function () w.image = img_release end))
function w.mouse_leave(s) w.image = img_release end w:add_signal("mouse::leave", function () w.image = img_release end)
function w.mouse_enter(s) if capi.mouse.coords().buttons[1] then w.image = img_press end end w:add_signal("mouse::enter", function ()
if capi.mouse.coords().buttons[1] then w.image = img_press end
end)
return w return w
end end

View File

@ -319,7 +319,6 @@ function notify(args)
textbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die))) textbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
textbox:margin({ right = margin, left = margin, bottom = margin, top = margin }) textbox:margin({ right = margin, left = margin, bottom = margin, top = margin })
textbox.text = string.format('<span font_desc="%s"><b>%s</b>%s</span>', font, title, text) textbox.text = string.format('<span font_desc="%s"><b>%s</b>%s</span>', font, title, text)
if hover_timeout then textbox.mouse_enter = hover_destroy end
-- create iconbox -- create iconbox
local iconbox = nil local iconbox = nil
@ -344,7 +343,6 @@ function notify(args)
end end
iconbox.resize = false iconbox.resize = false
iconbox.image = img iconbox.image = img
if hover_timeout then iconbox.mouse_enter = hover_destroy end
end end
end end
@ -354,6 +352,8 @@ function notify(args)
border_color = border_color, border_color = border_color,
border_width = border_width }) border_width = border_width })
if hover_timeout then notification.box:add_signal("mouse::enter", hover_destroy) end
-- calculate the height -- calculate the height
if not height then if not height then
if iconbox and iconbox:extents().height > textbox:extents().height then if iconbox and iconbox:extents().height > textbox:extents().height then

View File

@ -46,8 +46,6 @@ struct widget_t
int (*index)(lua_State *, awesome_token_t); int (*index)(lua_State *, awesome_token_t);
/** Newindex function */ /** Newindex function */
int (*newindex)(lua_State *, awesome_token_t); int (*newindex)(lua_State *, awesome_token_t);
/** Mouse over event handler */
void *mouse_enter, *mouse_leave;
/** Misc private data */ /** Misc private data */
void *data; void *data;
/** Button bindings */ /** Button bindings */