summaryrefslogtreecommitdiffstats
path: root/menu.c
diff options
context:
space:
mode:
authornicm <nicm>2023-01-20 21:36:00 +0000
committernicm <nicm>2023-01-20 21:36:00 +0000
commit3aa458ea6398b0de37c3e146304bd2a4e17ea3c0 (patch)
treec7940f0d27db91583fd08b9099409a8998a6b087 /menu.c
parent9789ea3fb4b3215e48b3f0024e2c21c50f95edec (diff)
Add a flag to display-menu to select the manu item chosen first, GitHub
issue 3442.
Diffstat (limited to 'menu.c')
-rw-r--r--menu.c57
1 files changed, 39 insertions, 18 deletions
diff --git a/menu.c b/menu.c
index 4aad1d8c..0ff180aa 100644
--- a/menu.c
+++ b/menu.c
@@ -427,12 +427,12 @@ chosen:
}
struct menu_data *
-menu_prepare(struct menu *menu, int flags, struct cmdq_item *item, u_int px,
- u_int py, struct client *c, struct cmd_find_state *fs, menu_choice_cb cb,
- void *data)
+menu_prepare(struct menu *menu, int flags, int starting_choice,
+ struct cmdq_item *item, u_int px, u_int py, struct client *c,
+ struct cmd_find_state *fs, menu_choice_cb cb, void *data)
{
struct menu_data *md;
- u_int i;
+ int choice;
const char *name;
if (c->tty.sx < menu->width + 4 || c->tty.sy < menu->count + 2)
@@ -457,18 +457,38 @@ menu_prepare(struct menu *menu, int flags, struct cmdq_item *item, u_int px,
md->py = py;
md->menu = menu;
+ md->choice = -1;
+
if (md->flags & MENU_NOMOUSE) {
- for (i = 0; i < menu->count; i++) {
- name = menu->items[i].name;
- if (name != NULL && *name != '-')
- break;
+ if (starting_choice >= (int)menu->count) {
+ starting_choice = menu->count - 1;
+ choice = starting_choice + 1;
+ for (;;) {
+ name = menu->items[choice - 1].name;
+ if (name != NULL && *name != '-') {
+ md->choice = choice - 1;
+ break;
+ }
+ if (--choice == 0)
+ choice = menu->count;
+ if (choice == starting_choice + 1)
+ break;
+ }
+ } else if (starting_choice >= 0) {
+ choice = starting_choice;
+ for (;;) {
+ name = menu->items[choice].name;
+ if (name != NULL && *name != '-') {
+ md->choice = choice;
+ break;
+ }
+ if (++choice == (int)menu->count)
+ choice = 0;
+ if (choice == starting_choice)
+ break;
+ }
}
- if (i != menu->count)
- md->choice = i;
- else
- md->choice = -1;
- } else
- md->choice = -1;
+ }
md->cb = cb;
md->data = data;
@@ -476,13 +496,14 @@ menu_prepare(struct menu *menu, int flags, struct cmdq_item *item, u_int px,
}
int
-menu_display(struct menu *menu, int flags, struct cmdq_item *item, u_int px,
- u_int py, struct client *c, struct cmd_find_state *fs, menu_choice_cb cb,
- void *data)
+menu_display(struct menu *menu, int flags, int starting_choice,
+ struct cmdq_item *item, u_int px, u_int py, struct client *c,
+ struct cmd_find_state *fs, menu_choice_cb cb, void *data)
{
struct menu_data *md;
- md = menu_prepare(menu, flags, item, px, py, c, fs, cb, data);
+ md = menu_prepare(menu, flags, starting_choice, item, px, py, c, fs, cb,
+ data);
if (md == NULL)
return (-1);
server_client_set_overlay(c, 0, NULL, menu_mode_cb, menu_draw_cb,