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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
local awful = require("awful")
local wibox = require("wibox")
local beautiful = require("beautiful")
local apply_dpi = beautiful.xresources.apply_dpi
local pavolctld = require("lib.pavolctld")
-- return table
local widget = {}
widget.dbmeter = wibox.widget.textbox("-999.99 dB") -- max width text
local dbmeter_maxwidth, _ = widget.dbmeter:get_preferred_size_at_dpi(beautiful.xresources.get_dpi()) -- max width, TODO per screen dpi
dbmeter_maxwidth = dbmeter_maxwidth * 1.5 -- ???
local slider = wibox.widget {
bar_height = 0,
widget = wibox.widget.slider,
maximum = pavolctld.max_volume,
}
local progressbar = wibox.widget {
max_value = pavolctld.max_volume,
shape = beautiful.slider_bar_shape,
bg = beautiful.slider_handle_color,
widget = wibox.widget.progressbar,
}
widget.vslider = wibox.widget {
{
{
progressbar,
height = apply_dpi(3),
widget = wibox.container.constraint
},
halign = "center",
widget = wibox.container.place,
},
slider,
layout = wibox.layout.stack,
}
-- scrollbox for default sink select
widget.defsink = wibox.widget.textbox()
local default_sink_scrollbox = wibox.widget {
widget.defsink,
step_function = wibox.container.scroll.step_functions.linear_increase,
speed = apply_dpi(15),
extra_space = apply_dpi(25), -- space between repetition
pause = true, -- start paused
widget = wibox.container.scroll.horizontal,
}
local muted = wibox.widget {
color = "#222222",
check_color = beautiful.border_focus,
forced_width = apply_dpi(20),
widget = wibox.widget.checkbox,
}
-- widget dropdown
local volume_dropdown = wibox.widget {
{
{
{
default_sink_scrollbox,
margins = beautiful.margin_topbottom,
widget = wibox.container.margin,
},
bg = "#333333",
widget = wibox.container.background,
},
margins = beautiful.border_width,
color = "#222222",
widget = wibox.container.margin,
},
{
{
{
{
{
text = "Mute:",
widget = wibox.widget.textbox,
},
left = apply_dpi(5),
right = apply_dpi(5),
widget = wibox.container.margin,
},
fill_vertical = true,
widget = wibox.container.place,
},
{
muted,
fill_vertical = true,
widget = wibox.container.place,
},
layout = wibox.layout.align.horizontal,
},
fill_vertical = true,
widget = wibox.container.place,
},
widget.vslider,
{
widget.dbmeter,
halign = "right",
forced_width = dbmeter_maxwidth,
widget = wibox.container.place,
},
forced_num_cols = 2,
forced_num_rows = 2,
homogeneous = false,
expand = true,
forced_width = apply_dpi(300),
forced_height = apply_dpi(60),
layout = wibox.layout.grid,
}
widget.dropdown = awful.popup {
widget = {
volume_dropdown,
left = beautiful.margin_leftright,
right = beautiful.margin_leftright,
top = beautiful.margin_topbottom,
bottom = beautiful.margin_topbottom,
widget = wibox.container.margin,
},
border_color = beautiful.border_normal,
border_width = beautiful.border_width,
ontop = true,
hide_on_right_click = true,
preferred_positions = "bottom",
preferred_anchors = "back",
visible = false,
}
function widget.set_volume(vol, mute)
progressbar:set_value(vol)
muted.checked = mute
if vol == slider.value then return end
slider.value = vol
if widget.dropdown.visible then
slider:emit_signal("widget::redraw_needed")
end
end
-- slider
slider:buttons(volume_buttons)
slider:connect_signal("property::value", function()
if pavolctld.sinks.default.vol == slider.value then return end
widget.dropdown.visible = true -- make sure widget isn't hidden
pavolctld.volume_set(slider.value)
end)
-- scroll when hovering
default_sink_scrollbox:connect_signal("mouse::enter", function()
default_sink_scrollbox:continue()
end)
default_sink_scrollbox:connect_signal("mouse::leave", function()
default_sink_scrollbox:pause()
default_sink_scrollbox:reset_scrolling()
end)
-- change sink
default_sink_scrollbox:connect_signal("button::press", function()
widget.dropdown.visible = true -- make sure widget isn't hidden
local g = mouse.current_widget_geometry -- relative to widget.dropdown
local menugeo = {
x = widget.dropdown.x + g.x - beautiful.margin_topbottom,
y = widget.dropdown.y + g.y + g.height + beautiful.margin_topbottom + (beautiful.border_width * 2),
width = g.width + beautiful.margin_topbottom * 2,
}
local menuopts = { items = {}, theme = menugeo }
for i, s in pairs(pavolctld.sinks.sinks) do
table.insert(menuopts.items, {
s.desc,
function() pavolctld.default_sink_set(i) end
})
end
if widget.menu then widget.menu:hide() end
widget.menu = awful.menu(menuopts) -- old menu dereferenced, should be cleaned up by gc
widget.menu:show({ coords = menugeo })
end)
widget.dropdown:connect_signal("property::visible", function()
if widget.menu then
widget.menu:hide()
widget.menu = nil
end
end)
-- mute button
muted:connect_signal("button::press", function()
widget.dropdown.visible = true -- make sure widget isn't hidden
pavolctld.mute_toggle()
end)
return widget
|