bling/docs/signals/pctl.md

2.6 KiB

🎵 Playerctl

This is a signal module in which you can connect to certain bling signals to grab playerctl info. Currently, this is what it supports:

  • Song title and artist
  • Album art (the path this module downloaded the art to)
  • If playing or not
  • Position
  • Song length

This module relies on playerctl and curl. If you have this module disabled, you won't need those programs. With this module, you can create a widget like below without worrying about the backend.

screenshot by javacafe

Usage

To enable: bling.signal.playerctl.enable()

Here are the signals available:

-- bling::playerctl::status     -- first line is the signal
--      playing  (boolean)      -- indented lines are function parameters
-- bling::playerctl::title_artist_album
--      title  (string)
--      artist  (string)
--      album_path (string)
-- bling::playerctl::position
--      interval_sec  (number)
--      length_sec  (number)

Example Implementation

Lets say we have an imagebox. If I wanted to set the imagebox to show the album art, all I have to do is this:

local art = wibox.widget {
    image = "default_image.png",
    resize = true,
    forced_height = dpi(80),
    forced_width = dpi(80),
    widget = wibox.widget.imagebox
}

local title_widget = wibox.widget {
    markup = 'Nothing Playing',
    align = 'center',
    valign = 'center',
    widget = wibox.widget.textbox
}

local artist_widget = wibox.widget {
    markup = 'Nothing Playing',
    align = 'center',
    valign = 'center',
    widget = wibox.widget.textbox
}

-- Get Song Info
awesome.connect_signal("bling::playerctl::title_artist_album",
                       function(title, artist, art_path)
    -- Set art widget
    art:set_image(gears.surface.load_uncached(art_path))

    -- Set title and artist widgets
    title_widget:set_markup_silently(title)
    artist_widget:set_markup_silently(artist)
end)

Thats all! You don't even have to worry about updating the widgets, the signals will handle that for you.

Here's another example in which you get a notification with the album art, title, and artist whenever the song changes.

local naughty = require("naughty")

awesome.connect_signal("bling::playerctl::title_artist_album",
                       function(title, artist, art_path)
    naughty.notify({title = title, text = artist, image = art_path})
end)

Theme Variables

theme.playerctl_position_update_interval = 1  -- the update interval for fetching the position from playerctl