summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 863d404)
raw | patch | inline | side by side (parent: 863d404)
author | Max Kellermann <max.kellermann@gmail.com> | |
Fri, 17 Mar 2017 22:24:27 +0000 (23:24 +0100) | ||
committer | Max Kellermann <max.kellermann@gmail.com> | |
Fri, 17 Mar 2017 22:28:05 +0000 (23:28 +0100) |
Cache the mpd_status_get_state()==MPD_STATE_PLAY value which is used
pretty often.
pretty often.
src/main.c | patch | blob | history | |
src/mpdclient.c | patch | blob | history | |
src/mpdclient.h | patch | blob | history |
diff --git a/src/main.c b/src/main.c
index 88e6f221fc89afb891470a29027fe2afccd8e044..177f1b529be07e0506fe8d245bf82b5d78c94ceb 100644 (file)
--- a/src/main.c
+++ b/src/main.c
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);
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
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 13937516897838b43b2f883758af8d966562d272..0209d6464bf8287ab4294ded44d35995ab05043b 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
playlist_init(&c->playlist);
c->volume = -1;
c->events = 0;
+ c->playing = false;
return c;
}
c->status = NULL;
c->volume = -1;
+ c->playing = false;
}
void
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 52088151dba89287f4bf57219005bbf386010f52..7756710173a368116e2165f161bf346919bde78f 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
* "idle" mode, and the #mpd_glib_source waits for an event.
*/
bool idle;
+
+ /**
+ * Is MPD currently playing?
+ */
+ bool playing;
};
enum {