summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2023-01-22 14:32:51 +0000
committerPhil Jones <philj56@gmail.com>2023-01-22 14:32:51 +0000
commit68ac60509f11d3a449a317a8d9c092ac49763451 (patch)
tree886989c893e0491297a32a796bc0d135fa44ac23
parenta0cb6eab595e67b1e45efb6e4203bea2b5bdd7ae (diff)
Add page up & page down keybindings.
-rw-r--r--doc/tofi.1.md8
-rw-r--r--doc/tofi.1.scd6
-rw-r--r--src/input.c31
3 files changed, 45 insertions, 0 deletions
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.
+\<Page Up\>
+
+> Move the selection back one page.
+
+\<Page Down\>
+
+> Move the selection forward one page.
+
\<Ctrl\>-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
<Down> | <Right> | <Ctrl>-j | <Tab>
Move the selection forward one entry.
+<Page Up>
+ Move the selection back one page.
+
+<Page Down>
+ Move the selection forward one page.
+
<Ctrl>-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;
+}