From 1495e7b909a0439ef56151114ec31f6e01f7e0f2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 1 Oct 2009 00:13:30 +0200 Subject: [PATCH] status_bar: use a GLib timer to remove the message --- src/status_bar.c | 26 ++++++++++++++++++++++++-- src/status_bar.h | 7 +++++-- 2 files changed, 29 insertions(+), 4 deletions(-) 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 -- 2.30.2