From 75c195782d7d4ad7f4707e0ac53dd1439ae344e5 Mon Sep 17 00:00:00 2001 From: streetturtle Date: Sat, 30 Mar 2019 17:42:59 -0400 Subject: volumearc - externalize config --- volumearc-widget/README.md | 51 +++++++++++++++-------- volumearc-widget/volumearc.lua | 95 ++++++++++++++++++++++++++---------------- 2 files changed, 91 insertions(+), 55 deletions(-) diff --git a/volumearc-widget/README.md b/volumearc-widget/README.md index 702b486..79f519d 100644 --- a/volumearc-widget/README.md +++ b/volumearc-widget/README.md @@ -2,24 +2,39 @@ Almost the same as [volumebar widget](https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumebar-widget), but using arcchart: -![screenshot](out.gif) - -Supports: - - scroll up - increase volume, - - scroll down - decrease volume, - - left click - mute/unmute. +![screenshot]({{'/assets/img/screenshots/volumearc-widget.gif' | relative_url }}){:.center-image} ## Installation -Clone repo, include widget and use it in **rc.lua**: - -```lua -require("volumearc") -... -s.mytasklist, -- Middle widget - { -- Right widgets - layout = wibox.layout.fixed.horizontal, - ... - volumearc_widget, - ... -``` +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 + s.mytasklist, -- Middle widget + { -- Right widgets + layout = wibox.layout.fixed.horizontal, + ... + --[[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 + }), + + ... + ``` \ No newline at end of file diff --git a/volumearc-widget/volumearc.lua b/volumearc-widget/volumearc.lua index 63500bc..4a91cd3 100644 --- a/volumearc-widget/volumearc.lua +++ b/volumearc-widget/volumearc.lua @@ -21,47 +21,68 @@ 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 icon = { - id = "icon", - image = PATH_TO_ICON, - resize = true, - widget = wibox.widget.imagebox, -} - -local volumearc = wibox.widget { - icon, - max_value = 1, - thickness = 2, - start_angle = 4.71238898, -- 2pi*3/4 - forced_height = 18, - forced_width = 18, - bg = "#ffffff11", - paddings = 2, - widget = wibox.container.arcchart -} - -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)) - - widget.value = volume / 100; - widget.colors = mute == 'off' and { beautiful.widget_red } - or { beautiful.widget_main_color } +local widget = {} -end +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 = { + id = "icon", + image = path_to_icon, + resize = true, + widget = wibox.widget.imagebox, + } -volumearc: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 volumearc = wibox.widget { + icon, + max_value = 1, + thickness = thickness, + start_angle = 4.71238898, -- 2pi*3/4 + forced_height = height, + forced_width = height, + bg = "#ffffff11", + paddings = 2, + widget = wibox.container.arcchart + } + + 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)) + + widget.value = volume / 100; + widget.colors = mute == 'off' + and { mute_color } + or { main_color } end - spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode) - update_graphic(volumearc, stdout, stderr, exitreason, exitcode) + volumearc: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(volumearc, stdout, stderr, exitreason, exitcode) + end) end) -end) -watch(GET_VOLUME_CMD, 1, update_graphic, volumearc) + watch(get_volume_cmd, 1, update_graphic, volumearc) + + return volumearc +end -return volumearc \ No newline at end of file +return setmetatable(widget, { __call = function(_, ...) return worker(...) end }) -- cgit v1.2.3 From c06b09703181954387d0e2dddca9680e3c36e21c Mon Sep 17 00:00:00 2001 From: streetturtle Date: Sat, 30 Mar 2019 17:42:59 -0400 Subject: volumearc - externalize config --- volumearc-widget/README.md | 51 +++++++++++++++-------- volumearc-widget/volumearc.lua | 95 ++++++++++++++++++++++++++---------------- 2 files changed, 91 insertions(+), 55 deletions(-) diff --git a/volumearc-widget/README.md b/volumearc-widget/README.md index 702b486..79f519d 100644 --- a/volumearc-widget/README.md +++ b/volumearc-widget/README.md @@ -2,24 +2,39 @@ Almost the same as [volumebar widget](https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumebar-widget), but using arcchart: -![screenshot](out.gif) - -Supports: - - scroll up - increase volume, - - scroll down - decrease volume, - - left click - mute/unmute. +![screenshot]({{'/assets/img/screenshots/volumearc-widget.gif' | relative_url }}){:.center-image} ## Installation -Clone repo, include widget and use it in **rc.lua**: - -```lua -require("volumearc") -... -s.mytasklist, -- Middle widget - { -- Right widgets - layout = wibox.layout.fixed.horizontal, - ... - volumearc_widget, - ... -``` +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 + s.mytasklist, -- Middle widget + { -- Right widgets + layout = wibox.layout.fixed.horizontal, + ... + --[[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 + }), + + ... + ``` \ No newline at end of file diff --git a/volumearc-widget/volumearc.lua b/volumearc-widget/volumearc.lua index 63500bc..4a91cd3 100644 --- a/volumearc-widget/volumearc.lua +++ b/volumearc-widget/volumearc.lua @@ -21,47 +21,68 @@ 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 icon = { - id = "icon", - image = PATH_TO_ICON, - resize = true, - widget = wibox.widget.imagebox, -} - -local volumearc = wibox.widget { - icon, - max_value = 1, - thickness = 2, - start_angle = 4.71238898, -- 2pi*3/4 - forced_height = 18, - forced_width = 18, - bg = "#ffffff11", - paddings = 2, - widget = wibox.container.arcchart -} - -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)) - - widget.value = volume / 100; - widget.colors = mute == 'off' and { beautiful.widget_red } - or { beautiful.widget_main_color } +local widget = {} -end +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 = { + id = "icon", + image = path_to_icon, + resize = true, + widget = wibox.widget.imagebox, + } -volumearc: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 volumearc = wibox.widget { + icon, + max_value = 1, + thickness = thickness, + start_angle = 4.71238898, -- 2pi*3/4 + forced_height = height, + forced_width = height, + bg = "#ffffff11", + paddings = 2, + widget = wibox.container.arcchart + } + + 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)) + + widget.value = volume / 100; + widget.colors = mute == 'off' + and { mute_color } + or { main_color } end - spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode) - update_graphic(volumearc, stdout, stderr, exitreason, exitcode) + volumearc: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(volumearc, stdout, stderr, exitreason, exitcode) + end) end) -end) -watch(GET_VOLUME_CMD, 1, update_graphic, volumearc) + watch(get_volume_cmd, 1, update_graphic, volumearc) + + return volumearc +end -return volumearc \ No newline at end of file +return setmetatable(widget, { __call = function(_, ...) return worker(...) end }) -- cgit v1.2.3 From 93ef029bdbcc1a1f6de927b1351d7169ba9b698e Mon Sep 17 00:00:00 2001 From: streetturtle Date: Sat, 13 Apr 2019 20:51:54 -0400 Subject: update volumearc readme --- volumearc-widget/README.md | 24 +++++++++++++++++++++--- volumearc-widget/custom.png | Bin 0 -> 9424 bytes volumearc-widget/volumearc.lua | 4 ++-- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 volumearc-widget/custom.png diff --git a/volumearc-widget/README.md b/volumearc-widget/README.md index 79f519d..5bd8e83 100644 --- a/volumearc-widget/README.md +++ b/volumearc-widget/README.md @@ -4,6 +4,24 @@ Almost the same as [volumebar widget](https://github.com/streetturtle/awesome-wm ![screenshot]({{'/assets/img/screenshots/volumearc-widget.gif' | relative_url }}){:.center-image} +## Customization + +It is possible to customize widget by providing a table with all or some of the following config parameters: + +```lua +volumearc_widget({ + main_color = '#af13f7', + mute_color = '#ff0000', + path_to_icon = '/usr/share/icons/Papirus-Dark/symbolic/status/audio-volume-high-symbolic.svg', + thickness = 5, + height = 25 +}) +``` + +Above config results in following widget: + +![custom](./custom.png) + ## Installation 1. Clone this repo under **~/.config/awesome/** @@ -29,12 +47,12 @@ Almost the same as [volumebar widget](https://github.com/streetturtle/awesome-wm volumearc_widget(), --[[or customized]] volumearc_widget({ - main_color = '#0000ff', + main_color = '#af13f7', mute_color = '#ff0000', - path_to_icon = '/usr/share/icons/Arc/actions/symbolic/view-grid-symbolic.svg', + path_to_icon = '/usr/share/icons/Papirus-Dark/symbolic/status/audio-volume-high-symbolic.svg', thickness = 5, height = 25 }), ... - ``` \ No newline at end of file + ``` diff --git a/volumearc-widget/custom.png b/volumearc-widget/custom.png new file mode 100644 index 0000000..f187345 Binary files /dev/null and b/volumearc-widget/custom.png differ diff --git a/volumearc-widget/volumearc.lua b/volumearc-widget/volumearc.lua index 4a91cd3..5fbf3dd 100644 --- a/volumearc-widget/volumearc.lua +++ b/volumearc-widget/volumearc.lua @@ -59,8 +59,8 @@ local function worker(args) } local update_graphic = function(widget, stdout, _, _, _) - local mute = string.match(stdout, "%[(o%D%D?)%]") - local volume = string.match(stdout, "(%d?%d?%d)%%") + local mute = string.match(stdout, "%[(o%D%D?)%]") -- \[(o\D\D?)\] - [on] or [off] + local volume = string.match(stdout, "(%d?%d?%d)%%") -- (\d?\d?\d)\%) volume = tonumber(string.format("% 3d", volume)) widget.value = volume / 100; -- cgit v1.2.3 From 6f495ea075f10c9c62ac23f89de6444387b2f9a5 Mon Sep 17 00:00:00 2001 From: streetturtle Date: Sat, 13 Apr 2019 20:53:50 -0400 Subject: Update README.md --- volumearc-widget/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/volumearc-widget/README.md b/volumearc-widget/README.md index 5bd8e83..38e7e05 100644 --- a/volumearc-widget/README.md +++ b/volumearc-widget/README.md @@ -2,7 +2,7 @@ Almost the same as [volumebar widget](https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumebar-widget), but using arcchart: -![screenshot]({{'/assets/img/screenshots/volumearc-widget.gif' | relative_url }}){:.center-image} +![screenshot](out.gif) ## Customization -- cgit v1.2.3