summaryrefslogtreecommitdiff
path: root/volume-widget
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@gmail.com>2017-02-03 22:15:16 -0500
committerstreetturtle <streetturtle@gmail.com>2017-02-03 22:15:16 -0500
commit52590602d91d705c9a356359b56f45c55cb4d9d8 (patch)
treef4a185265c806459cf8e9a225730d1877eca42c3 /volume-widget
parent78fa8e629da7ea64ed54a2a8d6d08857b83e4324 (diff)
improve widget rendering and use wibox.widget wrapper
Diffstat (limited to 'volume-widget')
-rw-r--r--volume-widget/vol-widget-1.pngbin817 -> 824 bytes
-rw-r--r--volume-widget/volume.lua52
2 files changed, 30 insertions, 22 deletions
diff --git a/volume-widget/vol-widget-1.png b/volume-widget/vol-widget-1.png
index ba03630..6f09cce 100644
--- a/volume-widget/vol-widget-1.png
+++ b/volume-widget/vol-widget-1.png
Binary files differ
diff --git a/volume-widget/volume.lua b/volume-widget/volume.lua
index 90251a6..c403dfd 100644
--- a/volume-widget/volume.lua
+++ b/volume-widget/volume.lua
@@ -1,26 +1,34 @@
-local wibox = require("wibox")
local awful = require("awful")
+local wibox = require("wibox")
+local watch = require("awful.widget.watch")
+local gears = require("gears")
-function update_volume()
- awful.spawn.easy_async([[bash -c 'amixer -D pulse sget Master']],
- function(stdout, stderr, reason, exit_code)
- local volume = string.match(stdout, "(%d?%d?%d)%%")
- volume = tonumber(string.format("% 3d", volume))
- local volume_icon_name
-
- if (volume >= 0 and volume < 20) then volume_icon_name="audio-volume-none-panel"
- elseif (volume >= 20 and volume < 40) then volume_icon_name="audio-volume-zero-panel"
- elseif (volume >= 40 and volume < 60) then volume_icon_name="audio-volume-low-panel"
- elseif (volume >= 60 and volume < 80) then volume_icon_name="audio-volume-medium-panel"
- elseif (volume >= 80 and volume <= 100) then volume_icon_name="audio-volume-high-panel"
- end
- volume_icon:set_image("/usr/share/icons/Arc/panel/22/" .. volume_icon_name .. ".svg")
- end)
-end
-
+local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
-volume_icon = wibox.widget.imagebox()
+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(brightness_icon, 0, 0, 3),
+ set_image = function(self, path)
+ self.icon.image = path
+ end
+}
-mytimer = timer({ timeout = 0.2 })
-mytimer:connect_signal("timeout", function () update_volume() end)
-mytimer:start() \ No newline at end of file
+watch(
+ 'amixer -D pulse sget Master', 1,
+ function(widget, stdout, stderr, reason, exit_code)
+ local volume = string.match(stdout, "(%d?%d?%d)%%")
+ volume = tonumber(string.format("% 3d", volume))
+ local volume_icon_name
+ if (volume >= 0 and volume < 25) then volume_icon_name="audio-volume-muted-symbolic"
+ elseif (volume >= 25 and volume < 50) then volume_icon_name="audio-volume-low-symbolic"
+ elseif (volume >= 50 and volume < 75) then volume_icon_name="audio-volume-medium-symbolic"
+ elseif (volume >= 75 and volume <= 100) then volume_icon_name="audio-volume-high-symbolic"
+ end
+ volume_widget.image = path_to_icons .. volume_icon_name .. ".svg"
+ end
+) \ No newline at end of file