summaryrefslogtreecommitdiff
path: root/volume-widget/volume.lua
diff options
context:
space:
mode:
authorPavel Makhov <pmakhov@theoctavegroup.com>2019-09-17 15:29:36 -0400
committerPavel Makhov <pmakhov@theoctavegroup.com>2019-09-17 15:29:36 -0400
commit6fd76c254b296da86619b43db619ccebcd521853 (patch)
treea005c8045bbee2998642c55fd5edadb258ea87de /volume-widget/volume.lua
parent372ae3c9e7cab4b64b8dcaf31d9d2d921a723585 (diff)
parent2e211937a116102c3647b85070718102192ddc54 (diff)
Merge branch '74-externalize-config'
Note: breaking change, now widgets should be created with parentheses, i.e. battery(), instead of battery. Read more in README of the widget.
Diffstat (limited to 'volume-widget/volume.lua')
-rw-r--r--volume-widget/volume.lua103
1 files changed, 60 insertions, 43 deletions
diff --git a/volume-widget/volume.lua b/volume-widget/volume.lua
index 8124bcf..6172f5e 100644
--- a/volume-widget/volume.lua
+++ b/volume-widget/volume.lua
@@ -15,53 +15,70 @@ local spawn = require("awful.spawn")
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
-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 volume_widget = wibox.widget {
- {
- id = "icon",
- image = path_to_icons .. "audio-volume-muted-symbolic.svg",
- resize = false,
- widget = wibox.widget.imagebox,
- },
- layout = wibox.container.margin(_, _, _, 3),
- set_image = function(self, path)
- self.icon.image = path
- end
-}
-
-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))
- local volume_icon_name
- if mute == "off" then volume_icon_name="audio-volume-muted-symbolic_red"
- elseif (volume >= 0 and volume < 25) then volume_icon_name="audio-volume-muted-symbolic"
- elseif (volume < 50) then volume_icon_name="audio-volume-low-symbolic"
- elseif (volume < 75) then volume_icon_name="audio-volume-medium-symbolic"
- elseif (volume <= 100) then volume_icon_name="audio-volume-high-symbolic"
+local volume_widget = {}
+
+local function worker(args)
+
+ local args = args or {}
+
+ local volume_audio_controller = args.volume_audio_controller or 'pulse'
+
+ local device_arg = ''
+ if volume_audio_controller == 'pulse' then
+ device_arg = '-D pulse'
end
- widget.image = path_to_icons .. volume_icon_name .. ".svg"
-end
---[[ allows control volume level by:
-- clicking on the widget to mute/unmute
-- scrolling when cursor is over the widget
-]]
-volume_widget: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)
+ local GET_VOLUME_CMD = 'amixer ' .. device_arg .. ' sget Master'
+ local INC_VOLUME_CMD = 'amixer ' .. device_arg .. ' sset Master 5%+'
+ local DEC_VOLUME_CMD = 'amixer ' .. device_arg .. ' sset Master 5%-'
+ local TOG_VOLUME_CMD = 'amixer ' .. device_arg .. ' sset Master toggle'
+
+
+ volume_widget = wibox.widget {
+ {
+ id = "icon",
+ image = path_to_icons .. "audio-volume-muted-symbolic.svg",
+ resize = false,
+ widget = wibox.widget.imagebox,
+ },
+ layout = wibox.container.margin(_, _, _, 3),
+ set_image = function(self, path)
+ self.icon.image = path
+ end
+ }
+
+ 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))
+ local volume_icon_name
+ if mute == "off" then volume_icon_name="audio-volume-muted-symbolic_red"
+ elseif (volume >= 0 and volume < 25) then volume_icon_name="audio-volume-muted-symbolic"
+ elseif (volume < 50) then volume_icon_name="audio-volume-low-symbolic"
+ elseif (volume < 75) then volume_icon_name="audio-volume-medium-symbolic"
+ elseif (volume <= 100) then volume_icon_name="audio-volume-high-symbolic"
+ end
+ widget.image = path_to_icons .. volume_icon_name .. ".svg"
end
- spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode)
- update_graphic(volume_widget, stdout, stderr, exitreason, exitcode)
+ --[[ allows control volume level by:
+ - clicking on the widget to mute/unmute
+ - scrolling when cursor is over the widget
+ ]]
+ volume_widget: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)
+ end
+
+ spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode)
+ update_graphic(volume_widget, stdout, stderr, exitreason, exitcode)
+ end)
end)
-end)
-watch(GET_VOLUME_CMD, 1, update_graphic, volume_widget)
+ watch(GET_VOLUME_CMD, 1, update_graphic, volume_widget)
+
+ return volume_widget
+end
-return volume_widget \ No newline at end of file
+return setmetatable(volume_widget, { __call = function(_, ...) return worker(...) end })