Add simple block for playerctl

This commit is contained in:
Maximilian Bosch 2017-09-15 18:02:15 +02:00
parent df030f4a68
commit 027fd7df3d
No known key found for this signature in database
GPG key ID: 091DBF4D1FC46B8E
5 changed files with 76 additions and 2 deletions

View file

@ -4,7 +4,7 @@ CPPFLAGS += -DVERSION=\"$(VERSION)\" -D_POSIX_C_SOURCE=199309L -DYA_INTERNAL -DY
-DYA_BSPWM -DYA_BSPWM
CFLAGS += -std=c99 -Iinclude -pedantic -Wall -flto -O2 `pkg-config --cflags pango pangocairo libconfig gdk-pixbuf-2.0 alsa` CFLAGS += -std=c99 -Iinclude -pedantic -Wall -flto -O2 `pkg-config --cflags pango pangocairo libconfig gdk-pixbuf-2.0 alsa`
LDFLAGS += -flto -O2 LDFLAGS += -flto -O2
LDLIBS += -liw -lxcb -lpthread -lxcb-randr -lxcb-ewmh -lxcb-icccm -lm `pkg-config --libs pango pangocairo libconfig gdk-pixbuf-2.0 alsa` LDLIBS += -liw -lxcb -lpthread -lxcb-randr -lxcb-ewmh -lxcb-icccm -lm `pkg-config --libs pango pangocairo libconfig gdk-pixbuf-2.0 alsa playerctl-1.0`
PROGRAM := yabar PROGRAM := yabar
DOCS := $(PROGRAM).1 DOCS := $(PROGRAM).1
PREFIX ?= /usr PREFIX ?= /usr

View file

@ -328,6 +328,12 @@ internal-option2: "    "; # icons to indicate quarter, half,
internal-suffix: "%"; internal-suffix: "%";
---- ----
* *YABAR_SONG* - *Current Song*: Uses 'playerctl' to retrieve the name of the currently played song. Example:
----
exec: "YABAR_SONG";
internal-option1: "spotify";
----
* *YABAR_VOLUME* - *Volume*: Uses ALSA to display sound volume in percentage. Example: * *YABAR_VOLUME* - *Volume*: Uses ALSA to display sound volume in percentage. Example:
---- ----
exec: "YABAR_VOLUME"; exec: "YABAR_VOLUME";

View file

@ -199,4 +199,10 @@ topbar:{
foreground-color-rgb:0x92D8F0; foreground-color-rgb:0x92D8F0;
underline-color-rgb:0xc0b929; underline-color-rgb:0xc0b929;
} }
song:{
exec: "YABAR_SONG";
fixed-size: 200;
type: "periodic";
internal-option1: "spotify";
}
} }

View file

@ -4,6 +4,6 @@ with import <nixpkgs>{}; stdenv.mkDerivation {
buildInputs = [ buildInputs = [
cairo gdk_pixbuf libconfig pango pkgconfig xorg.xcbutilwm docbook_xsl cairo gdk_pixbuf libconfig pango pkgconfig xorg.xcbutilwm docbook_xsl
alsaLib wirelesstools asciidoc libxslt makeWrapper libxml2 alsaLib wirelesstools asciidoc libxslt makeWrapper libxml2 playerctl
]; ];
} }

View file

@ -22,8 +22,10 @@ void ya_int_battery(ya_block_t *blk);
void ya_int_volume(ya_block_t *blk); void ya_int_volume(ya_block_t *blk);
void ya_int_wifi(ya_block_t *blk); void ya_int_wifi(ya_block_t *blk);
void ya_int_diskspace(ya_block_t *blk); void ya_int_diskspace(ya_block_t *blk);
void ya_int_song(ya_block_t *blk);
struct reserved_blk ya_reserved_blks[YA_INTERNAL_LEN] = { struct reserved_blk ya_reserved_blks[YA_INTERNAL_LEN] = {
{"YABAR_SONG", ya_int_song},
{"YABAR_DATE", ya_int_date}, {"YABAR_DATE", ya_int_date},
{"YABAR_UPTIME", ya_int_uptime}, {"YABAR_UPTIME", ya_int_uptime},
{"YABAR_THERMAL", ya_int_thermal}, {"YABAR_THERMAL", ya_int_thermal},
@ -129,6 +131,66 @@ __attribute__ ((gnu_inline)) inline void ya_setup_prefix_suffix(ya_block_t *blk,
} }
} }
#include <playerctl/playerctl.h>
#define CHECK_PLAYER_ERROR(PREFIX) \
if (PREFIX) \
ya_block_error(blk, "Player error!");
#define PRINT_PAUSED_MSG() \
sprintf(startstr,"%s",blk->internal->option[2]);
void ya_int_song(ya_block_t *blk) {
char *startstr = blk->buf;
size_t prflen = 0,suflen = 0;
ya_setup_prefix_suffix(blk, &prflen, &suflen, &startstr);
GError *e_tmp, *e_title, *e_artist;
PlayerctlPlayer *player;
gchar *s;
if (blk->internal->option[0]==NULL)
ya_block_error(blk, "Please set option0 for playerctl (e.g. spotify)!");
if (blk->internal->option[1]==NULL)
blk->internal->option[1] = " - ";
if (blk->internal->option[2]==NULL)
blk->internal->option[2] = "Paused";
while (1) {
player = playerctl_player_new(blk->internal->option[0], &e_tmp);
g_object_get(player, "status", &s, NULL);
if (s == NULL) {
PRINT_PAUSED_MSG();
continue;
}
if (strcmp("Playing", s) == 0) {
CHECK_PLAYER_ERROR(e_tmp);
sprintf(
startstr,
"%s %s %s",
playerctl_player_get_artist(player, &e_artist),
blk->internal->option[1],
playerctl_player_get_title(player, &e_title)
);
CHECK_PLAYER_ERROR(e_title);
CHECK_PLAYER_ERROR(e_artist);
} else {
PRINT_PAUSED_MSG();
}
if(suflen)
strcat(blk->buf, blk->internal->suffix);
g_free(s);
g_object_unref(player);
ya_draw_pango_text(blk);
sleep(blk->sleep);
}
}
#include <time.h> #include <time.h>
void ya_int_date(ya_block_t * blk) { void ya_int_date(ya_block_t * blk) {
time_t rawtime; time_t rawtime;