Commit: 9cce7db815c25d4a86b711fde753a2ef7357d95c
Parent: ac52e6f337cef50833a93c841e889a8129d57d48
Author: Randy Palamar
Date: Sun, 4 Apr 2021 13:58:58 -0600
properly check MPD_STATE and remove second if (status) check
Diffstat:
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/blocks/mpd.c b/blocks/mpd.c
@@ -38,19 +38,24 @@ mpd(struct Block *b)
}
mpd_run_noidle(conn);
- status = mpd_run_status(conn);
-
- /* >= covers both PLAY and PAUSE */
- if (status && (mpd_status_get_state(status) >= MPD_STATE_PLAY)) {
- song = mpd_run_current_song(conn);
- snprintf(buf, sizeof(buf), "%s",
- mpd_song_get_tag(song, b->u.i, 0));
- mpd_song_free(song);
+
+ if ((status = mpd_run_status(conn))) {
+ switch (mpd_status_get_state(status)) {
+ case MPD_STATE_PAUSE:
+ case MPD_STATE_PLAY:
+ song = mpd_run_current_song(conn);
+ snprintf(buf, sizeof(buf), "%s",
+ mpd_song_get_tag(song, b->u.i, 0));
+ mpd_song_free(song);
+ break;
+ case MPD_STATE_STOP:
+ default:
+ snprintf(buf, sizeof(buf), "%s", "");
+ }
+ mpd_status_free(status);
} else
snprintf(buf, sizeof(buf), "%s", "");
- if (status)
- mpd_status_free(status);
mpd_send_idle(conn);
return snprintf(b->curstr, LEN(b->curstr), b->fmt, buf);