diff options
Diffstat (limited to '')
-rw-r--r-- | src/list_window.c | 18 | ||||
-rw-r--r-- | src/list_window.h | 2 | ||||
-rw-r--r-- | src/screen_help.c | 11 | ||||
-rw-r--r-- | src/screen_lyrics.c | 10 | ||||
-rw-r--r-- | src/screen_play.c | 11 |
5 files changed, 25 insertions, 27 deletions
diff --git a/src/list_window.c b/src/list_window.c index f26088da4..ad671f0cf 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -82,6 +82,24 @@ list_window_check_selected(struct list_window *lw, unsigned length) } void +list_window_center(struct list_window *lw, unsigned rows, unsigned n) +{ + if (n > lw->rows / 2) + lw->start = n - lw->rows / 2; + else + lw->start = 0; + + if (lw->start + lw->rows > rows) { + if (lw->rows < rows) + lw->start = rows - lw->rows; + else + lw->start = 0; + } + + lw->repaint = lw->clear = 1; +} + +void list_window_set_selected(struct list_window *lw, unsigned n) { lw->selected = n; diff --git a/src/list_window.h b/src/list_window.h index ab02f4bdd..3a9fba4c3 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -56,6 +56,8 @@ int list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd); int list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd); +void +list_window_center(struct list_window *lw, unsigned rows, unsigned n); /* 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 850608181..363b440cf 100644 --- a/src/screen_help.c +++ b/src/screen_help.c @@ -248,16 +248,7 @@ help_cmd(screen_t *screen, mpd_unused mpdclient_t *c, command_t cmd) lw, help_text_rows, cmd, list_callback, NULL)) { /* center the row */ - if (lw->selected > lw->rows / 2) - lw->start = lw->selected - lw->rows / 2; - else - lw->start = 0; - if (lw->start + lw->rows > (unsigned)help_text_rows) { - if (lw->rows < (unsigned)help_text_rows) - lw->start = help_text_rows - lw->rows; - else - lw->start = 0; - } + list_window_center(lw, help_text_rows, lw->selected); return 1; } diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index 5356548c9..6853fecd7 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -292,8 +292,6 @@ 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_SELECT: /* XXX */ @@ -329,13 +327,7 @@ lyrics_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) lw, lyrics_text_rows, cmd, list_callback, NULL)) { /* center the row */ - lw->start = lw->selected - (lw->rows / 2); - if (lw->start + lw->rows > (unsigned)lyrics_text_rows) { - if (lw->rows < (unsigned)lyrics_text_rows) - lw->start = lyrics_text_rows - lw->rows; - else - lw->start = 0; - } + list_window_center(lw, current.lines->len, lw->selected); return 1; } diff --git a/src/screen_play.c b/src/screen_play.c index 6b4de7893..0426176d6 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -106,20 +106,15 @@ center_playing_item(mpdclient_t *c) /* try to center the song that are playing */ idx = playlist_get_index(c, c->song); D("Autocenter song id:%d pos:%d index:%d\n", c->song->id,c->song->pos,idx); - idx -= (lw->rows / 2); - if (idx + (int)lw->rows > (int)length) - idx = length - lw->rows; if (idx < 0) - idx = 0; - lw->start = idx; + return 0; + + list_window_center(lw, length, idx); /* make sure the cursor is in the window */ lw->selected = lw->start+offset; list_window_check_selected(lw, length); - lw->clear = 1; - lw->repaint = 1; - return 0; } |