awesome-wm-widgets/VolumeWidget/volume.lua

34 lines
1.2 KiB
Lua
Raw Normal View History

2015-07-13 22:56:52 +02:00
local wibox = require("wibox")
local awful = require("awful")
2015-07-13 23:07:30 +02:00
volume_widget = wibox.widget.imagebox()
2015-07-13 22:56:52 +02:00
2015-07-13 23:07:30 +02:00
function update_volume(widget)
2015-07-13 22:56:52 +02:00
local fd = io.popen("amixer -D pulse sget Master")
local status = fd:read("*all")
fd:close()
local volume = string.match(status, "(%d?%d?%d)%%")
volume = tonumber(string.format("% 3d", volume))
status = string.match(status, "%[(o[^%]]*)%]")
if (volume >= 0 and volume < 10) then volumeLevel=1
elseif (volume >= 10 and volume < 20) then volumeLevel=2
elseif (volume >= 20 and volume < 30) then volumeLevel=3
elseif (volume >= 30 and volume < 40) then volumeLevel=4
elseif (volume >= 40 and volume < 50) then volumeLevel=5
elseif (volume >= 50 and volume < 60) then volumeLevel=6
elseif (volume >= 60 and volume < 70) then volumeLevel=7
elseif (volume >= 70 and volume < 80) then volumeLevel=8
elseif (volume >= 80 and volume <= 100) then volumeLevel=9
end
2015-07-13 23:07:30 +02:00
widget:set_image("/home/pashik/.config/awesome/volume-icons/" .. volumeLevel .. ".png")
2015-07-13 22:56:52 +02:00
end
2015-07-13 23:07:30 +02:00
update_volume(volume_widget)
2015-07-13 22:56:52 +02:00
mytimer = timer({ timeout = 0.2 })
2015-07-13 23:07:30 +02:00
mytimer:connect_signal("timeout", function () update_volume(volume_widget) end)
2015-07-13 22:56:52 +02:00
mytimer:start()