-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.lua
145 lines (129 loc) · 3.6 KB
/
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
-- This project is licensed under the MIT License (see LICENSE).
--- Widget to show pending clients.
--
-- @author James Reed <[email protected]>
-- @copyright 2019-2020 James Reed
-- @module awesome-launch.widget
local awful = require("awful")
local gears = require("gears")
local wibox = require("wibox")
local beautiful = require("beautiful")
local dpi = require("beautiful.xresources").apply_dpi
local shared = require("awesome-launch.shared")
local widgets = {}
local widget = {}
local function props_visible(s, p)
if p.screen and p.screen ~= s then
return false
end
local function selected(t)
if gears.table.hasitem(s.selected_tags, t) then
return true
end
end
if p.first_tag then
return selected(p.first_tag)
end
if p.tag then
return selected(p.tag)
end
if p.tags then
for _, t in ipairs(p.tags) do
if selected(t) then
return true
end
end
end
end
local function update_widget(w)
w.widget:reset()
for _, data in pairs(shared.pending) do
local visible = true
if w.only_tagged then
visible = props_visible(w.screen or awful.screen.focused(),
data.props)
end
if visible and (not w.filter or w.filter(data)) then
w.widget:add(data.widget)
end
end
end
function widget.update_widgets()
for _, w in ipairs(widgets) do
update_widget(w)
end
end
function widget.new(cmd, data)
return wibox.widget {
{
{
{
id = "id_progress",
min_value = 0,
max_value = data.timeout,
value = data.timeout,
color = widget.color or beautiful.bg_normal,
border_color = widget.border_color or beautiful.fg_normal,
widget = wibox.container.radialprogressbar,
},
id = "id_margin",
margins = widget.margins or dpi(2),
layout = wibox.container.margin,
},
id = "id_const",
width = widget.width or beautiful.wibar_height or dpi(20),
layout = wibox.container.constraint,
},
{
text = cmd,
widget = wibox.widget.textbox,
},
layout = wibox.layout.fixed.horizontal,
}
end
function widget.active()
return #widgets > 0
end
--- Create a new launchbar widget.
--
-- The following options are available to customize the widget's
-- radialprogressbar:
--
-- launch.widget.color
--
-- launch.widget.border_color
--
-- launch.widget.width
--
-- launch.widget.margins
--
-- @param args Table containing widget options
-- @param args.screen The screen pending clients must belong to.
-- @param args.filter Function to filter clients that are considered.
-- @param args.only_tagged Show only pending clients with selected tags.
-- @return The widget.
-- @function launch.widget.launchbar
function widget.launchbar(args)
args = args or {}
local w = {
screen = args.screen,
filter = args.filter,
only_tagged = true,
widget = wibox.widget {
layout = wibox.layout.fixed.horizontal,
},
}
if args.only_tagged == false then
w.only_tagged = false
end
if w.only_tagged and w.screen then
screen.connect_signal("tag::history::update", function (s)
if s == w.screen then
update_widget(w)
end
end)
end
table.insert(widgets, w)
return w.widget
end
return widget