diff --git a/client/common/common.c b/client/common/common.c index ebc55e7..ea52b35 100644 --- a/client/common/common.c +++ b/client/common/common.c @@ -197,6 +197,7 @@ usage(FILE *out, const char *name) " -n, --no-overlap adjust geometry to not overlap with panels. (w)\n" " -m, --monitor index of monitor where menu will appear. (wx)\n" " -H, --line-height defines the height to make each menu line (0 = default height). (wx)\n" + " --ch defines the height of the cursor (0 = scales with line height). (wx)\n" " --fn defines the font to be used ('name [size]'). (wx)\n" " --tb defines the title background color. (wx)\n" " --tf defines the title foreground color. (wx)\n" @@ -260,6 +261,7 @@ do_getopt(struct client *client, int *argc, char **argv[]) { "no-overlap", no_argument, 0, 'n' }, { "monitor", required_argument, 0, 'm' }, { "line-height", required_argument, 0, 'H' }, + { "ch", required_argument, 0, 0x118 }, { "fn", required_argument, 0, 0x101 }, { "tb", required_argument, 0, 0x102 }, { "tf", required_argument, 0, 0x103 }, @@ -355,6 +357,9 @@ do_getopt(struct client *client, int *argc, char **argv[]) case 'H': client->line_height = strtol(optarg, NULL, 10); break; + case 0x118: + client->cursor_height = strtol(optarg, NULL, 10); + break; case 0x101: client->font = optarg; break; @@ -433,6 +438,7 @@ menu_with_options(struct client *client) bm_menu_set_font(menu, client->font); bm_menu_set_line_height(menu, client->line_height); + bm_menu_set_cursor_height(menu, client->cursor_height); bm_menu_set_title(menu, client->title); bm_menu_set_prefix(menu, client->prefix); bm_menu_set_filter_mode(menu, client->filter_mode); diff --git a/client/common/common.h b/client/common/common.h index dba46eb..6543472 100644 --- a/client/common/common.h +++ b/client/common/common.h @@ -13,6 +13,7 @@ struct client { const char *font; const char *initial_filter; uint32_t line_height; + uint32_t cursor_height; uint32_t lines; uint32_t selected; uint32_t monitor; diff --git a/lib/bemenu.h b/lib/bemenu.h index 0d64a84..b9b981e 100644 --- a/lib/bemenu.h +++ b/lib/bemenu.h @@ -448,6 +448,23 @@ BM_PUBLIC void bm_menu_set_line_height(struct bm_menu *menu, uint32_t line_heigh */ BM_PUBLIC uint32_t bm_menu_get_line_height(struct bm_menu *menu); +/** + * Set height of cursor in pixels. + * Some renderers such as ncurses may ignore this when it does not make sense. + * + * @param menu bm_menu instance where to set cursor height. + * @param cursor_height 0 for default cursor height, > 0 for that many pixels. + */ +BM_PUBLIC void bm_menu_set_cursor_height(struct bm_menu *menu, uint32_t cursor_height); + +/** + * Get height of cursor in pixels. + * + * @param menu bm_menu instance where to get cursor height. + * @return uint32_t for max amount of vertical cursors to be shown. + */ +BM_PUBLIC uint32_t bm_menu_get_cursor_height(struct bm_menu *menu); + /** * Set a hexadecimal color for element. * diff --git a/lib/internal.h b/lib/internal.h index 959dc22..ad8afe8 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -238,6 +238,11 @@ struct bm_menu { */ uint32_t line_height; + /** + * Cursor height. + */ + uint32_t cursor_height; + /** * Colors. */ diff --git a/lib/menu.c b/lib/menu.c index 52af1c1..caa7238 100644 --- a/lib/menu.c +++ b/lib/menu.c @@ -296,6 +296,20 @@ bm_menu_get_line_height(struct bm_menu *menu) return menu->line_height; } +void +bm_menu_set_cursor_height(struct bm_menu *menu, uint32_t cursor_height) +{ + assert(menu); + menu->cursor_height = cursor_height; +} + +uint32_t +bm_menu_get_cursor_height(struct bm_menu *menu) +{ + assert(menu); + return menu->cursor_height; +} + bool bm_menu_set_color(struct bm_menu *menu, enum bm_color color, const char *hex) { diff --git a/lib/renderers/cairo_renderer.h b/lib/renderers/cairo_renderer.h index 0b9bb1e..a61bbc3 100644 --- a/lib/renderers/cairo_renderer.h +++ b/lib/renderers/cairo_renderer.h @@ -25,6 +25,7 @@ struct cairo_paint { const char *font; int32_t baseline; uint32_t cursor; + uint32_t cursor_height; bool draw_cursor; struct box { @@ -131,11 +132,12 @@ bm_cairo_draw_line_str(struct cairo *cairo, struct cairo_paint *paint, struct ca height = paint->box.h > 0 ? paint->box.h : height; int base = pango_layout_get_baseline(layout) / PANGO_SCALE; + uint32_t line_height = height + paint->box.by + paint->box.ty; cairo_set_source_rgba(cairo->cr, paint->bg.r, paint->bg.b, paint->bg.g, paint->bg.a); cairo_rectangle(cairo->cr, paint->pos.x - paint->box.lx, paint->pos.y - paint->box.ty, (paint->box.w > 0 ? paint->box.w : width) + paint->box.rx + paint->box.lx, - height + paint->box.by + paint->box.ty); + line_height); cairo_fill(cairo->cr); cairo_set_source_rgba(cairo->cr, paint->fg.r, paint->fg.b, paint->fg.g, paint->fg.a); @@ -152,15 +154,16 @@ bm_cairo_draw_line_str(struct cairo *cairo, struct cairo_paint *paint, struct ca rect.width = result.x_advance * PANGO_SCALE; } + uint32_t cursor_height = fmin(paint->cursor_height == 0 ? line_height : paint->cursor_height, line_height); cairo_set_source_rgba(cairo->cr, paint->fg.r, paint->fg.b, paint->fg.g, paint->fg.a); cairo_rectangle(cairo->cr, - paint->pos.x + paint->box.lx + rect.x / PANGO_SCALE, paint->pos.y - paint->box.ty, - rect.width / PANGO_SCALE, height + paint->box.by + paint->box.ty); + paint->pos.x + paint->box.lx + rect.x / PANGO_SCALE, paint->pos.y - paint->box.ty + ((line_height - cursor_height) / 2), + rect.width / PANGO_SCALE, cursor_height); cairo_fill(cairo->cr); cairo_rectangle(cairo->cr, paint->pos.x + paint->box.lx + rect.x / PANGO_SCALE, paint->pos.y - paint->box.ty, - rect.width / PANGO_SCALE, height + paint->box.by + paint->box.ty); + rect.width / PANGO_SCALE, line_height); cairo_clip(cairo->cr); cairo_set_source_rgba(cairo->cr, paint->bg.r, paint->bg.b, paint->bg.g, paint->bg.a); @@ -172,7 +175,7 @@ bm_cairo_draw_line_str(struct cairo *cairo, struct cairo_paint *paint, struct ca g_object_unref(layout); result->x_advance = width + paint->box.rx; - result->height = height + paint->box.by + paint->box.ty; + result->height = line_height; cairo_identity_matrix(cairo->cr); return true; @@ -251,6 +254,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, const s bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_BG, &paint.bg); paint.draw_cursor = true; paint.cursor = menu->cursor; + paint.cursor_height = menu->cursor_height; paint.pos = (struct pos){ (menu->title ? 2 : 0) + result.x_advance, vpadding }; paint.box = (struct box){ (menu->title ? 2 : 4), 0, vpadding, vpadding, width - paint.pos.x, ascii_height };