summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3790917)
raw | patch | inline | side by side (parent: 3790917)
author | Max Kellermann <max@duempel.org> | |
Thu, 25 Sep 2008 16:42:48 +0000 (18:42 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Thu, 25 Sep 2008 16:42:48 +0000 (18:42 +0200) |
Instead of hiding the cursor in the update() callback, hide it with a
glib main loop timeout.
glib main loop timeout.
src/screen_play.c | patch | blob | history |
diff --git a/src/screen_play.c b/src/screen_play.c
index 64b170084ed06220cf4eaa33bd8a5ebcfb50ace0..757ead3a0ed46704127bfbe3e27770cd0a356352 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
mpdclient_t *c;
} completion_callback_data_t;
-static GTime input_timestamp;
static list_window_t *lw = NULL;
+static guint timer_hide_cursor_id;
static void
play_paint(struct mpdclient *c);
lw = list_window_init(w, cols, rows);
}
+static gboolean
+timer_hide_cursor(gpointer data)
+{
+ struct mpdclient *c = data;
+
+ assert(options.hide_cursor > 0);
+ assert(timer_hide_cursor_id != 0);
+
+ timer_hide_cursor_id = 0;
+
+ /* hide the cursor when mpd is playing and the user is inactive */
+
+ if (c->status != NULL && c->status->state == MPD_STATUS_STATE_PLAY) {
+ lw->flags |= LW_HIDE_CURSOR;
+ playlist_repaint(c);
+ } else
+ timer_hide_cursor_id = g_timeout_add(options.hide_cursor * 1000,
+ timer_hide_cursor, c);
+
+ return FALSE;
+}
+
static void
play_open(mpd_unused screen_t *screen, mpdclient_t *c)
{
static gboolean install_cb = TRUE;
- input_timestamp = time(NULL);
+ assert(timer_hide_cursor_id == 0);
+ if (options.hide_cursor > 0)
+ timer_hide_cursor_id = g_timeout_add(options.hide_cursor * 1000,
+ timer_hide_cursor, c);
if (install_cb) {
mpdclient_install_playlist_callback(c, playlist_changed_callback);
}
}
+static void
+play_close(void)
+{
+ if (timer_hide_cursor_id != 0) {
+ g_source_remove(timer_hide_cursor_id);
+ timer_hide_cursor_id = 0;
+ }
+}
+
static void
play_resize(int cols, int rows)
{
static void
play_update(mpd_unused screen_t *screen, mpdclient_t *c)
{
- int new_flags = lw->flags;
-
- /* hide the cursor when mpd are playing and the user are inactive */
- if (options.hide_cursor > 0 &&
- (c->status != NULL && c->status->state == MPD_STATUS_STATE_PLAY) &&
- time(NULL) - input_timestamp >= options.hide_cursor ) {
- new_flags |= LW_HIDE_CURSOR;
- } else {
- new_flags &= ~LW_HIDE_CURSOR;
- }
-
- if (new_flags != lw->flags) {
- lw->flags = new_flags;
- playlist_repaint(c);
- }
-
/* center the cursor */
if (options.auto_center) {
static int prev_song_id = 0;
static int
play_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
{
- input_timestamp = time(NULL);
+ lw->flags &= ~LW_HIDE_CURSOR;
+
+ if (options.hide_cursor > 0) {
+ if (timer_hide_cursor_id != 0)
+ g_source_remove(timer_hide_cursor_id);
+ timer_hide_cursor_id = g_timeout_add(options.hide_cursor * 1000,
+ timer_hide_cursor, c);
+ }
if (list_window_cmd(lw, playlist_length(&c->playlist), cmd)) {
playlist_repaint(c);
.init = play_init,
.exit = play_exit,
.open = play_open,
- .close = NULL,
+ .close = play_close,
.resize = play_resize,
.paint = play_paint,
.update = play_update,