X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fscreen_queue.c;h=f3ca21a06e49a6c5a1ae2d73d0ac9483e3548df0;hb=19267b94dc72a500a7760aed2ad1ee8705932775;hp=4eb3c734e8614c58085edf9c0176d0436d340140;hpb=9cb132951622b50f9dde5250dc938b264c866a7a;p=ncmpc.git diff --git a/src/screen_queue.c b/src/screen_queue.c index 4eb3c73..f3ca21a 100644 --- a/src/screen_queue.c +++ b/src/screen_queue.c @@ -134,12 +134,17 @@ screen_queue_lw_callback(unsigned idx, G_GNUC_UNUSED void *data) } static void -center_playing_item(struct mpdclient *c, bool center_cursor) +center_playing_item(const struct mpd_status *status, bool center_cursor) { int idx; + if (status == NULL || + (mpd_status_get_state(status) != MPD_STATE_PLAY && + mpd_status_get_state(status) != MPD_STATE_PAUSE)) + return; + /* try to center the song that are playing */ - idx = playlist_get_index(&c->playlist, c->song); + idx = mpd_status_get_song_pos(status); if (idx < 0) return; @@ -154,6 +159,32 @@ center_playing_item(struct mpdclient *c, bool center_cursor) list_window_fetch_cursor(lw); } +G_GNUC_PURE +static int +get_current_song_id(const struct mpd_status *status) +{ + return status != NULL && + (mpd_status_get_state(status) == MPD_STATE_PLAY || + mpd_status_get_state(status) == MPD_STATE_PAUSE) + ? (int)mpd_status_get_song_id(status) + : -1; +} + +static bool +screen_queue_song_change(const struct mpd_status *status) +{ + if (get_current_song_id(status) == current_song_id) + return false; + + current_song_id = get_current_song_id(status); + + /* center the cursor */ + if (options.auto_center && !lw->range_selection) + center_playing_item(status, false); + + return true; +} + #ifndef NCMPC_MINI static void save_pre_completion_cb(GCompletion *gcmp, G_GNUC_UNUSED gchar *line, @@ -441,6 +472,7 @@ screen_queue_open(struct mpdclient *c) } screen_queue_restore_selection(); + screen_queue_song_change(c->status); } static void @@ -516,37 +548,18 @@ screen_queue_paint(void) list_window_paint2(lw, screen_queue_paint_callback, NULL); } -G_GNUC_PURE -static int -get_current_song_id(const struct mpd_status *status) -{ - return status != NULL && - (mpd_status_get_state(status) == MPD_STATE_PLAY || - mpd_status_get_state(status) == MPD_STATE_PAUSE) - ? (int)mpd_status_get_song_id(status) - : -1; -} - static void screen_queue_update(struct mpdclient *c) { - if (c->events & MPD_IDLE_PLAYLIST) + if (c->events & MPD_IDLE_QUEUE) screen_queue_restore_selection(); - if ((c->events & MPD_IDLE_PLAYER) != 0 && - get_current_song_id(c->status) != current_song_id) { - current_song_id = get_current_song_id(c->status); - - /* center the cursor */ - if (options.auto_center && current_song_id != -1 && ! lw->range_selection) - center_playing_item(c, false); - + if (((c->events & MPD_IDLE_PLAYER) != 0 && + screen_queue_song_change(c->status)) || + c->events & MPD_IDLE_QUEUE) + /* the queue or the current song has changed, we must + paint the new version */ screen_queue_repaint(); - } else if (c->events & MPD_IDLE_PLAYLIST) { - /* the playlist has changed, we must paint the new - version */ - screen_queue_repaint(); - } } #ifdef HAVE_GETMOUSE @@ -627,7 +640,7 @@ screen_queue_cmd(struct mpdclient *c, command_t cmd) switch(cmd) { case CMD_SCREEN_UPDATE: - center_playing_item(c, prev_cmd == CMD_SCREEN_UPDATE); + center_playing_item(c->status, prev_cmd == CMD_SCREEN_UPDATE); screen_queue_repaint(); return false; case CMD_SELECT_PLAYING: