From 864295fc334f8887f2c17b484bca126f81b7f901 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 4 Oct 2009 01:10:28 +0200 Subject: [PATCH] main: update within timer_reconnect() Don't schedule the timer_mpd_update() call. Always return "true" from timer_mpd_update(). This sets the full event mask after a connection was established. The "database updated" message appears only if the connection existed before. --- src/main.c | 46 +++++++++++++++++++++++++++++----------------- src/screen.c | 4 +++- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/main.c b/src/main.c index 726f098..8669b63 100644 --- a/src/main.c +++ b/src/main.c @@ -165,8 +165,7 @@ enable_update_timer(void) return; update_source_id = g_timeout_add(update_interval, - timer_mpd_update, - GINT_TO_POINTER(TRUE)); + timer_mpd_update, NULL); } static void @@ -179,6 +178,26 @@ disable_update_timer(void) update_source_id = 0; } +static void +check_reconnect(void); + +static void +do_mpd_update(void) +{ + if (mpdclient_is_connected(mpd)) + mpdclient_update(mpd); + +#ifndef NCMPC_MINI + if (options.enable_xterm_title) + update_xterm_title(); +#endif + + screen_update(mpd); + mpd->events = 0; + + check_reconnect(); +} + /** * This timer is installed when the connection to the MPD server is * broken. It tries to recover by reconnecting periodically. @@ -232,7 +251,11 @@ timer_reconnect(G_GNUC_UNUSED gpointer data) doupdate(); /* update immediately */ - g_timeout_add(1, timer_mpd_update, GINT_TO_POINTER(FALSE)); + mpd->events = MPD_IDLE_DATABASE|MPD_IDLE_STORED_PLAYLIST| + MPD_IDLE_QUEUE|MPD_IDLE_PLAYER|MPD_IDLE_MIXER|MPD_IDLE_OUTPUT| + MPD_IDLE_OPTIONS|MPD_IDLE_UPDATE; + + do_mpd_update(); return FALSE; } @@ -247,22 +270,11 @@ check_reconnect(void) } static gboolean -timer_mpd_update(gpointer data) +timer_mpd_update(G_GNUC_UNUSED gpointer data) { - if (mpdclient_is_connected(mpd)) - mpdclient_update(mpd); - -#ifndef NCMPC_MINI - if (options.enable_xterm_title) - update_xterm_title(); -#endif - - screen_update(mpd); - mpd->events = 0; - - check_reconnect(); + do_mpd_update(); - return GPOINTER_TO_INT(data); + return true; } void begin_input_event(void) diff --git a/src/screen.c b/src/screen.c index efbd37f..1944170 100644 --- a/src/screen.c +++ b/src/screen.c @@ -366,6 +366,7 @@ void screen_update(struct mpdclient *c) { #ifndef NCMPC_MINI + static bool was_connected; static bool initialized = false; static bool repeat; static bool random_enabled; @@ -424,8 +425,9 @@ screen_update(struct mpdclient *c) crossfade = mpd_status_get_crossfade(c->status); } - if (c->events & MPD_IDLE_DATABASE) + if ((c->events & MPD_IDLE_DATABASE) != 0 && was_connected) screen_status_printf(_("Database updated")); + was_connected = mpdclient_is_connected(c); /* update title/header window */ if (screen.welcome_source_id != 0) -- 2.30.2