-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvolume.lua
52 lines (39 loc) · 1.28 KB
/
volume.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
local wibox = require("wibox")
local awful = require("awful")
local helpers = require("./helpers")
local lain = require("lain")
markup = lain.util.markup
local widget = {}
-- {{{ Define subwidgets
widget.text = wibox.widget.textbox()
-- Change the draw method so icons can be drawn smaller
--helpers:set_draw_method(widget.text)
-- }}}
-- {{{ Define interactive behaviour
--widget.text:buttons(awful.util.table.join(
--awful.button({ }, 1, function () awful.util.spawn("gnome-control-center sound") end)
--))
-- }}}
-- {{{ Update method
function widget:update()
local fd = io.popen("amixer sget Master")
local status = fd:read("*all")
fd:close()
local volume = tonumber(string.match(status, "(%d?%d?%d)%%")) or 0
if string.find(status, "[off]", 1, true) or volume <= 0.0 then
if string.find(status, "[off]", 1, true) then
widget.text:set_markup(markup("#ff0000"," mute"))
end
elseif volume < 25 then
widget.text:set_markup(markup("#00ff00"," " .. volume .. "%"))
elseif volume > 45 then
widget.text:set_markup(markup("#00ff00"," " .. volume .. "%"))
else
widget.text:set_markup(markup("#00ff00"," " .. volume .. "%"))
end
end
-- }}}
-- {{{ Listen
helpers:listen(widget)
-- }}}
return widget