tShow an animation instead of a long URI when no tags - spoon - dwm status utility (2f30 fork)
(HTM) git clone git://src.adamsgaard.dk/spoon
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit cb6af3adecc068b161a43a20103221498a228bcf
(DIR) parent 34037d775918f2fcb5f0efc395cf786da46bd79e
(HTM) Author: lostd <lostd@2f30.org>
Date: Wed, 2 Nov 2016 16:43:35 +0000
Show an animation instead of a long URI when no tags
Diffstat:
M mpd.c | 18 +++++++++++-------
M spoon.c | 2 +-
M util.h | 2 ++
3 files changed, 14 insertions(+), 8 deletions(-)
---
(DIR) diff --git a/mpd.c b/mpd.c
t@@ -6,13 +6,22 @@
#include "types.h"
#include "util.h"
+char *anim[] = {
+ "!!.|.",
+ "|!.!.",
+ "!.!!.",
+ "!!|.!",
+ ".!!|!",
+};
+
int
mpdread(void *arg, char *buf, size_t len)
{
static struct mpd_connection *conn;
struct mpd_song *song;
- const char *artist, *title, *name;
+ const char *artist, *title;
struct mpdarg *mpdarg = arg;
+ static int frame = 0;
if (conn == NULL) {
conn = mpd_connection_new(mpdarg->host, mpdarg->port, 0);
t@@ -36,12 +45,7 @@ mpdread(void *arg, char *buf, size_t len)
} else if (title != NULL) {
strlcpy(buf, title, len);
} else {
- name = mpd_song_get_uri(song);
- if (name == NULL) {
- mpd_song_free(song);
- goto out;
- }
- strlcpy(buf, name, len);
+ strlcpy(buf, anim[frame++ % LEN(anim)], len);
}
mpd_song_free(song);
if (!mpd_response_finish(conn))
(DIR) diff --git a/spoon.c b/spoon.c
t@@ -5,7 +5,7 @@
#include <X11/Xlib.h>
-#define LEN(x) (sizeof (x) / sizeof *(x))
+#include "util.h"
int battread(void *, char *, size_t);
int cpuread(void *, char *, size_t);
(DIR) diff --git a/util.h b/util.h
t@@ -3,6 +3,8 @@ size_t strlcat(char *, const char *, size_t);
#undef strlcpy
size_t strlcpy(char *, const char *, size_t);
+#define LEN(x) (sizeof (x) / sizeof *(x))
+
#ifdef DEBUG
#define DPRINTF_S(x) printf(#x "=%s\n", x)
#define DPRINTF_U(x) printf(#x "=%u\n", x)