summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2022-07-26 17:51:31 +0100
committerPhil Jones <philj56@gmail.com>2022-07-26 17:51:31 +0100
commit88e713b981c8760c255b19009918ee94f60fbdc1 (patch)
treeecdca68c12425bbec7fb2f353d28a03c4e2f5a5c /src/main.c
parentd3bf3b017b8129ff772ad9c5658ccdfc826d0e51 (diff)
Add automatic detection of number of results.
Tofi will now try to autodetect how many results can be drawn if --num-results=0 is specified, which is now the default.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index ef0dc48..9429408 100644
--- a/src/main.c
+++ b/src/main.c
@@ -201,6 +201,11 @@ static void wl_keyboard_key(
return;
}
+ uint32_t num_results = tofi->window.entry.num_results;
+ if (num_results == 0) {
+ num_results = tofi->window.entry.num_results_drawn;
+ }
+ uint32_t nsel = MAX(MIN(num_results, tofi->window.entry.results.count), 1);
if (sym == XKB_KEY_Up || sym == XKB_KEY_Left
|| (sym == XKB_KEY_k
&& xkb_state_mod_name_is_active(
@@ -209,7 +214,6 @@ static void wl_keyboard_key(
XKB_STATE_MODS_EFFECTIVE)
)
) {
- uint32_t nsel = MAX(MIN(tofi->window.entry.num_results, tofi->window.entry.results.count), 1);
tofi->window.entry.selection += nsel;
tofi->window.entry.selection--;
tofi->window.entry.selection %= nsel;
@@ -221,7 +225,6 @@ static void wl_keyboard_key(
XKB_STATE_MODS_EFFECTIVE)
)
) {
- uint32_t nsel = MAX(MIN(tofi->window.entry.num_results, tofi->window.entry.results.count), 1);
tofi->window.entry.selection++;
tofi->window.entry.selection %= nsel;
} else {
@@ -839,7 +842,6 @@ int main(int argc, char *argv[])
.font_name = "Sans",
.font_size = 24,
.prompt_text = "run: ",
- .num_results = 5,
.padding_top = 8,
.padding_bottom = 8,
.padding_left = 8,