summaryrefslogtreecommitdiffstats
path: root/programs/dotfiles/awesome/volume.lua
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2023-09-24 20:07:40 -0400
committerJon Santmyer <jon@jonsantmyer.com>2023-09-24 20:07:40 -0400
commit59328d463daf5c7af066e284c7f9072e8da02f1f (patch)
tree5c1d8a003749ae519d59074d285f7361d23eb92f /programs/dotfiles/awesome/volume.lua
parent9cffa9b6eb594983b3f4fab4bceca42091a531e5 (diff)
downloadnix-config-59328d463daf5c7af066e284c7f9072e8da02f1f.tar.gz
nix-config-59328d463daf5c7af066e284c7f9072e8da02f1f.tar.bz2
nix-config-59328d463daf5c7af066e284c7f9072e8da02f1f.zip
add vomule widget to awesome
Diffstat (limited to 'programs/dotfiles/awesome/volume.lua')
-rw-r--r--programs/dotfiles/awesome/volume.lua60
1 files changed, 60 insertions, 0 deletions
diff --git a/programs/dotfiles/awesome/volume.lua b/programs/dotfiles/awesome/volume.lua
new file mode 100644
index 0000000..21c200b
--- /dev/null
+++ b/programs/dotfiles/awesome/volume.lua
@@ -0,0 +1,60 @@
+local awful = require("awful")
+local spawn = require("awful.spawn")
+local watch = require("awful.widget.watch")
+local beautiful = require("beautiful")
+local wibox = require("wibox")
+local gears = require("gears")
+local naughty = require("naughty")
+
+local volume_widget = {}
+
+local get_volume_cmd = "bash -c 'wpctl get-volume @DEFAULT_AUDIO_SINK@'"
+
+local function worker(user_args)
+ local volume_bar = wibox.widget {
+ bar_shape = gears.shape.rounded_rect,
+ bar_height = 4,
+ bar_color = beautiful.fg_focus,
+ handle_color = beautiful.fg_focus,
+ handle_shape = gears.shape.circle,
+ handle_border_width = 0,
+ value = 0,
+ forced_width = 50,
+ widget = wibox.widget.slider,
+ }
+
+ volume_widget = wibox.widget {
+ {
+ layout = wibox.layout.fixed.horizontal,
+ {
+ text = "󰕾 ",
+ widget = wibox.widget.textbox
+ },
+ volume_bar,
+ spacing = 4
+ },
+ widget = wibox.container.margin,
+ left = 8,
+ }
+
+ local function percentage(value)
+ return math.floor(value)
+ end
+
+ watch(get_volume_cmd, 1,
+ function(widget, stdout)
+ volume = stdout:match('0.%d+')
+ widget.value = tonumber(volume) * 100
+ end, volume_bar)
+
+ volume_bar:connect_signal("property::value",
+ function(self)
+ spawn.easy_async("bash -c 'wpctl set-volume @DEFAULT_AUDIO_SINK@ " .. self.value .. "%'", function() end)
+ end)
+
+ return volume_widget
+end
+
+return setmetatable(volume_widget, { __call = function(_, ...)
+ return worker(...)
+end})