summaryrefslogtreecommitdiff
path: root/volumearc-widget/volumearc.lua
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@gmail.com>2019-03-30 17:42:59 -0400
committerstreetturtle <streetturtle@gmail.com>2019-03-30 18:16:03 -0400
commitc06b09703181954387d0e2dddca9680e3c36e21c (patch)
tree96c9aa91dc4cf131ff284b8d1a752757c62a58fc /volumearc-widget/volumearc.lua
parenta1636558f539637b17ebbc2ebcd8677d93027319 (diff)
volumearc - externalize config
Diffstat (limited to 'volumearc-widget/volumearc.lua')
-rw-r--r--volumearc-widget/volumearc.lua95
1 files changed, 58 insertions, 37 deletions
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 })