forked from mokasin/apw
-
Notifications
You must be signed in to change notification settings - Fork 1
/
widget.lua
109 lines (88 loc) · 2.9 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
-- Copyright 2013 mokasin
-- This file is part of the Awesome Pulseaudio Widget (APW).
--
-- APW is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- APW is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with APW. If not, see <http://www.gnu.org/licenses/>.
-- Configuration variables
local width = 40 -- width in pixels of progressbar
local margin_right = 0 -- right margin in pixels of progressbar
local margin_left = 0 -- left margin in pixels of progressbar
local margin_top = 0 -- top margin in pixels of progressbar
local margin_bottom = 0 -- bottom margin in pixels of progressbar
local step = 0.05 -- stepsize for volume change (ranges from 0 to 1)
local color = '#698f1e' -- foreground color of progessbar
local color_bg = '#33450f' -- background color
local color_mute = '#be2a15' -- foreground color when muted
local color_bg_mute = '#532a15' -- background color when muted
local mixer = 'pavucontrol' -- mixer command
-- End of configuration
local awful = require("awful")
local wibox = require("wibox")
local pulseaudio = require("apw.pulseaudio")
local p = pulseaudio:Create()
local pulseBar = awful.widget.progressbar()
local pulseWidget = pulseBar
pulseBar:set_width(width)
pulseBar.step = step
awful.widget.layout.margins[pulseBar.widget] = {
right = margin_right,
left = margin_left,
top = margin_top,
bottom = margin_bottom
}
function pulseWidget.setColor(mute)
if mute then
pulseBar:set_color(color_mute)
pulseBar:set_background_color(color_bg_mute)
else
pulseBar:set_color(color)
pulseBar:set_background_color(color_bg)
end
end
local function _update()
pulseBar:set_value(p.Volume)
pulseWidget.setColor(p.Mute)
end
function pulseWidget.SetMixer(command)
mixer = command
end
function pulseWidget.Up()
p:SetVolume(p.Volume + pulseBar.step)
_update()
end
function pulseWidget.Down()
p:SetVolume(p.Volume - pulseBar.step)
_update()
end
function pulseWidget.ToggleMute()
p:ToggleMute()
_update()
end
function pulseWidget.Update()
p:UpdateState()
_update()
end
function pulseWidget.LaunchMixer()
awful.util.spawn_with_shell( mixer )
end
-- register mouse button actions
pulseBar.widget:buttons(awful.util.table.join(
awful.button({ }, 1, pulseWidget.ToggleMute),
awful.button({ }, 3, pulseWidget.LaunchMixer),
awful.button({ }, 4, pulseWidget.Up),
awful.button({ }, 5, pulseWidget.Down)
)
)
-- initialize
_update()
return pulseWidget