externalize config of volume widget
This commit is contained in:
parent
dbee6f75f7
commit
0999de2bfd
|
@ -1,10 +1,18 @@
|
||||||
# Volume widget
|
# 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)
|
./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.
|
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
|
## Installation
|
||||||
|
|
||||||
- clone/copy **volume.lua** file;
|
- clone/copy **volume.lua** file;
|
||||||
|
@ -18,7 +26,7 @@ s.mytasklist, -- Middle widget
|
||||||
{ -- Right widgets
|
{ -- Right widgets
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
...
|
...
|
||||||
volume_widget,
|
volume_widget(),
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -35,9 +43,12 @@ s.mytasklist, -- Middle widget
|
||||||
|
|
||||||
Try running this command:
|
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:
|
If that prints something like this, then the default setting of 'pulse' is probably fine:
|
||||||
|
|
||||||
```
|
```
|
||||||
Simple mixer control 'Master',0
|
Simple mixer control 'Master',0
|
||||||
Capabilities: pvolume pvolume-joined pswitch pswitch-joined
|
Capabilities: pvolume pvolume-joined pswitch pswitch-joined
|
||||||
|
@ -48,13 +59,22 @@ Simple mixer control 'Master',0
|
||||||
```
|
```
|
||||||
|
|
||||||
If it prints something like this:
|
If it prints something like this:
|
||||||
```
|
|
||||||
|
```bash
|
||||||
$ amixer -D pulse sget Master
|
$ amixer -D pulse sget Master
|
||||||
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
|
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
|
||||||
|
|
||||||
amixer: Mixer attach pulse error: 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
|
## Control volume
|
||||||
|
|
||||||
|
|
|
@ -13,23 +13,28 @@ local wibox = require("wibox")
|
||||||
local watch = require("awful.widget.watch")
|
local watch = require("awful.widget.watch")
|
||||||
local spawn = require("awful.spawn")
|
local spawn = require("awful.spawn")
|
||||||
|
|
||||||
local secrets = require("awesome-wm-widgets.secrets")
|
|
||||||
|
|
||||||
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
|
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
|
||||||
|
|
||||||
if secrets.volume_audio_controller == 'pulse' then
|
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'
|
device_arg = '-D pulse'
|
||||||
else
|
end
|
||||||
device_arg = ''
|
|
||||||
end
|
|
||||||
|
|
||||||
local GET_VOLUME_CMD = 'amixer ' .. device_arg .. ' sget Master'
|
local GET_VOLUME_CMD = 'amixer ' .. device_arg .. ' sget Master'
|
||||||
local INC_VOLUME_CMD = 'amixer ' .. device_arg .. ' sset Master 5%+'
|
local INC_VOLUME_CMD = 'amixer ' .. device_arg .. ' sset Master 5%+'
|
||||||
local DEC_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 TOG_VOLUME_CMD = 'amixer ' .. device_arg .. ' sset Master toggle'
|
||||||
|
|
||||||
|
|
||||||
local volume_widget = wibox.widget {
|
volume_widget = wibox.widget {
|
||||||
{
|
{
|
||||||
id = "icon",
|
id = "icon",
|
||||||
image = path_to_icons .. "audio-volume-muted-symbolic.svg",
|
image = path_to_icons .. "audio-volume-muted-symbolic.svg",
|
||||||
|
@ -40,9 +45,9 @@ local volume_widget = wibox.widget {
|
||||||
set_image = function(self, path)
|
set_image = function(self, path)
|
||||||
self.icon.image = path
|
self.icon.image = path
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
local update_graphic = function(widget, stdout, _, _, _)
|
local update_graphic = function(widget, stdout, _, _, _)
|
||||||
local mute = string.match(stdout, "%[(o%D%D?)%]")
|
local mute = string.match(stdout, "%[(o%D%D?)%]")
|
||||||
local volume = string.match(stdout, "(%d?%d?%d)%%")
|
local volume = string.match(stdout, "(%d?%d?%d)%%")
|
||||||
volume = tonumber(string.format("% 3d", volume))
|
volume = tonumber(string.format("% 3d", volume))
|
||||||
|
@ -54,13 +59,13 @@ local update_graphic = function(widget, stdout, _, _, _)
|
||||||
elseif (volume <= 100) then volume_icon_name="audio-volume-high-symbolic"
|
elseif (volume <= 100) then volume_icon_name="audio-volume-high-symbolic"
|
||||||
end
|
end
|
||||||
widget.image = path_to_icons .. volume_icon_name .. ".svg"
|
widget.image = path_to_icons .. volume_icon_name .. ".svg"
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[ allows control volume level by:
|
--[[ allows control volume level by:
|
||||||
- clicking on the widget to mute/unmute
|
- clicking on the widget to mute/unmute
|
||||||
- scrolling when cursor is over the widget
|
- scrolling when cursor is over the widget
|
||||||
]]
|
]]
|
||||||
volume_widget:connect_signal("button::press", function(_,_,_,button)
|
volume_widget:connect_signal("button::press", function(_,_,_,button)
|
||||||
if (button == 4) then awful.spawn(INC_VOLUME_CMD, false)
|
if (button == 4) then awful.spawn(INC_VOLUME_CMD, false)
|
||||||
elseif (button == 5) then awful.spawn(DEC_VOLUME_CMD, false)
|
elseif (button == 5) then awful.spawn(DEC_VOLUME_CMD, false)
|
||||||
elseif (button == 1) then awful.spawn(TOG_VOLUME_CMD, false)
|
elseif (button == 1) then awful.spawn(TOG_VOLUME_CMD, false)
|
||||||
|
@ -69,8 +74,11 @@ volume_widget:connect_signal("button::press", function(_,_,_,button)
|
||||||
spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode)
|
spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode)
|
||||||
update_graphic(volume_widget, stdout, stderr, exitreason, exitcode)
|
update_graphic(volume_widget, stdout, stderr, exitreason, exitcode)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
watch(GET_VOLUME_CMD, 1, update_graphic, volume_widget)
|
watch(GET_VOLUME_CMD, 1, update_graphic, volume_widget)
|
||||||
|
|
||||||
return volume_widget
|
return volume_widget
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(volume_widget, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Volumearc widget
|
# 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)
|
![screenshot](out.gif)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue