widget: emit signals on mouse enter and leave
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
59c991ace0
commit
9c40168f02
33
event.c
33
event.c
|
@ -351,24 +351,18 @@ event_handle_widget_motionnotify(void *object,
|
|||
{
|
||||
if(*mouse_over)
|
||||
{
|
||||
if((*mouse_over)->mouse_leave)
|
||||
{
|
||||
/* call mouse leave function on old widget */
|
||||
luaA_object_push(globalconf.L, *mouse_over);
|
||||
luaA_object_push_item(globalconf.L, -1, (*mouse_over)->mouse_leave);
|
||||
luaA_dofunction(globalconf.L, 1, 0);
|
||||
}
|
||||
/* call mouse leave function on old widget */
|
||||
luaA_object_push(globalconf.L, *mouse_over);
|
||||
luaA_object_emit_signal(globalconf.L, -1, "mouse::leave", 0);
|
||||
lua_pop(globalconf.L, 1);
|
||||
}
|
||||
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;
|
||||
if(widget->mouse_enter)
|
||||
{
|
||||
luaA_object_push(globalconf.L, widget);
|
||||
luaA_object_push_item(globalconf.L, -1, widget->mouse_enter);
|
||||
luaA_dofunction(globalconf.L, 1, 0);
|
||||
}
|
||||
luaA_object_push(globalconf.L, widget);
|
||||
luaA_object_emit_signal(globalconf.L, -1, "mouse::enter", 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->mouse_leave)
|
||||
{
|
||||
/* call mouse leave function on widget the mouse was over */
|
||||
luaA_object_push(globalconf.L, wibox->mouse_over);
|
||||
luaA_object_push_item(globalconf.L, -1, wibox->mouse_over->mouse_leave);
|
||||
luaA_dofunction(globalconf.L, 1, 0);
|
||||
}
|
||||
luaA_object_push(globalconf.L, wibox->mouse_over);
|
||||
/* emit mouse::leave signal on widget the mouse was over */
|
||||
luaA_object_emit_signal(globalconf.L, -1, "mouse::leave", 0);
|
||||
lua_pop(globalconf.L, 1);
|
||||
wibox->mouse_over = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -202,8 +202,10 @@ local function add_item(data, num, item_info)
|
|||
|
||||
item:buttons(bindings)
|
||||
|
||||
function label.mouse_enter() item_enter(data, num, true) end
|
||||
function item.mouse_enter() item_enter(data, num, true) end
|
||||
local mouse_enter_func = function () 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
|
||||
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:buttons(bindings)
|
||||
|
||||
function submenu.mouse_enter() item_enter(data, num, true) end
|
||||
submenu:add_signal("mouse::enter", mouse_enter_func)
|
||||
end
|
||||
|
||||
-- Add widgets to the wibox
|
||||
|
|
|
@ -33,8 +33,10 @@ function new(args)
|
|||
local w = capi.widget(args)
|
||||
w.image = img_release
|
||||
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
|
||||
function w.mouse_enter(s) if capi.mouse.coords().buttons[1] then w.image = img_press end end
|
||||
w:add_signal("mouse::leave", function () w.image = img_release end)
|
||||
w:add_signal("mouse::enter", function ()
|
||||
if capi.mouse.coords().buttons[1] then w.image = img_press end
|
||||
end)
|
||||
return w
|
||||
end
|
||||
|
||||
|
|
|
@ -319,7 +319,6 @@ function notify(args)
|
|||
textbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
|
||||
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)
|
||||
if hover_timeout then textbox.mouse_enter = hover_destroy end
|
||||
|
||||
-- create iconbox
|
||||
local iconbox = nil
|
||||
|
@ -344,7 +343,6 @@ function notify(args)
|
|||
end
|
||||
iconbox.resize = false
|
||||
iconbox.image = img
|
||||
if hover_timeout then iconbox.mouse_enter = hover_destroy end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -354,6 +352,8 @@ function notify(args)
|
|||
border_color = border_color,
|
||||
border_width = border_width })
|
||||
|
||||
if hover_timeout then notification.box:add_signal("mouse::enter", hover_destroy) end
|
||||
|
||||
-- calculate the height
|
||||
if not height then
|
||||
if iconbox and iconbox:extents().height > textbox:extents().height then
|
||||
|
|
Loading…
Reference in New Issue