From b770a429c63a8e286dbd3939215fbffa59e73d9a Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 15 Aug 2023 07:01:47 +0000 Subject: Add an option menu-selected-style to configure the currently selected menu item, from Alexis Hildebrandt. --- menu.c | 62 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 30 deletions(-) (limited to 'menu.c') diff --git a/menu.c b/menu.c index 4d2fb95a..8d7b40a2 100644 --- a/menu.c +++ b/menu.c @@ -29,6 +29,7 @@ struct menu_data { struct grid_cell style; struct grid_cell border_style; + struct grid_cell selected_style; enum box_lines border_lines; struct cmd_find_state fs; @@ -201,7 +202,6 @@ menu_draw_cb(struct client *c, void *data, struct menu *menu = md->menu; struct screen_write_ctx ctx; u_int i, px = md->px, py = md->py; - struct grid_cell gc; screen_write_start(&ctx, s); screen_write_clearscreen(&ctx, 8); @@ -210,10 +210,9 @@ menu_draw_cb(struct client *c, void *data, screen_write_box(&ctx, menu->width + 4, menu->count + 2, md->border_lines, &md->border_style, menu->title); } - style_apply(&gc, c->session->curw->window->options, "mode-style", NULL); screen_write_menu(&ctx, menu, md->choice, md->border_lines, - &md->style, &md->border_style, &gc); + &md->style, &md->border_style, &md->selected_style); screen_write_stop(&ctx); for (i = 0; i < screen_size_y(&md->s); i++) { @@ -438,16 +437,35 @@ chosen: return (1); } +static void +menu_set_style(struct client *c, struct grid_cell *gc, const char *style, + const char *option) +{ + struct style sytmp; + struct options *o = c->session->curw->window->options; + + memcpy(gc, &grid_default_cell, sizeof *gc); + style_apply(gc, o, option, NULL); + if (style != NULL) { + style_set(&sytmp, &grid_default_cell); + if (style_parse(&sytmp, gc, style) == 0) { + gc->fg = sytmp.gc.fg; + gc->bg = sytmp.gc.bg; + } + } + gc->attr = 0; +} + struct menu_data * menu_prepare(struct menu *menu, int flags, int starting_choice, struct cmdq_item *item, u_int px, u_int py, struct client *c, - enum box_lines lines, const char *style, const char *border_style, - struct cmd_find_state *fs, menu_choice_cb cb, void *data) + enum box_lines lines, const char *style, const char *selected_style, + const char *border_style, struct cmd_find_state *fs, menu_choice_cb cb, + void *data) { struct menu_data *md; int choice; const char *name; - struct style sytmp; struct options *o = c->session->curw->window->options; if (c->tty.sx < menu->width + 4 || c->tty.sy < menu->count + 2) @@ -465,27 +483,10 @@ menu_prepare(struct menu *menu, int flags, int starting_choice, md->flags = flags; md->border_lines = lines; - memcpy(&md->style, &grid_default_cell, sizeof md->style); - style_apply(&md->style, o, "menu-style", NULL); - if (style != NULL) { - style_set(&sytmp, &grid_default_cell); - if (style_parse(&sytmp, &md->style, style) == 0) { - md->style.fg = sytmp.gc.fg; - md->style.bg = sytmp.gc.bg; - } - } - md->style.attr = 0; - - memcpy(&md->border_style, &grid_default_cell, sizeof md->border_style); - style_apply(&md->border_style, o, "menu-border-style", NULL); - if (border_style != NULL) { - style_set(&sytmp, &grid_default_cell); - if (style_parse(&sytmp, &md->border_style, border_style) == 0) { - md->border_style.fg = sytmp.gc.fg; - md->border_style.bg = sytmp.gc.bg; - } - } - md->border_style.attr = 0; + menu_set_style(c, &md->style, style, "menu-style"); + menu_set_style(c, &md->selected_style, selected_style, + "menu-selected-style"); + menu_set_style(c, &md->border_style, border_style, "menu-border-style"); if (fs != NULL) cmd_find_copy_state(&md->fs, fs); @@ -539,13 +540,14 @@ menu_prepare(struct menu *menu, int flags, int starting_choice, int menu_display(struct menu *menu, int flags, int starting_choice, struct cmdq_item *item, u_int px, u_int py, struct client *c, - enum box_lines lines, const char *style, const char *border_style, - struct cmd_find_state *fs, menu_choice_cb cb, void *data) + enum box_lines lines, const char *style, const char *selected_style, + const char *border_style, struct cmd_find_state *fs, menu_choice_cb cb, + void *data) { struct menu_data *md; md = menu_prepare(menu, flags, starting_choice, item, px, py, c, lines, - style, border_style, fs, cb, data); + style, selected_style, border_style, fs, cb, data); if (md == NULL) return (-1); server_client_set_overlay(c, 0, NULL, menu_mode_cb, menu_draw_cb, -- cgit v1.2.3