Introduction
Introduction Statistics Contact Development Disclaimer Help
tAdd support for mpd current song - spoon - dwm status utility (2f30 fork)
git clone git://src.adamsgaard.dk/spoon
Log
Files
Refs
LICENSE
---
commit 121956cfc0fa87ba9608d804f3ca044dc57c8d12
parent c9624f19c37036e05abadc0c8c978a07581cb5dd
Author: lostd <[email protected]>
Date: Sun, 15 May 2016 14:08:13 +0100
Add support for mpd current song
Diffstat:
M Makefile | 6 +++---
M spoon.c | 34 +++++++++++++++++++++++++++++…
2 files changed, 35 insertions(+), 5 deletions(-)
---
diff --git a/Makefile b/Makefile
t@@ -1,7 +1,7 @@
PREFIX = /usr/local
-CFLAGS = -I/usr/X11R6/include
-LDFLAGS = -L/usr/X11R6/lib
-LDLIBS = -lxkbfile -lX11
+CFLAGS = -I/usr/X11R6/include -I/usr/local/include
+LDFLAGS = -L/usr/X11R6/lib -L/usr/local/lib
+LDLIBS = -lxkbfile -lX11 -lmpdclient
OBJ = spoon.o
BIN = spoon
diff --git a/spoon.c b/spoon.c
t@@ -9,6 +9,8 @@
#include <X11/XKBlib.h>
#include <X11/extensions/XKBrules.h>
+#include <mpd/client.h>
+
#define LEN(x) (sizeof (x) / sizeof *(x))
int dummyread(char *buf, size_t len);
t@@ -40,8 +42,36 @@ dummyread(char *buf, size_t len)
int
mpdread(char *buf, size_t len)
{
- strlcpy(buf, "mpd", len);
- return 0;
+ struct mpd_connection *conn;
+ struct mpd_song *song;
+ const char *artist, *title;
+ int ret = 0;
+
+ conn = mpd_connection_new(NULL, 0, 0);
+ if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {
+ warnx("cannot connect to mpd");
+ return -1;
+ }
+ mpd_send_current_song(conn);
+ song = mpd_recv_song(conn);
+ if (song == NULL) {
+ warnx("cannot recv mpd song");
+ ret = -1;
+ goto out;
+ }
+ artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
+ title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
+ if (artist != NULL && title != NULL)
+ snprintf(buf, len, "%s - %s", artist, title);
+ else if (title != NULL)
+ strlcpy(buf, title, len);
+ else
+ ret = -1;
+ mpd_song_free(song);
+ mpd_response_finish(conn);
+out:
+ mpd_connection_free(conn);
+ return ret;
}
#ifdef __OpenBSD__
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.