summaryrefslogtreecommitdiffstats
path: root/modules/desktop/awesome/widgets
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2023-09-30 19:20:48 -0400
committerJon Santmyer <jon@jonsantmyer.com>2023-09-30 19:20:48 -0400
commit972bff32235bbd414cbbaba5ac3eeb7979c2bad6 (patch)
treeefcb87c13a0de139a9ac8529dfd9daec81b9c0d3 /modules/desktop/awesome/widgets
parent7b599b6e10ab6e5fd3e7ec0c5b7d79a586375842 (diff)
downloadnix-config-972bff32235bbd414cbbaba5ac3eeb7979c2bad6.tar.gz
nix-config-972bff32235bbd414cbbaba5ac3eeb7979c2bad6.tar.bz2
nix-config-972bff32235bbd414cbbaba5ac3eeb7979c2bad6.zip
add mpd widget; better borders
Diffstat (limited to 'modules/desktop/awesome/widgets')
-rw-r--r--modules/desktop/awesome/widgets/mpd.lua86
1 files changed, 86 insertions, 0 deletions
diff --git a/modules/desktop/awesome/widgets/mpd.lua b/modules/desktop/awesome/widgets/mpd.lua
new file mode 100644
index 0000000..d588089
--- /dev/null
+++ b/modules/desktop/awesome/widgets/mpd.lua
@@ -0,0 +1,86 @@
+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 mpd_widget = {}
+
+local MUSIC_ICON = ' '
+local OFF_ICON = '󰝛 '
+
+local PLAY_ICON = ' '
+local PAUSE_ICON = ' '
+
+local PREV_ICON = ' '
+local NEXT_ICON = ' '
+
+local function worker(user_args)
+ local mpd_bar = wibox.widget {
+ {
+ id = "progress",
+ widget = wibox.widget.progressbar,
+ max_value = 1,
+ forced_height = 12,
+ forced_width = 150,
+ border_width = 0,
+ color = beautiful.bg_focus,
+ background_color = beautiful.bg_normal,
+ },
+ {
+ id = "title",
+ widget = wibox.widget.textbox,
+ text = "NO SONG",
+ valign = "center",
+ halign = "center",
+ },
+ layout = wibox.layout.stack
+ }
+
+ local status_icon = wibox.widget {
+ id = "status",
+ widget = wibox.widget.textbox,
+ text = PLAY_ICON
+ }
+
+ local update = function(widget, stdout, _, _, _)
+ local current_song = string.gmatch(stdout, "[^\r\n]+")()
+ stdout = string.gsub(stdout, "\n", "")
+ local mpd_percent = string.match(stdout, "(%d%d)%%")
+ local mpd_status = string.match(stdout, "%[(%a+)%]")
+
+ widget:get_children_by_id("title")[1].text = current_song
+ widget:get_children_by_id("progress")[1].value = tonumber(mpd_percent)/100
+
+ if mpd_status == "playing" then
+ status_icon.text = PLAY_ICON
+ elseif mpd_status == "paused" then
+ status_icon.text = PAUSE_ICON
+ end
+ end
+
+ mpd_bar:connect_signal("button::press", function(_, _, _, button)
+ if button == 1 then awful.spawn("mpc toggle", false)
+ elseif button == 3 then awful.spawn("kitty -e ncmpcpp", false)
+ elseif button == 4 then awful.spawn("mpc next", false)
+ elseif button == 5 then awful.spawn("mpc prev", false)
+ end
+ end)
+
+ watch("mpc status", 1, update, mpd_bar)
+
+ mpd_widget = wibox.widget {
+ status_icon,
+ mpd_bar,
+ layout = wibox.layout.align.horizontal,
+ spacing = 8,
+ }
+
+ return mpd_widget
+end
+
+return setmetatable(mpd_widget, { __call = function(_, ...)
+ return worker(...)
+end})