awesome-wm-widgets/volumearc-widget/volumearc.lua

61 lines
2.0 KiB
Lua
Raw Normal View History

-------------------------------------------------
-- Volume Arc Widget for Awesome Window Manager
-- Shows the current volume level
-- More details could be found here:
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumearc-widget
-- @author Pavel Makhov
-- @copyright 2017 Pavel Makhov
-------------------------------------------------
2017-10-04 21:15:50 +02:00
local awful = require("awful")
2017-10-09 22:20:20 +02:00
local beautiful = require("beautiful")
2017-10-04 21:15:50 +02:00
local spawn = require("awful.spawn")
local watch = require("awful.widget.watch")
local wibox = require("wibox")
2017-10-09 22:20:20 +02:00
local GET_VOLUME_CMD = 'amixer -D pulse sget Master'
local INC_VOLUME_CMD = 'amixer -D pulse sset Master 5%+'
local DEC_VOLUME_CMD = 'amixer -D pulse sset Master 5%-'
local TOG_VOLUME_CMD = 'amixer -D pulse sset Master toggle'
local volumearc = wibox.widget {
2017-10-04 21:15:50 +02:00
max_value = 1,
thickness = 2,
start_angle = 4.71238898, -- 2pi*3/4
2017-10-09 22:20:20 +02:00
forced_height = 17,
forced_width = 17,
2017-10-04 21:15:50 +02:00
bg = "#ffffff11",
paddings = 2,
widget = wibox.container.arcchart
2017-10-04 21:15:50 +02:00
}
local volumearc_widget = wibox.container.mirror(volumearc, { horizontal = true })
2017-10-09 22:20:20 +02:00
2017-10-04 21:15:50 +02:00
local update_graphic = function(widget, stdout, _, _, _)
local mute = string.match(stdout, "%[(o%D%D?)%]")
local volume = string.match(stdout, "(%d?%d?%d)%%")
volume = tonumber(string.format("% 3d", volume))
2017-10-05 02:46:09 +02:00
widget.value = volume / 100;
2017-10-04 21:15:50 +02:00
if mute == "off" then
2017-10-09 22:20:20 +02:00
widget.colors = { beautiful.widget_red }
2017-10-04 21:15:50 +02:00
else
2017-10-09 22:20:20 +02:00
widget.colors = { beautiful.widget_main_color }
2017-10-04 21:15:50 +02:00
end
end
2017-10-09 22:20:20 +02:00
volumearc:connect_signal("button::press", function(_, _, _, button)
if (button == 4) then awful.spawn(INC_VOLUME_CMD, false)
elseif (button == 5) then awful.spawn(DEC_VOLUME_CMD, false)
elseif (button == 1) then awful.spawn(TOG_VOLUME_CMD, false)
2017-10-04 21:15:50 +02:00
end
2017-10-09 22:20:20 +02:00
spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode)
update_graphic(volumearc, stdout, stderr, exitreason, exitcode)
2017-10-04 21:15:50 +02:00
end)
end)
2017-10-09 22:20:20 +02:00
watch(GET_VOLUME_CMD, 1, update_graphic, volumearc)
return volumearc_widget