From: Max Kellermann Date: Wed, 30 Sep 2009 22:13:30 +0000 (+0200) Subject: status_bar: use a GLib timer to remove the message X-Git-Tag: release-0.16~240 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1495e7b909a0439ef56151114ec31f6e01f7e0f2;p=ncmpc.git status_bar: use a GLib timer to remove the message --- diff --git a/src/status_bar.c b/src/status_bar.c index 3c16731..5aaf04b 100644 --- a/src/status_bar.c +++ b/src/status_bar.c @@ -31,8 +31,27 @@ #include +#include #include +static gboolean +status_bar_clear_message(gpointer data) +{ + struct status_bar *p = data; + WINDOW *w = p->window.w; + + assert(p != NULL); + assert(p->message_source_id != 0); + + p->message_source_id = 0; + + wmove(w, 0, 0); + wclrtoeol(w); + wrefresh(w); + + return false; +} + void status_bar_paint(const struct status_bar *p, const struct mpd_status *status, const struct mpd_song *song) @@ -49,7 +68,7 @@ status_bar_paint(const struct status_bar *p, const struct mpd_status *status, int x = 0; char buffer[p->window.cols * 4 + 1]; - if (time(NULL) - p->message_timestamp <= options.status_message_time) + if (p->message_source_id != 0) return; wmove(w, 0, 0); @@ -192,5 +211,8 @@ status_bar_message(struct status_bar *p, const char *msg) waddstr(w, msg); wnoutrefresh(w); - p->message_timestamp = time(NULL); + if (p->message_source_id != 0) + g_source_remove(p->message_source_id); + p->message_source_id = g_timeout_add(options.status_message_time * 1000, + status_bar_clear_message, p); } diff --git a/src/status_bar.h b/src/status_bar.h index 78b367c..902ed1a 100644 --- a/src/status_bar.h +++ b/src/status_bar.h @@ -32,7 +32,7 @@ struct mpd_song; struct status_bar { struct window window; - GTime message_timestamp; + guint message_source_id; }; static inline void @@ -43,13 +43,16 @@ status_bar_init(struct status_bar *p, unsigned width, int y, int x) leaveok(p->window.w, false); keypad(p->window.w, true); - p->message_timestamp = 0; + p->message_source_id = 0; } static inline void status_bar_deinit(struct status_bar *p) { delwin(p->window.w); + + if (p->message_source_id != 0) + g_source_remove(p->message_source_id); } void