From: Max Kellermann Date: Fri, 17 Mar 2017 22:24:27 +0000 (+0100) Subject: mpdclient: add "playing" attribute X-Git-Tag: v0.26~48 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=445a3a03d4bd0f3da0e2bc4ecc65021faf24325c;p=ncmpc.git mpdclient: add "playing" attribute Cache the mpd_status_get_state()==MPD_STATE_PLAY value which is used pretty often. --- diff --git a/src/main.c b/src/main.c index 88e6f22..177f1b5 100644 --- a/src/main.c +++ b/src/main.c @@ -74,12 +74,10 @@ static guint check_key_bindings_source_id; static void update_xterm_title(void) { - struct mpd_status *status = mpd->status; const struct mpd_song *song = mpd->song; char tmp[BUFSIZE]; - if (options.xterm_title_format && status && song && - mpd_status_get_state(status) == MPD_STATE_PLAY) + if (options.xterm_title_format && mpd->playing && song) strfsong(tmp, BUFSIZE, options.xterm_title_format, song); else g_strlcpy(tmp, PACKAGE " version " VERSION, BUFSIZE); @@ -177,9 +175,7 @@ disable_update_timer(void) static bool should_enable_update_timer(void) { - return (mpdclient_is_connected(mpd) && - mpd->status != NULL && - mpd_status_get_state(mpd->status) == MPD_STATE_PLAY) + return mpd->playing #ifndef NCMPC_MINI || options.display_time #endif @@ -202,9 +198,7 @@ static void do_mpd_update(void) { if (mpdclient_is_connected(mpd) && - (mpd->events != 0 || - (mpd->status != NULL && - mpd_status_get_state(mpd->status) == MPD_STATE_PLAY))) + (mpd->events != 0 || mpd->playing)) mpdclient_update(mpd); #ifndef NCMPC_MINI diff --git a/src/mpdclient.c b/src/mpdclient.c index 1393751..0209d64 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -104,6 +104,7 @@ mpdclient_new(void) playlist_init(&c->playlist); c->volume = -1; c->events = 0; + c->playing = false; return c; } @@ -128,6 +129,7 @@ mpdclient_status_free(struct mpdclient *c) c->status = NULL; c->volume = -1; + c->playing = false; } void @@ -210,6 +212,7 @@ mpdclient_update(struct mpdclient *c) return mpdclient_handle_error(c); c->volume = mpd_status_get_volume(c->status); + c->playing = mpd_status_get_state(c->status) == MPD_STATE_PLAY; /* check if the playlist needs an update */ if (c->playlist.version != mpd_status_get_queue_version(c->status)) { diff --git a/src/mpdclient.h b/src/mpdclient.h index 5208815..7756710 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -41,6 +41,11 @@ struct mpdclient { * "idle" mode, and the #mpd_glib_source waits for an event. */ bool idle; + + /** + * Is MPD currently playing? + */ + bool playing; }; enum {