From: Max Kellermann Date: Wed, 17 Sep 2008 10:18:00 +0000 (+0200) Subject: list_window: added list_window_scroll_cmd() X-Git-Tag: v0.12_alpha1~272 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ca2b9d1390a56b89336b963113b5763edd70238e;p=ncmpc.git list_window: added list_window_scroll_cmd() It is similar to list_window_cmd(), but it scrolls the window instead of moving the selection. It is used by the "lyrics" and the "help" screen. --- diff --git a/src/list_window.c b/src/list_window.c index 88f0a69..f26088d 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -296,6 +296,56 @@ list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd) return 1; } +int +list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd) +{ + switch (cmd) { + case CMD_LIST_PREVIOUS: + if (lw->start > 0) + lw->start--; + break; + + case CMD_LIST_NEXT: + if (lw->start + lw->rows < rows) + lw->start++; + break; + + case CMD_LIST_FIRST: + lw->start = 0; + break; + + case CMD_LIST_LAST: + if (rows > lw->rows) + lw->start = rows - lw->rows; + else + lw->start = 0; + break; + + case CMD_LIST_NEXT_PAGE: + lw->start += lw->rows - 1; + if (lw->start + lw->rows > rows) { + if (rows > lw->rows) + lw->start = rows - lw->rows; + else + lw->start = 0; + } + break; + + case CMD_LIST_PREVIOUS_PAGE: + if (lw->start > lw->rows) + lw->start -= lw->rows; + else + lw->start = 0; + break; + + default: + return 0; + } + + lw->repaint = lw->clear = 1; + return 1; +} + list_window_state_t * list_window_init_state(void) { diff --git a/src/list_window.h b/src/list_window.h index 2efff8a..ab02f4b 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -49,6 +49,13 @@ void list_window_paint(struct list_window *lw, /* perform basic list window commands (movement) */ int list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd); +/** + * Scroll the window. Returns non-zero if the command has been + * consumed. + */ +int +list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd); + /* select functions */ void list_window_set_selected(struct list_window *lw, unsigned n); diff --git a/src/screen_help.c b/src/screen_help.c index 7c5134f..8506081 100644 --- a/src/screen_help.c +++ b/src/screen_help.c @@ -240,44 +240,8 @@ help_update(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) static int help_cmd(screen_t *screen, mpd_unused mpdclient_t *c, command_t cmd) { - lw->repaint=1; - lw->clear=1; - switch(cmd) { - case CMD_LIST_NEXT: - if (lw->start + lw->rows < (unsigned)help_text_rows) - lw->start++; + if (list_window_scroll_cmd(lw, help_text_rows, cmd)) return 1; - case CMD_LIST_PREVIOUS: - if (lw->start > 0) - lw->start--; - return 1; - case CMD_LIST_FIRST: - lw->start = 0; - return 1; - case CMD_LIST_LAST: - if ((unsigned)help_text_rows > lw->rows) - lw->start = help_text_rows - lw->rows; - else - lw->start = 0; - return 1; - case CMD_LIST_NEXT_PAGE: - lw->start = lw->start + lw->rows; - if (lw->start + lw->rows >= (unsigned)help_text_rows) { - if ((unsigned)help_text_rows > lw->rows) - lw->start = help_text_rows - lw->rows; - else - lw->start = 0; - } - return 1; - case CMD_LIST_PREVIOUS_PAGE: - if (lw->start > lw->rows) - lw->start -= lw->rows; - else - lw->start = 0; - return 1; - default: - break; - } lw->selected = lw->start+lw->rows; if (screen_find(screen, diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index e6e2cf0..5356548 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -289,40 +289,12 @@ lyrics_update(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) static int lyrics_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) { + if (list_window_scroll_cmd(lw, current.lines->len, cmd)) + return 1; + lw->repaint=1; + switch(cmd) { - case CMD_LIST_NEXT: - if (current.lines != NULL && lw->start+lw->rows < current.lines->len+1) - lw->start++; - return 1; - case CMD_LIST_PREVIOUS: - if( lw->start >0 ) - lw->start--; - return 1; - case CMD_LIST_FIRST: - lw->start = 0; - return 1; - case CMD_LIST_LAST: - if ((unsigned)lyrics_text_rows > lw->rows) - lw->start = lyrics_text_rows - lw->rows; - else - lw->start = 0; - return 1; - case CMD_LIST_NEXT_PAGE: - lw->start = lw->start + lw->rows - 1; - if (lw->start + lw->rows >= (unsigned)lyrics_text_rows + 1) { - if ((unsigned)lyrics_text_rows + 1 > lw->rows) - lw->start = lyrics_text_rows + 1 - lw->rows; - else - lw->start = 0; - } - return 1; - case CMD_LIST_PREVIOUS_PAGE: - if (lw->start > lw->rows) - lw->start -= lw->rows; - else - lw->start = 0; - return 1; case CMD_SELECT: /* XXX */ if (current.loader != NULL) {