Code

screen_queue: use mpd_status.song_pos for centering the list
authorMax Kellermann <max@duempel.org>
Mon, 2 Nov 2009 17:29:06 +0000 (18:29 +0100)
committerMax Kellermann <max@duempel.org>
Mon, 2 Nov 2009 17:29:06 +0000 (18:29 +0100)
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.

src/screen_queue.c

index 4eb3c734e8614c58085edf9c0176d0436d340140..b20aa2496a62d506fe81f2b15feaf360d5025e42 100644 (file)
@@ -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: