mirror of
https://github.com/Cloudef/bemenu
synced 2025-03-30 07:18:34 +00:00
Add option to configure cursor height
If set to 0 (the default), the height of the cursor is set to the height of the line (as is the current behaviour).
This commit is contained in:
parent
a42fa97a49
commit
0589962d1c
@ -197,6 +197,7 @@ usage(FILE *out, const char *name)
|
|||||||
" -n, --no-overlap adjust geometry to not overlap with panels. (w)\n"
|
" -n, --no-overlap adjust geometry to not overlap with panels. (w)\n"
|
||||||
" -m, --monitor index of monitor where menu will appear. (wx)\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"
|
" -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"
|
" --fn defines the font to be used ('name [size]'). (wx)\n"
|
||||||
" --tb defines the title background color. (wx)\n"
|
" --tb defines the title background color. (wx)\n"
|
||||||
" --tf defines the title foreground 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' },
|
{ "no-overlap", no_argument, 0, 'n' },
|
||||||
{ "monitor", required_argument, 0, 'm' },
|
{ "monitor", required_argument, 0, 'm' },
|
||||||
{ "line-height", required_argument, 0, 'H' },
|
{ "line-height", required_argument, 0, 'H' },
|
||||||
|
{ "ch", required_argument, 0, 0x118 },
|
||||||
{ "fn", required_argument, 0, 0x101 },
|
{ "fn", required_argument, 0, 0x101 },
|
||||||
{ "tb", required_argument, 0, 0x102 },
|
{ "tb", required_argument, 0, 0x102 },
|
||||||
{ "tf", required_argument, 0, 0x103 },
|
{ "tf", required_argument, 0, 0x103 },
|
||||||
@ -355,6 +357,9 @@ do_getopt(struct client *client, int *argc, char **argv[])
|
|||||||
case 'H':
|
case 'H':
|
||||||
client->line_height = strtol(optarg, NULL, 10);
|
client->line_height = strtol(optarg, NULL, 10);
|
||||||
break;
|
break;
|
||||||
|
case 0x118:
|
||||||
|
client->cursor_height = strtol(optarg, NULL, 10);
|
||||||
|
break;
|
||||||
case 0x101:
|
case 0x101:
|
||||||
client->font = optarg;
|
client->font = optarg;
|
||||||
break;
|
break;
|
||||||
@ -433,6 +438,7 @@ menu_with_options(struct client *client)
|
|||||||
|
|
||||||
bm_menu_set_font(menu, client->font);
|
bm_menu_set_font(menu, client->font);
|
||||||
bm_menu_set_line_height(menu, client->line_height);
|
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_title(menu, client->title);
|
||||||
bm_menu_set_prefix(menu, client->prefix);
|
bm_menu_set_prefix(menu, client->prefix);
|
||||||
bm_menu_set_filter_mode(menu, client->filter_mode);
|
bm_menu_set_filter_mode(menu, client->filter_mode);
|
||||||
|
@ -13,6 +13,7 @@ struct client {
|
|||||||
const char *font;
|
const char *font;
|
||||||
const char *initial_filter;
|
const char *initial_filter;
|
||||||
uint32_t line_height;
|
uint32_t line_height;
|
||||||
|
uint32_t cursor_height;
|
||||||
uint32_t lines;
|
uint32_t lines;
|
||||||
uint32_t selected;
|
uint32_t selected;
|
||||||
uint32_t monitor;
|
uint32_t monitor;
|
||||||
|
17
lib/bemenu.h
17
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);
|
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.
|
* Set a hexadecimal color for element.
|
||||||
*
|
*
|
||||||
|
@ -238,6 +238,11 @@ struct bm_menu {
|
|||||||
*/
|
*/
|
||||||
uint32_t line_height;
|
uint32_t line_height;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cursor height.
|
||||||
|
*/
|
||||||
|
uint32_t cursor_height;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Colors.
|
* Colors.
|
||||||
*/
|
*/
|
||||||
|
14
lib/menu.c
14
lib/menu.c
@ -296,6 +296,20 @@ bm_menu_get_line_height(struct bm_menu *menu)
|
|||||||
return menu->line_height;
|
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
|
bool
|
||||||
bm_menu_set_color(struct bm_menu *menu, enum bm_color color, const char *hex)
|
bm_menu_set_color(struct bm_menu *menu, enum bm_color color, const char *hex)
|
||||||
{
|
{
|
||||||
|
@ -25,6 +25,7 @@ struct cairo_paint {
|
|||||||
const char *font;
|
const char *font;
|
||||||
int32_t baseline;
|
int32_t baseline;
|
||||||
uint32_t cursor;
|
uint32_t cursor;
|
||||||
|
uint32_t cursor_height;
|
||||||
bool draw_cursor;
|
bool draw_cursor;
|
||||||
|
|
||||||
struct box {
|
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;
|
height = paint->box.h > 0 ? paint->box.h : height;
|
||||||
int base = pango_layout_get_baseline(layout) / PANGO_SCALE;
|
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_set_source_rgba(cairo->cr, paint->bg.r, paint->bg.b, paint->bg.g, paint->bg.a);
|
||||||
cairo_rectangle(cairo->cr,
|
cairo_rectangle(cairo->cr,
|
||||||
paint->pos.x - paint->box.lx, paint->pos.y - paint->box.ty,
|
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,
|
(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_fill(cairo->cr);
|
||||||
|
|
||||||
cairo_set_source_rgba(cairo->cr, paint->fg.r, paint->fg.b, paint->fg.g, paint->fg.a);
|
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;
|
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_set_source_rgba(cairo->cr, paint->fg.r, paint->fg.b, paint->fg.g, paint->fg.a);
|
||||||
cairo_rectangle(cairo->cr,
|
cairo_rectangle(cairo->cr,
|
||||||
paint->pos.x + paint->box.lx + rect.x / PANGO_SCALE, paint->pos.y - 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, height + paint->box.by + paint->box.ty);
|
rect.width / PANGO_SCALE, cursor_height);
|
||||||
cairo_fill(cairo->cr);
|
cairo_fill(cairo->cr);
|
||||||
|
|
||||||
cairo_rectangle(cairo->cr,
|
cairo_rectangle(cairo->cr,
|
||||||
paint->pos.x + paint->box.lx + rect.x / PANGO_SCALE, paint->pos.y - paint->box.ty,
|
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_clip(cairo->cr);
|
||||||
|
|
||||||
cairo_set_source_rgba(cairo->cr, paint->bg.r, paint->bg.b, paint->bg.g, paint->bg.a);
|
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);
|
g_object_unref(layout);
|
||||||
|
|
||||||
result->x_advance = width + paint->box.rx;
|
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);
|
cairo_identity_matrix(cairo->cr);
|
||||||
return true;
|
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);
|
bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_BG, &paint.bg);
|
||||||
paint.draw_cursor = true;
|
paint.draw_cursor = true;
|
||||||
paint.cursor = menu->cursor;
|
paint.cursor = menu->cursor;
|
||||||
|
paint.cursor_height = menu->cursor_height;
|
||||||
paint.pos = (struct pos){ (menu->title ? 2 : 0) + result.x_advance, vpadding };
|
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 };
|
paint.box = (struct box){ (menu->title ? 2 : 4), 0, vpadding, vpadding, width - paint.pos.x, ascii_height };
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user