summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--volume-widget/README.md30
-rw-r--r--volume-widget/volume.lua110
-rw-r--r--volumearc-widget/README.md2
3 files changed, 85 insertions, 57 deletions
diff --git a/volume-widget/README.md b/volume-widget/README.md
index 494be24..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(),
...
```
@@ -35,9 +43,12 @@ s.mytasklist, -- Middle widget
Try running this command:
-```amixer -D pulse sget Master```
+```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
@@ -48,13 +59,22 @@ Simple mixer control 'Master',0
```
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 try setting the environment variable `AWW_VOLUME_CONTROLLER` to `alsa_only`.
+then set `volume_audio_controller` to `alsa_only` in widget constructor:
+
+```lua
+volume_widget({
+ volume_audio_controller = 'alsa_only'
+})
+```
+
+.
## Control volume
diff --git a/volume-widget/volume.lua b/volume-widget/volume.lua
index 04f1c26..6172f5e 100644
--- a/volume-widget/volume.lua
+++ b/volume-widget/volume.lua
@@ -13,64 +13,72 @@ local wibox = require("wibox")
local watch = require("awful.widget.watch")
local spawn = require("awful.spawn")
-local secrets = require("awesome-wm-widgets.secrets")
-
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
-if secrets.volume_audio_controller == 'pulse' then
- device_arg = '-D pulse'
-else
- device_arg = ''
-end
+local volume_widget = {}
-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'
-
-
-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 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
+return setmetatable(volume_widget, { __call = function(_, ...) return worker(...) end })
diff --git a/volumearc-widget/README.md b/volumearc-widget/README.md
index 9f1a60e..0ae17b4 100644
--- a/volumearc-widget/README.md
+++ b/volumearc-widget/README.md
@@ -1,6 +1,6 @@
# Volumearc widget
-Almost the same as [volumebar widget](https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumebar-widget), but using arcchart:
+Almost the same as [volumebar widget](https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumebar-widget), but using [arcchart](https://awesomewm.org/doc/api/classes/wibox.container.arcchart.html):
![screenshot](out.gif)