aboutsummaryrefslogtreecommitdiff
path: root/config.dot/awesome.link/widgets/volume.lua
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-05-01 16:10:07 -0300
committerSilvio Rhatto <rhatto@riseup.net>2017-05-01 16:10:07 -0300
commite5b1984f0e868a29fc2b171bb8d672d5e202f844 (patch)
treea810e67b30cd63a4fd3ef27402588a689c61dbc1 /config.dot/awesome.link/widgets/volume.lua
parentcf0613ba5eb07467bd641b4c0ccbe603d71d89cc (diff)
downloadawesome-e5b1984f0e868a29fc2b171bb8d672d5e202f844.tar.gz
awesome-e5b1984f0e868a29fc2b171bb8d672d5e202f844.tar.bz2
Create a widgets folder
Diffstat (limited to 'config.dot/awesome.link/widgets/volume.lua')
-rw-r--r--config.dot/awesome.link/widgets/volume.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/config.dot/awesome.link/widgets/volume.lua b/config.dot/awesome.link/widgets/volume.lua
new file mode 100644
index 0000000..c183cb9
--- /dev/null
+++ b/config.dot/awesome.link/widgets/volume.lua
@@ -0,0 +1,34 @@
+-- See http://awesome.naquadah.org/wiki/Volume_control_and_display
+volume_widget = widget({ type = "textbox", name = "tb_volume",
+ 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 = volume * (er - sr) + sr
+ local ig = volume * (eg - sg) + sg
+ local ib = 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.text = volume
+ end
+
+volumeTimer = timer({ timeout = 1 })
+volumeTimer:add_signal("timeout", function () update_volume(volume_widget) end)
+volumeTimer:start()