diff --git a/docs/example.Xresources b/docs/example.Xresources index 814f579..93f022f 100644 --- a/docs/example.Xresources +++ b/docs/example.Xresources @@ -124,6 +124,11 @@ spmenu.indentitems: 0 spmenu.maxhist: 64 spmenu.histdup: 0 +!! Caret +spmenu.caretwidth: 0 +spmenu.caretheight: 0 +spmenu.caretpadding: 0 + !! Matches spmenu.type: 1 spmenu.passwd: 0 diff --git a/docs/spmenu.conf b/docs/spmenu.conf index 5c62143..753b313 100644 --- a/docs/spmenu.conf +++ b/docs/spmenu.conf @@ -216,6 +216,12 @@ spmenu = { password = 0; // Don't read standard input and replace all characters with the password character (0/1) } ); + /* Caret options */ + caret = ( { width = 0; // Caret width (0: Default) (px) + height = 0; // Caret height (0: Default) (px) + padding = 0; // Caret padding (px) + } ); + /* Output options */ output = ( { printindex = 0; // Print index instead of actual text (0/1) incremental = 0; // Print text on every keypress (0/1) diff --git a/libs/conf/config.c b/libs/conf/config.c index f55cd2e..4b50f4a 100644 --- a/libs/conf/config.c +++ b/libs/conf/config.c @@ -454,6 +454,19 @@ void conf_init(void) { } } + // load options spmenu.caret + config_setting_t *caret_setting = config_lookup(&cfg, "spmenu.caret"); + if (caret_setting != NULL && loadconfig) { + for (unsigned int i = 0; i < config_setting_length(caret_setting); ++i) { + config_setting_t *conf = config_setting_get_elem(caret_setting, i); + + // look up + config_setting_lookup_int(conf, "width", &caretwidth); // spmenu.caret.width + config_setting_lookup_int(conf, "height", &caretheight); // spmenu.caret.height + config_setting_lookup_int(conf, "padding", &caretpadding); // spmenu.caret.padding + } + } + // load options spmenu.output config_setting_t *output_setting = config_lookup(&cfg, "spmenu.output"); if (output_setting != NULL && loadconfig) { diff --git a/libs/draw.c b/libs/draw.c index 1572c2a..71b6d7f 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -375,7 +375,15 @@ int drawprompt(int x, int y, int w) { int drawinput(int x, int y, int w) { char *censort; // censor text (password) unsigned int curpos = 0; - int fh = drw->font->h; + int fh = caretheight; + int fw = MAX(2, caretwidth); + int fp = caretpadding; + + if (fh > bh) { + fh = bh; + } else if (!fh) { + fh = drw->font->h; + } if (passwd) { censort = ecalloc(1, sizeof(text)); @@ -397,7 +405,8 @@ int drawinput(int x, int y, int w) { } if ((curpos += lrpad / 2 - 1) < w && !hidecaret && cursorstate) { - drw_rect(drw, x + curpos, 2 + (bh - fh) / 2 + y, 2, fh - 4, 1, 0, col_caretfg, col_caretbg, alpha_caretfg, alpha_caretbg); + curpos += fp; + drw_rect(drw, x + curpos, 2 + (bh - fh) / 2 + y, fw, fh - 4, 1, 0, col_caretfg, col_caretbg, alpha_caretfg, alpha_caretbg); } return x; diff --git a/libs/options.h b/libs/options.h index c4b4067..e2e03dd 100644 --- a/libs/options.h +++ b/libs/options.h @@ -25,8 +25,8 @@ static char *bindsfile = NULL; /* Keybind file path. Default is /* Window options */ static int alpha = 1; /* Enable alpha */ static int menuposition = 2; /* Position of the menu (0: Bottom, 1: Top, 2: Center */ -static int menupaddingv = 0; /* Vertical padding inside the menu (in pixels) */ -static int menupaddingh = 0; /* Horizontal padding inside the menu (in pixels) */ +static int menupaddingv = 0; /* Vertical padding inside the menu (px) */ +static int menupaddingh = 0; /* Horizontal padding inside the menu (px) */ static int menuwidth = 0; /* spmenu width */ static int menumarginv = 0; /* Vertical padding around the menu */ static int menumarginh = 0; /* Horizontal padding around the menu */ @@ -103,6 +103,11 @@ static int histdup = 0; /* If 1, record repeated histories * /* Prompt options */ static int indentitems = 0; /* Indent items to prompt width? (0/1) */ +/* Caret options */ +static int caretwidth = 0; /* Caret width (0: Calculate automatically) */ +static int caretheight = 0; /* Caret height (0: Calculate automatically) */ +static int caretpadding = 0; /* Caret padding (px) */ + /* Hide options */ static int hideinput = 0; /* Hide input (0/1) */ static int hidelarrow = 0; /* Hide left arrow (0/1) */ diff --git a/libs/theme/theme.c b/libs/theme/theme.c index 51432c5..f4896fb 100644 --- a/libs/theme/theme.c +++ b/libs/theme/theme.c @@ -74,6 +74,19 @@ void theme_load(void) { } } + // load options theme.caret + config_setting_t *caret_setting = config_lookup(&cfg, "theme.caret"); + if (caret_setting != NULL && loadconfig) { + for (unsigned int i = 0; i < config_setting_length(caret_setting); ++i) { + config_setting_t *conf = config_setting_get_elem(caret_setting, i); + + // look up + config_setting_lookup_int(conf, "width", &caretwidth); // spmenu.caret.width + config_setting_lookup_int(conf, "height", &caretheight); // spmenu.caret.height + config_setting_lookup_int(conf, "padding", &caretpadding); // spmenu.caret.padding + } + } + // load options theme.powerline config_setting_t *pwl_setting = config_lookup(&cfg, "theme.powerline"); if (pwl_setting != NULL) { diff --git a/libs/x11/xresources.h b/libs/x11/xresources.h index fad70ca..e12411f 100644 --- a/libs/x11/xresources.h +++ b/libs/x11/xresources.h @@ -110,6 +110,9 @@ ResourcePref resources[] = { { "menuposition", INTEGER, &menuposition }, { "xpos", INTEGER, &xpos }, { "ypos", INTEGER, &ypos }, + { "caretpadding", INTEGER, &caretpadding }, + { "caretwidth", INTEGER, &caretwidth }, + { "caretheight", INTEGER, &caretheight }, { "menuwidth", INTEGER, &menuwidth }, { "menupaddingv", INTEGER, &menupaddingv }, { "menupaddingh", INTEGER, &menupaddingh },