From 9e4446060e85b56b362c7ccf94d5ca69ec61c86e Mon Sep 17 00:00:00 2001 From: Yauhen Kirylau Date: Sun, 27 Aug 2017 21:01:24 +0200 Subject: [PATCH] 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 --- lib/awful/widget/calendar_popup.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/awful/widget/calendar_popup.lua b/lib/awful/widget/calendar_popup.lua index a9d7961c..e204b10a 100644 --- a/lib/awful/widget/calendar_popup.lua +++ b/lib/awful/widget/calendar_popup.lua @@ -247,17 +247,37 @@ end -- -- @param widget Widget to attach the calendar -- @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 -function calendar_popup:attach(widget, position) +function calendar_popup:attach(widget, position, args) position = position or "tr" + args = args or {} + if args.on_hover == nil then args.on_hover=true end widget:buttons(gears.table.join( abutton({ }, 1, function () - self:call_calendar(0, position) - self.visible = not self.visible + if not self.visible or self._calendar_clicked then + self:call_calendar(0, position) + self.visible = not self.visible + end + self._calendar_clicked = self.visible end), abutton({ }, 4, 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 end