From: Jeffrey Middleton Date: Tue, 10 Mar 2009 13:49:46 +0000 (-0500) Subject: Center the cursor on a second Ctrl-L X-Git-Tag: release-0.14~68 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8664f4fa424c5ae30b495e49e0f606b220c56696;p=ncmpc.git Center the cursor on a second Ctrl-L To aid in getting to info/lyrics screen, or in selecting ranges involving the currently playing song. Ctrl-L followed by M will achieve the same result as long as the playlist is at least as long as the screen, but this is faster to type and will work for short playlists too. An alternative method would be to center the cursor whenever Ctrl-L will not cause the screen to move; this could be implemented as an option perhaps, but would be annoying if you just wanted to repaint the screen. --- diff --git a/src/screen_play.c b/src/screen_play.c index b9b0ecb..ceb37c4 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -137,13 +137,13 @@ list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED void *data) } static void -center_playing_item(mpdclient_t *c) +center_playing_item(mpdclient_t *c, bool center_cursor) { unsigned length = c->playlist.list->len; int idx; - if (!c->song || length < lw->rows || - c->status == NULL || IS_STOPPED(c->status->state)) + if (!c->song || c->status == NULL || + IS_STOPPED(c->status->state)) return; /* try to center the song that are playing */ @@ -151,8 +151,20 @@ center_playing_item(mpdclient_t *c) if (idx < 0) return; + if (length < lw->rows) + { + if (center_cursor) + list_window_set_selected(lw, idx); + return; + } + list_window_center(lw, length, idx); + if (center_cursor) { + list_window_set_selected(lw, idx); + return; + } + /* make sure the cursor is in the window */ if (lw->selected < lw->start) { lw->selected = lw->start; @@ -513,7 +525,7 @@ play_update(mpdclient_t *c) /* center the cursor */ if (options.auto_center && current_song_id != -1 && ! lw->visual_selection) - center_playing_item(c); + center_playing_item(c, false); playlist_repaint(); #ifndef NCMPC_MINI @@ -568,6 +580,10 @@ handle_mouse_event(struct mpdclient *c) static bool play_cmd(mpdclient_t *c, command_t cmd) { + static command_t cached_cmd = CMD_NONE; + command_t prev_cmd = cached_cmd; + cached_cmd = cmd; + lw->hide_cursor = false; if (options.hide_cursor > 0) { @@ -609,7 +625,7 @@ play_cmd(mpdclient_t *c, command_t cmd) handle_add_to_playlist(c); return true; case CMD_SCREEN_UPDATE: - center_playing_item(c); + center_playing_item(c, prev_cmd == CMD_SCREEN_UPDATE); playlist_repaint(); return false; case CMD_SHUFFLE: