diff options
author | Peter Palfrader <peter@palfrader.org> | 2016-12-13 14:37:08 +0100 |
---|---|---|
committer | Peter Palfrader <peter@palfrader.org> | 2016-12-15 21:49:55 +0100 |
commit | 2b642e582ad79d54c195011f0d51f61f91966ac4 (patch) | |
tree | 29024288060fd5b6639081db121812d0b2562af3 /config/awesome/volume.lua | |
parent | ebbda18dfb774064e1151b0fcd354de24fe49202 (diff) |
volume control and more
Diffstat (limited to 'config/awesome/volume.lua')
-rw-r--r-- | config/awesome/volume.lua | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/config/awesome/volume.lua b/config/awesome/volume.lua new file mode 100644 index 0000000..bd1d1fb --- /dev/null +++ b/config/awesome/volume.lua @@ -0,0 +1,80 @@ +-- 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("% 3d", volume) + + status = string.match(status, "%[(o[^%]]*)%]") + + if string.find(status, "on", 1, true) then + -- For the volume numbers + volume = volume .. "%" + else + -- For the mute button + volume = "<span color='red'>" .. 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 +) |