summaryrefslogtreecommitdiff
path: root/mpdarc-widget
diff options
context:
space:
mode:
authorSam Delmerico <svdelmerico@gmail.com>2018-11-26 16:21:48 -0500
committerSam Delmerico <svdelmerico@gmail.com>2018-11-26 16:21:48 -0500
commit2cf217dc6c45f206aef0e065fa3ede4c36d73e3b (patch)
treea257f029216862d7525ca7e6e1818982b4a03085 /mpdarc-widget
parentf369e1cb28a308f6967d7bc31375c637755b1e3f (diff)
parent1eefac87faefa22b0d3941a9fd4c76010688f59e (diff)
merge biased battery levels
Diffstat (limited to 'mpdarc-widget')
-rw-r--r--mpdarc-widget/README.md14
-rw-r--r--mpdarc-widget/mpdarc.lua27
2 files changed, 36 insertions, 5 deletions
diff --git a/mpdarc-widget/README.md b/mpdarc-widget/README.md
index 0a6ffa6..2192410 100644
--- a/mpdarc-widget/README.md
+++ b/mpdarc-widget/README.md
@@ -10,5 +10,17 @@ Install `mpd` (Music Player Daemon itself) and `mpc` (Music Player Client - prog
sudo apt-get install mpd mpc
```
-Set them up and then just follow the [installation](https://github.com/streetturtle/awesome-wm-widgets#installation) section of the repo.
+## Installation
+To use this widget clone repo under **~/.config/awesome/** and then add it in **rc.lua**:
+
+```lua
+local mpdarc_widget = require("awesome-wm-widgets.mpdarc-widget.mpdarc")
+...
+s.mytasklist, -- Middle widget
+ { -- Right widgets
+ layout = wibox.layout.fixed.horizontal,
+ ...
+ mpdarc_widget,
+ ...
+```
diff --git a/mpdarc-widget/mpdarc.lua b/mpdarc-widget/mpdarc.lua
index 56009ef..ca0f411 100644
--- a/mpdarc-widget/mpdarc.lua
+++ b/mpdarc-widget/mpdarc.lua
@@ -14,6 +14,7 @@ local wibox = require("wibox")
local naughty = require("naughty")
local GET_MPD_CMD = "mpc status"
+local TOGGLE_MPD_CMD = "mpc toggle"
local PAUSE_MPD_CMD = "mpc pause"
local STOP_MPD_CMD = "mpc stop"
local NEXT_MPD_CMD = "mpc next"
@@ -45,9 +46,15 @@ local mpdarc = wibox.widget {
widget = wibox.container.arcchart
}
-local mpdarc_widget = wibox.container.mirror(mpdarc, { horizontal = true })
+local mpdarc_icon_widget = wibox.container.mirror(mpdarc, { horizontal = true })
+local mpdarc_current_song_widget = wibox.widget {
+ id = 'current_song',
+ widget = wibox.widget.textbox,
+ font = 'Play 9'
+}
local update_graphic = function(widget, stdout, _, _, _)
+ local current_song = string.gmatch(stdout, "[^\r\n]+")()
stdout = string.gsub(stdout, "\n", "")
local mpdpercent = string.match(stdout, "(%d%d)%%")
local mpdstatus = string.match(stdout, "%[(%a+)%]")
@@ -55,18 +62,25 @@ local update_graphic = function(widget, stdout, _, _, _)
icon.image = PLAY_ICON_NAME
widget.colors = { beautiful.widget_main_color }
widget.value = tonumber((100-mpdpercent)/100)
- elseif mpdstatus == "paused" then
+ mpdarc_current_song_widget.markup = current_song
+ elseif mpdstatus == "paused" then
icon.image = PAUSE_ICON_NAME
widget.colors = { beautiful.widget_main_color }
widget.value = tonumber(mpdpercent/100)
+ mpdarc_current_song_widget.markup = current_song
else
icon.image = STOP_ICON_NAME
- widget.colors = { beautiful.widget_red }
+ if string.len(stdout) == 0 then -- MPD is not running
+ mpdarc_current_song_widget.markup = "MPD is not running"
+ else
+ widget.colors = { beautiful.widget_red }
+ mpdarc_current_song_widget.markup = ""
+ end
end
end
mpdarc:connect_signal("button::press", function(_, _, _, button)
- if (button == 1) then awful.spawn("mpc toggle", false) -- left click
+ if (button == 1) then awful.spawn(TOGGLE_MPD_CMD, false) -- left click
elseif (button == 2) then awful.spawn(STOP_MPD_CMD, false)
elseif (button == 3) then awful.spawn(PAUSE_MPD_CMD, false)
elseif (button == 4) then awful.spawn(NEXT_MPD_CMD, false) -- scroll up
@@ -97,4 +111,9 @@ mpdarc:connect_signal("mouse::leave", function() naughty.destroy(notification) e
watch(GET_MPD_CMD, 1, update_graphic, mpdarc)
+local mpdarc_widget = {
+ mpdarc_icon_widget,
+ mpdarc_current_song_widget,
+ layout = wibox.layout.align.horizontal,
+ }
return mpdarc_widget