volumearc - externalize config

This commit is contained in:
streetturtle 2019-03-30 17:42:59 -04:00
parent 54924ef064
commit cf75c446e1
2 changed files with 87 additions and 51 deletions

View File

@ -2,24 +2,39 @@
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:
![screenshot](out.gif) ![screenshot]({{'/assets/img/screenshots/volumearc-widget.gif' | relative_url }}){:.center-image}
Supports:
- scroll up - increase volume,
- scroll down - decrease volume,
- left click - mute/unmute.
## Installation ## Installation
Clone repo, include widget and use it in **rc.lua**: 1. Clone this repo under **~/.config/awesome/**
```bash
git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/awesome/
```
1. Require volumearc widget at the beginning of **rc.lua**:
```lua
local volumearc_widget = require("awesome-wm-widgets.volumearc-widget.volumearc")
```
1. Add widget to the tasklist:
```lua ```lua
require("volumearc")
...
s.mytasklist, -- Middle widget s.mytasklist, -- Middle widget
{ -- Right widgets { -- Right widgets
layout = wibox.layout.fixed.horizontal, layout = wibox.layout.fixed.horizontal,
... ...
volumearc_widget, --[[default]]
volumearc_widget(),
--[[or customized]]
volumearc_widget({
main_color = '#0000ff',
mute_color = '#ff0000',
path_to_icon = '/usr/share/icons/Arc/actions/symbolic/view-grid-symbolic.svg',
thickness = 5,
height = 25
}),
... ...
``` ```

View File

@ -21,9 +21,27 @@ local TOG_VOLUME_CMD = 'amixer -D pulse sset Master toggle'
local PATH_TO_ICON = "/usr/share/icons/Arc/status/symbolic/audio-volume-muted-symbolic.svg" local PATH_TO_ICON = "/usr/share/icons/Arc/status/symbolic/audio-volume-muted-symbolic.svg"
local widget = {}
local function worker(args)
local args = args or {}
local main_color = args.main_color or beautiful.widget_main_color
local mute_color = args.mute_color or beautiful.widget_red
local path_to_icon = args.path_to_icon or PATH_TO_ICON
local thickness = args.thickness or 2
local height = args.height or 18
local get_volume_cmd = args.get_volume_cmd or GET_VOLUME_CMD
local inc_volume_cmd = args.inc_volume_cmd or INC_VOLUME_CMD
local dec_volume_cmd = args.dec_volume_cmd or DEC_VOLUME_CMD
local tog_volume_cmd = args.tog_volume_cmd or TOG_VOLUME_CMD
local icon = { local icon = {
id = "icon", id = "icon",
image = PATH_TO_ICON, image = path_to_icon,
resize = true, resize = true,
widget = wibox.widget.imagebox, widget = wibox.widget.imagebox,
} }
@ -31,10 +49,10 @@ local icon = {
local volumearc = wibox.widget { local volumearc = wibox.widget {
icon, icon,
max_value = 1, max_value = 1,
thickness = 2, thickness = thickness,
start_angle = 4.71238898, -- 2pi*3/4 start_angle = 4.71238898, -- 2pi*3/4
forced_height = 18, forced_height = height,
forced_width = 18, forced_width = height,
bg = "#ffffff11", bg = "#ffffff11",
paddings = 2, paddings = 2,
widget = wibox.container.arcchart widget = wibox.container.arcchart
@ -46,22 +64,25 @@ local update_graphic = function(widget, stdout, _, _, _)
volume = tonumber(string.format("% 3d", volume)) volume = tonumber(string.format("% 3d", volume))
widget.value = volume / 100; widget.value = volume / 100;
widget.colors = mute == 'off' and { beautiful.widget_red } widget.colors = mute == 'off'
or { beautiful.widget_main_color } and { mute_color }
or { main_color }
end end
volumearc:connect_signal("button::press", function(_, _, _, button) volumearc: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)
end end
spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode) spawn.easy_async(get_volume_cmd, function(stdout, stderr, exitreason, exitcode)
update_graphic(volumearc, stdout, stderr, exitreason, exitcode) update_graphic(volumearc, stdout, stderr, exitreason, exitcode)
end) end)
end) end)
watch(GET_VOLUME_CMD, 1, update_graphic, volumearc) watch(get_volume_cmd, 1, update_graphic, volumearc)
return volumearc return volumearc
end
return setmetatable(widget, { __call = function(_, ...) return worker(...) end })