diff options
author | Josh Rahm <rahm@google.com> | 2023-01-27 23:04:47 +0000 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2023-01-27 23:04:47 +0000 |
commit | e64dc03ff7b867826c7fc76d6fff210ad3382e33 (patch) | |
tree | 9cf71b02a7ee8f6d39ae1207201dc0745bdb8be5 /menu.c | |
parent | fb15fd116097b98c1b839cfdc76a7d84e206e6d5 (diff) | |
parent | f5af3cfb211c12897b15e3b5a3b29c4bbb0493a8 (diff) | |
download | rtmux-e64dc03ff7b867826c7fc76d6fff210ad3382e33.tar.gz rtmux-e64dc03ff7b867826c7fc76d6fff210ad3382e33.tar.bz2 rtmux-e64dc03ff7b867826c7fc76d6fff210ad3382e33.zip |
Merge remote-tracking branch 'upstream/master' into rahm
Diffstat (limited to 'menu.c')
-rw-r--r-- | menu.c | 120 |
1 files changed, 89 insertions, 31 deletions
@@ -323,27 +323,64 @@ menu_key_cb(struct client *c, void *data, struct key_event *event) } while ((name == NULL || *name == '-') && md->choice != old); c->flags |= CLIENT_REDRAWOVERLAY; return (0); - case 'g': case KEYC_PPAGE: case '\002': /* C-b */ - if (md->choice > 5) - md->choice -= 5; - else + if (md->choice < 6) md->choice = 0; - while (md->choice != count && (name == NULL || *name == '-')) - md->choice++; - if (md->choice == count) - md->choice = -1; + else { + i = 5; + while (i > 0) { + md->choice--; + name = menu->items[md->choice].name; + if (md->choice != 0 && + (name != NULL && *name != '-')) + i--; + else if (md->choice == 0) + break; + } + } c->flags |= CLIENT_REDRAWOVERLAY; break; - case 'G': case KEYC_NPAGE: - if (md->choice > count - 6) + if (md->choice > count - 6) { md->choice = count - 1; - else - md->choice += 5; - while (md->choice != -1 && (name == NULL || *name == '-')) + name = menu->items[md->choice].name; + } else { + i = 5; + while (i > 0) { + md->choice++; + name = menu->items[md->choice].name; + if (md->choice != count - 1 && + (name != NULL && *name != '-')) + i++; + else if (md->choice == count - 1) + break; + } + } + while (name == NULL || *name == '-') { md->choice--; + name = menu->items[md->choice].name; + } + c->flags |= CLIENT_REDRAWOVERLAY; + break; + case 'g': + case KEYC_HOME: + md->choice = 0; + name = menu->items[md->choice].name; + while (name == NULL || *name == '-') { + md->choice++; + name = menu->items[md->choice].name; + } + c->flags |= CLIENT_REDRAWOVERLAY; + break; + case 'G': + case KEYC_END: + md->choice = count - 1; + name = menu->items[md->choice].name; + while (name == NULL || *name == '-') { + md->choice--; + name = menu->items[md->choice].name; + } c->flags |= CLIENT_REDRAWOVERLAY; break; case '\006': /* C-f */ @@ -390,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) @@ -420,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; @@ -439,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, |