summaryrefslogtreecommitdiff
path: root/config/awesome/volume.lua
blob: 4d491df7384d642ec7fabe9a99af12558ae4f21f (plain)
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
-- from https://awesome.naquadah.org/wiki/Volume_control_and_display
-- 2016-12-13

--local wibox = require("wibox")
--local awful = require("awful")
--
--volume_widget = wibox.widget.textbox()
--volume_widget:set_align("right")
--
--function update_volume(widget)
--   local fd = io.popen("amixer sget Master")
--   local status = fd:read("*all")
--   fd:close()
--
--   local volume = tonumber(string.match(status, "(%d?%d?%d)%%")) / 100
--   -- volume = string.format("% 3d", volume)
--
--   status = string.match(status, "%[(o[^%]]*)%]")
--
--   -- starting colour
--   local sr, sg, sb = 0x3F, 0x3F, 0x3F
--   -- ending colour
--   local er, eg, eb = 0xDC, 0xDC, 0xCC
--
--   local ir = math.floor(volume * (er - sr) + sr)
--   local ig = math.floor(volume * (eg - sg) + sg)
--   local ib = math.floor(volume * (eb - sb) + sb)
--   interpol_colour = string.format("%.2x%.2x%.2x", ir, ig, ib)
--   if string.find(status, "on", 1, true) then
--       volume = " <span background='#" .. interpol_colour .. "'>   </span>"
--   else
--       volume = " <span color='red' background='#" .. interpol_colour .. "'> M </span>"
--   end
--   widget:set_markup(volume)
--end
--
--update_volume(volume_widget)
--
--mytimer = timer({ timeout = 1 })
--mytimer:connect_signal("timeout", function () update_volume(volume_widget) end)
--mytimer:start()
local wibox = require("wibox")
local awful = require("awful")
 
volume_widget = wibox.widget.textbox()
volume_widget:set_align("right")
 
function update_volume(widget)
   local fd = io.popen("amixer sget Master")
   local status = fd:read("*all")
   fd:close()
 
   -- local volume = tonumber(string.match(status, "(%d?%d?%d)%%")) / 100
   local volume = string.match(status, "(%d?%d?%d)%%")
   volume = string.format("%02d", volume)
 
   status = string.match(status, "%[(o[^%]]*)%]")

   if string.find(status, "on", 1, true) then
       -- For the volume numbers
       note = '♬'
       volume = ' '..  note .. volume .. "%" .. " "
   else
       -- For the mute button
       -- rest = '𝄻'
       rest = '♬'
       volume = " <span color='red'>".. rest .. volume .. "%" .. "</span> "
   end
   widget:set_markup(volume)
end
 
update_volume(volume_widget)
 
-- mytimer = timer({ timeout = 0.2 })
-- mytimer:connect_signal("timeout", function () update_volume(volume_widget) end)
-- mytimer:start()

dbus.request_name("session", "com.ch1p.avm")
dbus.add_match("session", "interface='com.ch1p.avm',member='valueChanged'")
dbus.connect_signal("com.ch1p.avm", function()
        update_volume(volume_widget)
    end
)