-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup_widget.lua
59 lines (45 loc) · 1.31 KB
/
popup_widget.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
--- A wrapper for awful.menu that wraps a widget in a popup menu
local awful = require("awful")
local wibox = require("wibox")
local timeout = require("nifty.timeout")
local popup_widget = {}
popup_widget.__index = popup_widget
function popup_widget:show(...)
if self._private.timeout then
self._private.timeout:start_timeout()
end
self._private.menu:show(...)
end
function popup_widget:hide(...)
if self._private.timeout then
self._private.timeout:stop_timeout()
end
self._private.menu:hide(...)
end
function popup_widget:toggle(...)
if self._private.menu.wibox.visible then
self:hide(...)
else
self:show(...)
end
end
function popup_widget.new(widget, args)
local self = setmetatable({}, popup_widget)
self._private = {}
self._private.menu = awful.menu{ theme = args.theme }
local wrapper = wibox.container.background(widget)
if args.timeout then
self._private.timeout = timeout(args.timeout, wrapper, function() self:hide() end)
end
local function make_menu()
return {akey = nil, widget = wrapper, cmd = nil}
end
self._private.menu:add({ new = make_menu })
return self
end
setmetatable(popup_widget, {
__call = function(cls, ...)
return cls.new(...)
end
})
return popup_widget