summaryrefslogtreecommitdiff
path: root/mpris-widget
diff options
context:
space:
mode:
Diffstat (limited to 'mpris-widget')
-rw-r--r--mpris-widget/README.md2
-rw-r--r--mpris-widget/init.lua154
2 files changed, 132 insertions, 24 deletions
diff --git a/mpris-widget/README.md b/mpris-widget/README.md
index 317385f..1978914 100644
--- a/mpris-widget/README.md
+++ b/mpris-widget/README.md
@@ -1,4 +1,4 @@
-# MPRIS Widget
+# MPRIS Widget (In progress)
Music Player Info widget cy @mgabs
diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua
index 5af85b4..1b6dcfc 100644
--- a/mpris-widget/init.lua
+++ b/mpris-widget/init.lua
@@ -11,15 +11,16 @@ local spawn = require("awful.spawn")
local watch = require("awful.widget.watch")
local wibox = require("wibox")
local naughty = require("naughty")
+local gears = require("gears")
-local GET_MPD_CMD =
- "playerctl -f '{{status}};{{xesam:artist}};{{xesam:title}};{{mpris:artUrl}}' metadata"
+local GET_MPD_CMD = "playerctl -p %s -f '{{status}};{{xesam:artist}};{{xesam:title}};{{mpris:artUrl}}' metadata"
local TOGGLE_MPD_CMD = "playerctl play-pause"
local PAUSE_MPD_CMD = "playerctl pause"
local STOP_MPD_CMD = "playerctl stop"
local NEXT_MPD_CMD = "playerctl next"
local PREV_MPD_CMD = "playerctl previous"
+local LIST_PLAYERS_CMD = "playerctl -l"
local PATH_TO_ICONS = "/usr/share/icons/Arc"
local PAUSE_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_pause.png"
@@ -27,9 +28,106 @@ local PLAY_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_play.png"
local STOP_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_stop.png"
local LIBRARY_ICON_NAME = PATH_TO_ICONS .. "/actions/24/music-library.png"
-local mpdarc_widget = {}
+local default_player = ''
-local function worker(args)
+local mpris_widget = wibox.widget{
+ {
+ id = 'artist',
+ widget = wibox.widget.textbox
+ },
+ {
+ max_value = 1,
+ value = 0,
+ thickness = 2,
+ start_angle = 4.71238898, -- 2pi*3/4
+ forced_height = 24,
+ forced_width = 24,
+ rounded_edge = true,
+ bg = "#ffffff11",
+ paddings = 0,
+ widget = wibox.container.arcchart
+ },
+ {
+ id = 'title',
+ widget = wibox.widget.textbox
+ },
+ layout = wibox.layout.fixed.horizontal,
+ set_text = function(self, artis, title)
+ self:get_children_by_id('artist')[1]:set_text(artis)
+ self:get_children_by_id('title')[1]:set_text(title)
+ end
+}
+
+local rows = { layout = wibox.layout.fixed.vertical }
+
+local popup = awful.popup{
+ bg = beautiful.bg_normal,
+ ontop = true,
+ visible = false,
+ shape = gears.shape.rounded_rect,
+ border_width = 1,
+ border_color = beautiful.bg_focus,
+ maximum_width = 400,
+ offset = { y = 5 },
+ widget = {}
+}
+
+local function rebuild_popup()
+ awful.spawn.easy_async(LIST_PLAYERS_CMD, function(stdout, _, _, _)
+ for player_name in stdout:gmatch("[^\r\n]+") do
+ if player_name ~='' or player_name ~=nil then
+ for i = 0, #rows do rows[i]=nil end
+
+ local checkbox = wibox.widget{
+ {
+ checked = player_name == default_player,
+ color = beautiful.bg_normal,
+ paddings = 2,
+ shape = gears.shape.circle,
+ forced_width = 20,
+ forced_height = 20,
+ check_color = beautiful.fg_urgent,
+ widget = wibox.widget.checkbox
+ },
+ valign = 'center',
+ layout = wibox.container.place,
+ }
+
+ checkbox:connect_signal("button::press", function(c)
+ default_player = player_name
+ rebuild_popup()
+ end)
+
+ table.insert(rows, wibox.widget {
+ {
+ {
+ checkbox,
+ {
+ {
+ text = player_name,
+ align = 'left',
+ widget = wibox.widget.textbox
+ },
+ left = 10,
+ layout = wibox.container.margin
+ },
+ spacing = 8,
+ layout = wibox.layout.align.horizontal
+ },
+ margins = 4,
+ layout = wibox.container.margin
+ },
+ bg = beautiful.bg_normal,
+ widget = wibox.container.background
+ })
+ end
+ end
+ end)
+
+ popup:setup(rows)
+end
+
+local function worker()
-- retriving song info
local current_song, artist, mpdstatus, art, artUrl
@@ -55,8 +153,7 @@ local function worker(args)
widget = wibox.container.arcchart
}
- local mpdarc_icon_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,
@@ -85,11 +182,13 @@ local function worker(args)
icon.image = PLAY_ICON_NAME
widget.colors = {beautiful.widget_main_color}
mpdarc_current_song_widget.markup = current_song
+ widget:set_text(artist, current_song)
elseif mpdstatus == "Paused" then
mpdarc_icon_widget.visible = true
icon.image = PAUSE_ICON_NAME
widget.colors = {beautiful.widget_main_color}
mpdarc_current_song_widget.markup = current_song
+ widget.set_text(artist, current_song)
elseif mpdstatus == "Stopped" then
mpdarc_icon_widget.visible = true
icon.image = STOP_ICON_NAME
@@ -115,15 +214,32 @@ local function worker(args)
awful.spawn(PREV_MPD_CMD, false) -- scroll down
end
- spawn.easy_async(GET_MPD_CMD,
- function(stdout, stderr, exitreason, exitcode)
- update_graphic(mpdarc, stdout, stderr, exitreason, exitcode)
- end)
+ -- spawn.easy_async(string.format(GET_MPD_CMD, "'" .. default_player .. "'"), function(stdout, stderr, exitreason, exitcode)
+ -- update_graphic(mpdarc, stdout, stderr, exitreason, exitcode)
+ -- end)
end)
+ mpris_widget:buttons(
+ awful.util.table.join(
+ awful.button({}, 3, function()
+ if popup.visible then
+ popup.visible = not popup.visible
+ else
+ rebuild_popup()
+ popup:move_next_to(mouse.current_widget_geometry)
+ end
+ end),
+ awful.button({}, 4, function() awful.spawn(NEXT_MPD_CMD, false) end),
+ awful.button({}, 5, function() awful.spawn(PREV_MPD_CMD, false) end),
+ awful.button({}, 1, function() awful.spawn(TOGGLE_MPD_CMD, false) end)
+ )
+ )
+
+
+
local notification
local function show_MPD_status()
- spawn.easy_async(GET_MPD_CMD, function(stdout, _, _, _)
+ spawn.easy_async(GET_MPD_CMD, function()
notification = naughty.notification {
margin = 10,
timeout = 5,
@@ -140,20 +256,12 @@ local function worker(args)
mpdarc:connect_signal("mouse::enter", function()
if current_song ~= nil and artist ~= nil then show_MPD_status() end
end)
- mpdarc:connect_signal("mouse::leave",
- function() naughty.destroy(notification) end)
+ mpdarc:connect_signal("mouse::leave", function() naughty.destroy(notification) end)
- watch(GET_MPD_CMD, 1, update_graphic, mpdarc)
+ watch(string.format(GET_MPD_CMD, "'" .. default_player .. "'"), 1, update_graphic, mpris_widget)
- mpdarc_widget = wibox.widget {
- screen = 'primary',
- mpdarc_icon_widget,
- mpdarc_current_song_widget,
- layout = wibox.layout.align.horizontal
- }
- return mpdarc_widget
+ return mpris_widget
end
-return setmetatable(mpdarc_widget,
- {__call = function(_, ...) return worker(...) end})
+return setmetatable(mpris_widget, {__call = function(_, ...) return worker(...) end})