From: Max Kellermann Date: Mon, 2 Nov 2009 17:29:06 +0000 (+0100) Subject: screen_queue: use mpd_status.song_pos for centering the list X-Git-Tag: release-0.16~40 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2ff7f4cdedb080d9f6129c283e8876077b1b1b6f;p=ncmpc.git screen_queue: use mpd_status.song_pos for centering the list Don't look up the playlist. Just use the position provided by MPD. Side effect: we can pass the mpd_status object to center_playing_item(), not the whole mpdclient object. --- diff --git a/src/screen_queue.c b/src/screen_queue.c index 4eb3c73..b20aa24 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; @@ -538,8 +543,8 @@ screen_queue_update(struct mpdclient *c) 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 (options.auto_center && !lw->range_selection) + center_playing_item(c->status, false); screen_queue_repaint(); } else if (c->events & MPD_IDLE_PLAYLIST) { @@ -627,7 +632,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: