mirror of
https://codeberg.org/adnano/wmenu.git
synced 2025-10-29 05:40:20 -04:00
Add wmenu -H flag
This flag allows the user to specify the line height usually in terms of pixels.
This commit is contained in:
parent
fc69aa6e2b
commit
3725c6fadc
4 changed files with 21 additions and 7 deletions
|
|
@ -7,6 +7,7 @@ wmenu - dynamic menu for Wayland
|
|||
# SYNOPSIS
|
||||
|
||||
*wmenu* [-biPv] \
|
||||
[-H _height_] \
|
||||
[-f _font_] \
|
||||
[-l _lines_] \
|
||||
[-o _output_] \
|
||||
|
|
@ -42,6 +43,10 @@ $PATH and runs the result.
|
|||
*-v*
|
||||
prints version information to stdout, then exits.
|
||||
|
||||
*-H* _height_
|
||||
defines the height of a line (usually in pixels). For more information,
|
||||
see https://docs.gtk.org/Pango/const.SCALE.html
|
||||
|
||||
*-f* _font_
|
||||
defines the font used. For more information, see
|
||||
https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html
|
||||
|
|
|
|||
15
menu.c
15
menu.c
|
|
@ -89,7 +89,8 @@ void menu_getopts(struct menu *menu, int argc, char *argv[]) {
|
|||
"\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n";
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "bhiPvf:l:o:p:N:n:M:m:S:s:")) != -1) {
|
||||
int line_height = 0;
|
||||
while ((opt = getopt(argc, argv, "bhiPvH:f:l:o:p:N:n:M:m:S:s:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'b':
|
||||
menu->bottom = true;
|
||||
|
|
@ -103,6 +104,9 @@ void menu_getopts(struct menu *menu, int argc, char *argv[]) {
|
|||
case 'v':
|
||||
puts("wmenu " VERSION);
|
||||
exit(EXIT_SUCCESS);
|
||||
case 'H':
|
||||
line_height = atoi(optarg);
|
||||
break;
|
||||
case 'f':
|
||||
menu->font = optarg;
|
||||
break;
|
||||
|
|
@ -156,13 +160,16 @@ void menu_getopts(struct menu *menu, int argc, char *argv[]) {
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int height = get_font_height(menu->font);
|
||||
menu->line_height = height + 2;
|
||||
menu->font_height = get_font_height(menu->font);
|
||||
menu->line_height = menu->font_height + 2;
|
||||
if(line_height > menu->line_height) {
|
||||
menu->line_height = line_height;
|
||||
}
|
||||
menu->height = menu->line_height;
|
||||
if (menu->lines > 0) {
|
||||
menu->height += menu->height * menu->lines;
|
||||
}
|
||||
menu->padding = height / 2;
|
||||
menu->padding = menu->font_height / 2;
|
||||
}
|
||||
|
||||
// Add an item to the menu.
|
||||
|
|
|
|||
1
menu.h
1
menu.h
|
|
@ -58,6 +58,7 @@ struct menu {
|
|||
|
||||
int width;
|
||||
int height;
|
||||
int font_height;
|
||||
int line_height;
|
||||
int padding;
|
||||
int inputw;
|
||||
|
|
|
|||
7
render.c
7
render.c
|
|
@ -107,12 +107,13 @@ static void render_input(struct menu *menu, cairo_t *cairo) {
|
|||
static void render_cursor(struct menu *menu, cairo_t *cairo) {
|
||||
const int cursor_width = 2;
|
||||
const int cursor_margin = 2;
|
||||
int cursor_pos = menu->promptw + menu->padding
|
||||
int cursor_x_pos = menu->promptw + menu->padding
|
||||
+ text_width(cairo, menu->font, menu->input)
|
||||
- text_width(cairo, menu->font, &menu->input[menu->cursor])
|
||||
- cursor_width / 2;
|
||||
cairo_rectangle(cairo, cursor_pos, cursor_margin, cursor_width,
|
||||
menu->line_height - 2 * cursor_margin);
|
||||
int cursor_y_pos = (menu->line_height - menu->font_height) / 2 + cursor_margin;
|
||||
cairo_rectangle(cairo, cursor_x_pos, cursor_y_pos, cursor_width,
|
||||
menu->font_height - cursor_margin);
|
||||
cairo_fill(cairo);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue