From 972bff32235bbd414cbbaba5ac3eeb7979c2bad6 Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Sat, 30 Sep 2023 19:20:48 -0400 Subject: add mpd widget; better borders --- modules/desktop/awesome/rc.lua | 35 +++++++++++++- modules/desktop/awesome/theme.lua | 6 +-- modules/desktop/awesome/widgets/mpd.lua | 86 +++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 modules/desktop/awesome/widgets/mpd.lua (limited to 'modules/desktop/awesome') diff --git a/modules/desktop/awesome/rc.lua b/modules/desktop/awesome/rc.lua index 1fb1ea5..41728fa 100644 --- a/modules/desktop/awesome/rc.lua +++ b/modules/desktop/awesome/rc.lua @@ -143,6 +143,9 @@ local topcalendar = calendar_widget() local volume_widget = require("widgets.volume") local volumebar = volume_widget() +local mpd_widget = require("widgets.mpd") +local mpdbar = mpd_widget() + toptextclock:connect_signal("button::press", function(_, _, _, button) if button == 1 then topcalendar.toggle() end @@ -344,6 +347,22 @@ awful.screen.connect_for_each_screen(function(s) end) -- }}} +local mpd_dock = wibox { + visible = true, + ontop = false, + height = 24, + width = 300, + bg = "00000000" +} + +mpd_dock:setup { + mpdbar, + halign = "center", + layout = wibox.container.place +} + +awful.placement.top_right(mpd_dock, { margins = { top = 42, right = 8 }, parent = awful.screen.focused() }) + -- {{{ Mouse bindings root.buttons(gears.table.join( awful.button({ }, 3, function () mymainmenu:toggle() end), @@ -657,7 +676,16 @@ client.connect_signal("request::titlebars", function(c) end) ) - awful.titlebar(c, {size = dpi(20), position = "left"}) : setup { + awful.titlebar(c, {size = dpi(6), position = "top"}) : setup { + layout = wibox.layout.align.horizontal + } + awful.titlebar(c, {size = dpi(6), position = "bottom"}) : setup { + layout = wibox.layout.align.horizontal + } + awful.titlebar(c, {size = dpi(6), position = "right"}) : setup { + layout = wibox.layout.align.vertical + } + awful.titlebar(c, {size = dpi(26), position = "left"}) : setup { { -- Left awful.titlebar.widget.iconwidget(c), widget = wibox.container.margin, @@ -681,29 +709,32 @@ client.connect_signal("request::titlebars", function(c) widget = awful.titlebar.widget.maximizedbutton(c), }, widget = wibox.container.background, + ontop = true, shape = gears.shape.circle, shape_border_width = 1, shape_border_color = "#12ac28", bg = "#28c940", forced_height = dpi(14), + forced_width = dpi(14), }, { { widget = awful.titlebar.widget.closebutton(c), }, widget = wibox.container.background, + ontop = true, shape = gears.shape.circle, shape_border_width = 1, shape_border_color = "#ad3934", bg = "#bf4943", forced_height = dpi(14), + forced_width = dpi(14), }, spacing = dpi(6), layout = wibox.layout.fixed.vertical }, widget = wibox.container.margin; top = dpi(6); - bottom = dpi(6); }, layout = wibox.layout.align.vertical } diff --git a/modules/desktop/awesome/theme.lua b/modules/desktop/awesome/theme.lua index 1568b5a..18be5db 100644 --- a/modules/desktop/awesome/theme.lua +++ b/modules/desktop/awesome/theme.lua @@ -30,10 +30,10 @@ theme.tag_list_focused = "#cdd6f4" theme.tag_list_urgent = "#f38ba8" theme.useless_gap = dpi(4) -theme.border_width = 0 +theme.border_width = dpi(0) theme.border_normal = theme.bg_normal -theme.border_focus = theme.bg_focus -theme.border_marked = theme.fg_focus .. "88" +theme.border_focus = theme.bg_normal +theme.border_marked = theme.bg_normal -- There are other variable sets -- overriding the default one when 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}) -- cgit v1.2.1