feat(awful: widget: calendar_popup: attach): implement 'on_hover' option (#2008)

* feat(awful: widget: calendar_popup: attach): implement 'on_hover' option

* feat(awful: widget: calendar_popup): smarter handling of click and hover at the same time
This commit is contained in:
Yauhen Kirylau 2017-08-27 21:01:24 +02:00 committed by GitHub
parent fd66d12a4b
commit 9e4446060e
1 changed files with 23 additions and 3 deletions

View File

@ -247,17 +247,37 @@ end
-- --
-- @param widget Widget to attach the calendar -- @param widget Widget to attach the calendar
-- @tparam[opt="tr"] string position Two characters string defining the position on the screen -- @tparam[opt="tr"] string position Two characters string defining the position on the screen
-- @tparam[opt={}] table args Additional options
-- @tparam[opt=true] bool args.on_hover Show popup during mouse hover
-- @treturn wibox The wibox calendar -- @treturn wibox The wibox calendar
function calendar_popup:attach(widget, position) function calendar_popup:attach(widget, position, args)
position = position or "tr" position = position or "tr"
args = args or {}
if args.on_hover == nil then args.on_hover=true end
widget:buttons(gears.table.join( widget:buttons(gears.table.join(
abutton({ }, 1, function () abutton({ }, 1, function ()
if not self.visible or self._calendar_clicked then
self:call_calendar(0, position) self:call_calendar(0, position)
self.visible = not self.visible self.visible = not self.visible
end
self._calendar_clicked = self.visible
end), end),
abutton({ }, 4, function () self:call_calendar(-1) end), abutton({ }, 4, function () self:call_calendar(-1) end),
abutton({ }, 5, function () self:call_calendar( 1) end) abutton({ }, 5, function () self:call_calendar( 1) end)
)) ))
if args.on_hover then
widget:connect_signal("mouse::enter", function ()
if not self._calendar_clicked then
self:call_calendar(0, position)
self.visible = true
end
end)
widget:connect_signal("mouse::leave", function ()
if not self._calendar_clicked then
self.visible = false
end
end)
end
return self return self
end end