summaryrefslogtreecommitdiff
path: root/volume-widget
diff options
context:
space:
mode:
Diffstat (limited to 'volume-widget')
-rw-r--r--volume-widget/README.md49
-rw-r--r--volume-widget/volume.lua103
2 files changed, 107 insertions, 45 deletions
diff --git a/volume-widget/README.md b/volume-widget/README.md
index 118abc6..24c2d76 100644
--- a/volume-widget/README.md
+++ b/volume-widget/README.md
@@ -1,10 +1,18 @@
# Volume widget
-Simple and easy-to-install widget for Awesome Window Manager which represents the sound level: ![Volume Widget](
+Simple and easy-to-install widget for Awesome Window Manager which shows the sound level: ![Volume Widget](
./vol-widget-1.png)
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
+## Customization
+
+It is possible to customize widget by providing a table with all or some of the following config parameters:
+
+| Name | Default | Description |
+|---|---|---|
+| `volume_audio_controller` | `pulse` | audio device |
+
## Installation
- clone/copy **volume.lua** file;
@@ -18,7 +26,7 @@ s.mytasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
...
- volume_widget,
+ volume_widget(),
...
```
@@ -31,6 +39,43 @@ s.mytasklist, -- Middle widget
sudo sed -i 's/bebebe/ed4737/g' ./audio-volume-muted-symbolic_red.svg
```
+### Pulse or ALSA only
+
+Try running this command:
+
+```bash
+amixer -D pulse sget Master
+```
+
+If that prints something like this, then the default setting of 'pulse' is probably fine:
+
+```
+Simple mixer control 'Master',0
+ Capabilities: pvolume pvolume-joined pswitch pswitch-joined
+ Playback channels: Mono
+ Limits: Playback 0 - 64
+ Mono: Playback 64 [100%] [0.00dB] [on]
+
+```
+
+If it prints something like this:
+
+```bash
+$ amixer -D pulse sget Master
+ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
+
+amixer: Mixer attach pulse error: Connection refused
+```
+then set `volume_audio_controller` to `alsa_only` in widget constructor:
+
+```lua
+volume_widget({
+ volume_audio_controller = 'alsa_only'
+})
+```
+
+.
+
## Control volume
To mute/unmute click on the widget. To increase/decrease volume scroll up or down when mouse cursor is over the widget.
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 })