Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
ui: add half page scroll up/down
include/seamus.h | 2 ++ src/ui.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
diff --git a/include/seamus.h b/include/seamus.h index 0e19c5c68b5c69f68b4780ca5d2f2c6c827c09f8..c2f8af6a9e78ab3055055526e4d4caaf1c08cd9a 100644 --- a/include/seamus.h +++ b/include/seamus.h @@ -48,6 +48,8 @@ KEY_GOTO_END, KEY_HOME, KEY_GOTO_START, KEY_SWITCH_MODE, + KEY_HALF_PAGE_UP, + KEY_HALF_PAGE_DOWN, }; struct seamus_frontend { diff --git a/src/ui.c b/src/ui.c index a19d1cf7448db3368d882ba13c59658f4ee2649d..6ef76637078a9580f62243419d5aa5974af9a2ea 100644 --- a/src/ui.c +++ b/src/ui.c @@ -12,6 +12,7 @@ static int toggle_playing_status(struct seamus_frontend *seamus); static int update_scroll_position(struct seamus_frontend *seamus, int direction); static int scroll_page(struct seamus_frontend *seamus, int direction); static int scroll_to_extremes(struct seamus_frontend *seamus, int home); +static int scroll_half_page(struct seamus_frontend *seamus, int direction); static int switch_window(struct seamus_frontend *seamus); static int update_status(Tickit *t, TickitEventFlags flags, void *_info, void *data); static int update_main_window(Tickit *t, TickitEventFlags flags, void *_info, void *data); @@ -97,6 +98,8 @@ if (strcmp(str, "G") == 0) return KEY_GOTO_END; if (strcmp(str, "Home") == 0) return KEY_HOME; if (strcmp(str, "g") == 0) return KEY_GOTO_START; if (strcmp(str, "Tab") == 0) return KEY_SWITCH_MODE; + if (strcmp(str, "C-u") == 0) return KEY_HALF_PAGE_UP; + if (strcmp(str, "C-d") == 0) return KEY_HALF_PAGE_DOWN; return KEY_NONE; } @@ -152,6 +155,16 @@ log_info("Go to start"); scroll_to_extremes(seamus, 1); break; + case KEY_HALF_PAGE_UP: + log_info("Half page up"); + scroll_half_page(seamus, -1); + break; + + case KEY_HALF_PAGE_DOWN: + log_info("Half page down"); + scroll_half_page(seamus, +1); + break; + case KEY_SWITCH_MODE: switch_window(seamus); break; @@ -265,6 +278,40 @@ seamus->highlight_index = seamus->status->length - 1; } tickit_window_expose(seamus->main_window, NULL); + return 0; +} + +static int +scroll_half_page(struct seamus_frontend *seamus, int direction) +{ + if (seamus->status->length <= 0) { + return 0; + } + + int visible_rows = tickit_window_lines(seamus->main_window) - QUEUE_START_LINE; + if (visible_rows <= 0) visible_rows = 1; + + int step = visible_rows / 2; + if (step < 1) step = 1; + + if (direction == 1) { + seamus->scroll_offset += step; + + if (seamus->scroll_offset > seamus->status->length - visible_rows) { + seamus->scroll_offset = seamus->status->length - visible_rows; + } + + if (seamus->scroll_offset < 0) seamus->scroll_offset = 0; + seamus->highlight_index = seamus->scroll_offset; + } else if (direction == -1) { + seamus->scroll_offset -= step; + + if (seamus->scroll_offset < 0) seamus->scroll_offset = 0; + seamus->highlight_index = seamus->scroll_offset; + } + + tickit_window_expose(seamus->main_window, NULL); + return 0; }