Commit: 6a4c9aa992791dedf57dcfb5fb4f393205adb4d1
Parent: 309468cd71cefd05240ce20f6f2373a904f41b79
Author: Randy Palamar
Date: Wed, 17 Mar 2021 13:15:45 -0600
update and re-enable mpd block
Diffstat:
4 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/Makefile b/Makefile
@@ -4,6 +4,7 @@ include config.mk
SRC =\
blocks/battery.c\
blocks/gettime.c\
+ blocks/mpd.c\
blocks/volume.c\
status.c util.c
OBJ = $(SRC:.c=.o)
diff --git a/blocks/mpd.c b/blocks/mpd.c
@@ -5,8 +5,8 @@
#include "../util.h"
#include "mpd.h"
-static const char *
-mpd(enum mpd_tag_type type)
+size_t
+mpd(struct Block *b)
{
struct mpd_connection *conn = NULL;
struct mpd_song *song = NULL;
@@ -14,7 +14,7 @@ mpd(enum mpd_tag_type type)
conn = mpd_connection_new(mpdhost, 0, 600);
if (!conn || mpd_connection_get_error(conn))
- return NULL;
+ return bprintf(b->curstr, BLOCKLEN, b->fmt, "");
mpd_command_list_begin(conn, true);
mpd_send_status(conn);
@@ -27,16 +27,16 @@ mpd(enum mpd_tag_type type)
if (status && (mpd_status_get_state(status) >= MPD_STATE_PLAY)) {
mpd_response_next(conn);
song = mpd_recv_song(conn);
- snprintf(buf, sizeof(buf), "%s",
- mpd_song_get_tag(song, type, 0));
+ bprintf(buf, sizeof(buf), "%s",
+ mpd_song_get_tag(song, b->u.i, 0));
mpd_song_free(song);
} else
- snprintf(buf, sizeof(buf), "%s", "");
+ bprintf(buf, sizeof(buf), "%s", "");
if (status)
mpd_status_free(status);
mpd_response_finish(conn);
mpd_connection_free(conn);
- return buf;
+ return bprintf(b->curstr, BLOCKLEN, b->fmt, buf);
}
diff --git a/blocks/mpd.h b/blocks/mpd.h
@@ -0,0 +1,5 @@
+/* to have access to tag types */
+#include <mpd/tag.h>
+
+extern const char *mpdhost;
+size_t mpd(struct Block *b);
diff --git a/config.def.h b/config.def.h
@@ -1,5 +1,6 @@
#include "blocks/battery.h"
#include "blocks/gettime.h"
+#include "blocks/mpd.h"
#include "blocks/volume.h"
#define STATUSLEN 1024
@@ -15,6 +16,8 @@ const char *alsacard = "default";
/* status block definitions */
struct Block blks[] = {
/* fn fmt interval signal arg */
+ { mpd, "[ %s ", 0, 0, { .i = MPD_TAG_ARTIST } },
+ { mpd, "- %s ]", 0, 0, { .i = MPD_TAG_TITLE } },
{ batinfo, "[ %s ]", 0, 0, { .s = "BAT0" } },
{ getvol, "[ %s ]", 0, 0, { .s = "Speaker" } },
{ gettime, "[ %R ]", 20, 0, {0} },