From 68ac60509f11d3a449a317a8d9c092ac49763451 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Sun, 22 Jan 2023 14:32:51 +0000 Subject: Add page up & page down keybindings. --- doc/tofi.1.md | 8 ++++++++ doc/tofi.1.scd | 6 ++++++ src/input.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/doc/tofi.1.md b/doc/tofi.1.md index 818ad53..9ef52c6 100644 --- a/doc/tofi.1.md +++ b/doc/tofi.1.md @@ -48,6 +48,14 @@ the form **--key=value**. > Move the selection forward one entry. +\ + +> Move the selection back one page. + +\ + +> Move the selection forward one page. + \-u > Delete line. diff --git a/doc/tofi.1.scd b/doc/tofi.1.scd index 24e75b7..9f7ebe6 100644 --- a/doc/tofi.1.scd +++ b/doc/tofi.1.scd @@ -44,6 +44,12 @@ All config file options described in *tofi*(5) are also accepted, in the form | | -j | Move the selection forward one entry. + + Move the selection back one page. + + + Move the selection forward one page. + -u Delete line. diff --git a/src/input.c b/src/input.c index be65e24..7f78c50 100644 --- a/src/input.c +++ b/src/input.c @@ -16,6 +16,8 @@ static void clear_input(struct tofi *tofi); static void paste(struct tofi *tofi); static void select_previous_result(struct tofi *tofi); static void select_next_result(struct tofi *tofi); +static void select_previous_page(struct tofi *tofi); +static void select_next_page(struct tofi *tofi); static void next_cursor_or_result(struct tofi *tofi); static void previous_cursor_or_result(struct tofi *tofi); static void reset_selection(struct tofi *tofi); @@ -88,6 +90,10 @@ void input_handle_keypress(struct tofi *tofi, xkb_keycode_t keycode) select_next_result(tofi); } else if (sym == XKB_KEY_Home) { reset_selection(tofi); + } else if (sym == XKB_KEY_Page_Up) { + select_previous_page(tofi); + } else if (sym == XKB_KEY_Page_Down) { + select_next_page(tofi); } else if (sym == XKB_KEY_Escape || (key == KEY_C && xkb_state_mod_name_is_active( @@ -335,3 +341,28 @@ void next_cursor_or_result(struct tofi *tofi) select_next_result(tofi); } } + +void select_previous_page(struct tofi *tofi) +{ + struct entry *entry = &tofi->window.entry; + + if (entry->first_result >= entry->last_num_results_drawn) { + entry->first_result -= entry->last_num_results_drawn; + } else { + entry->first_result = 0; + } + entry->selection = 0; + entry->last_num_results_drawn = entry->num_results_drawn; +} + +void select_next_page(struct tofi *tofi) +{ + struct entry *entry = &tofi->window.entry; + + entry->first_result += entry->num_results_drawn; + if (entry->first_result >= entry->results.count) { + entry->first_result = 0; + } + entry->selection = 0; + entry->last_num_results_drawn = entry->num_results_drawn; +} -- cgit v1.2.3