From 6b20fe939e2039ea6cd841f2182b5892e5056f92 Mon Sep 17 00:00:00 2001 From: speedie Date: Thu, 17 Aug 2023 14:56:37 +0200 Subject: [PATCH] Add --min-lines option --- docs/docs.md | 6 ++++++ docs/spmenu.conf | 3 ++- libs/arg.c | 4 +++- libs/argv.c | 7 +++++-- libs/conf/config.c | 1 + libs/options.h | 1 + libs/stream.c | 4 ++-- libs/wl/wayland.c | 2 +- libs/x11/client.c | 2 +- spmenu.1 | 8 +++++++- spmenu_run.1 | 2 +- spmenu_test.1 | 2 +- 12 files changed, 31 insertions(+), 11 deletions(-) diff --git a/docs/docs.md b/docs/docs.md index 963d481..636bf83 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -43,9 +43,15 @@ in the config files. `-cw, --center-width width` : Set width to width when centered +`-l, --lines lines` +: Set the number of lines to lines + `-g, --columns grid` : Set the number of grids to grid +`-ml, --min-lines` +: Set minimum number of lines allowed to lines + `-gc, --generate-cache` : Generate image cache diff --git a/docs/spmenu.conf b/docs/spmenu.conf index c98b116..9f9438c 100644 --- a/docs/spmenu.conf +++ b/docs/spmenu.conf @@ -247,6 +247,7 @@ spmenu = { columns = 10; // Number of columns (number) overridelines = 1; // Allow overriding lines using keybinds (0/1) overridecolumns = 1; // Allow overriding columns using keybinds (0/1) + minlines = 0; // Minimum number of lines (number) indentitems = 0; // Indent items to prompt width (0/1) } ); @@ -353,7 +354,7 @@ spmenu = { { click = "None"; button = "Scroll Down"; function = "movenext"; argument = "0"; }, // Scroll Down: Move to the next page { - scrolldistance = 512; // Distance to scroll for a scroll action to count. Wayland only (num) + scrolldistance = 512; // Distance to scroll for a scroll action to count. Wayland only (number) ignoreglobalmouse = 1; // Ignore hardcoded mouse binds (0/1) } ); diff --git a/libs/arg.c b/libs/arg.c index 35a5149..49a8956 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -567,7 +567,9 @@ void setlines(Arg *arg) { insert(NULL, 0 - sp.cursor); selecteditem = currentitem = matches; - lines += arg->i; + if (lines + arg->i >= minlines) { + lines += arg->i; + } if (lines < 0) { lines = 0; diff --git a/libs/argv.c b/libs/argv.c index f2fceba..5151cd1 100644 --- a/libs/argv.c +++ b/libs/argv.c @@ -321,8 +321,10 @@ void readargs(int argc, char *argv[]) { } else if (!strcmp(argv[i], "-l") || (!strcmp(argv[i], "--lines"))) { // number of lines in grid lines = atoi(argv[++i]); } else if (!strcmp(argv[i], "-mh") || (!strcmp(argv[i], "--lineheight")) || (!strcmp(argv[i], "--line-height"))) { // line height - lineheight += atoi(argv[++i]); + lineheight = atoi(argv[++i]); if (columns == 0) columns = 1; + } else if (!strcmp(argv[i], "-ml") || (!strcmp(argv[i], "--min-lines"))) { + minlines = atoi(argv[++i]); } else if (!strcmp(argv[i], "-cw") || (!strcmp(argv[i], "--center-width")) || (!strcmp(argv[i], "-mw") || (!strcmp(argv[i], "--min-width")))) { // center width centerwidth = atoi(argv[++i]); } else if (!strcmp(argv[i], "-txp") || (!strcmp(argv[i], "--text-padding"))) { // text padding @@ -612,10 +614,11 @@ void usage(int status) { fputs(VERSION, status ? stderr : stdout); fputs(": fancy dynamic menu\n\n" "- Arguments -\n" - "spmenu -l, --lines Set line count to stdin\n" "spmenu -mh, --line-height Set spmenu line height to \n" "spmenu -cw, --center-width Set width to when centered\n" + "spmenu -l, --lines Set line count to stdin\n" "spmenu -g, --columns Set the number of grids to \n" + "spmenu -ml, --min-lines Minimum number of lines allowed\n" "spmenu -gc, --generate-cache Generate image cache\n" "spmenu -ngc, --no-generate-cache Don't generate image cache\n" "spmenu -mc, --max-cache Set max image cache size to \n" diff --git a/libs/conf/config.c b/libs/conf/config.c index 65331f3..0b117ad 100644 --- a/libs/conf/config.c +++ b/libs/conf/config.c @@ -788,6 +788,7 @@ void conf_init(void) { config_setting_lookup_int(conf, "columns", &columns); // spmenu.line.columns config_setting_lookup_int(conf, "overridelines", &overridelines); // spmenu.line.overridelines config_setting_lookup_int(conf, "overridecolumns", &overridecolumns); // spmenu.line.overridecolumns + config_setting_lookup_int(conf, "minlines", &minlines); // spmenu.line.minlines config_setting_lookup_int(conf, "indentitems", &indentitems); // spmenu.line.indentitems } } diff --git a/libs/options.h b/libs/options.h index 93ba8b7..3b84b07 100644 --- a/libs/options.h +++ b/libs/options.h @@ -115,6 +115,7 @@ static int lines = 0; /* Default number of lines */ static int columns = 10; /* Default number of columns */ static int overridelines = 1; /* Allow overriding lines using keybinds */ static int overridecolumns = 1; /* Allow overriding columns using keybinds */ +static int minlines = 0; /* Minimum number of lines allowed */ /* History options */ static char *histfile = NULL; /* History file, NULL means no history file */ diff --git a/libs/stream.c b/libs/stream.c index 06544a3..7d44399 100644 --- a/libs/stream.c +++ b/libs/stream.c @@ -63,7 +63,7 @@ void readstdin(void) { #endif } - lines = MIN(lines, i); + lines = MAX(MIN(lines, i), minlines); } void readfile(void) { @@ -130,7 +130,7 @@ void readfile(void) { #endif } - lines = columns == 1 ? i : MIN(i, lines); // i = number of items + lines = MAX(columns == 1 ? i : MIN(i, lines), minlines); #if IMAGE if (!o) img.longestedge = img.imagegaps = 0; diff --git a/libs/wl/wayland.c b/libs/wl/wayland.c index b0558f2..43c781d 100644 --- a/libs/wl/wayland.c +++ b/libs/wl/wayland.c @@ -633,7 +633,7 @@ void resizeclient_wl(struct state *state) { for (item = items; item && item->text; item++) ic++; - lines = MIN(ic, MAX(lines, 0)); + lines = MAX(MIN(ic, MAX(lines, 0)), minlines); #if IMAGE img.setlines = lines; #endif diff --git a/libs/x11/client.c b/libs/x11/client.c index 3e2f95a..642f953 100644 --- a/libs/x11/client.c +++ b/libs/x11/client.c @@ -78,7 +78,7 @@ void resizeclient_x11(void) { for (item = items; item && item->text; item++) ic++; - lines = MIN(ic, MAX(lines, 0)); + lines = MAX(MIN(ic, MAX(lines, 0)), minlines); #if IMAGE img.setlines = lines; diff --git a/spmenu.1 b/spmenu.1 index 461c002..e119658 100644 --- a/spmenu.1 +++ b/spmenu.1 @@ -1,5 +1,5 @@ '\" t -.\" Automatically generated by Pandoc 3.1.3 +.\" Automatically generated by Pandoc 3.1.2 .\" .\" Define V font for inline verbatim, using C font in formats .\" that render this, and otherwise B font. @@ -70,9 +70,15 @@ Set spmenu line height to height \f[V]-cw, --center-width width\f[R] Set width to width when centered .TP +\f[V]-l, --lines lines\f[R] +Set the number of lines to lines +.TP \f[V]-g, --columns grid\f[R] Set the number of grids to grid .TP +\f[V]-ml, --min-lines\f[R] +Set minimum number of lines allowed to lines +.TP \f[V]-gc, --generate-cache\f[R] Generate image cache .TP diff --git a/spmenu_run.1 b/spmenu_run.1 index 9d73336..a1b3d95 100644 --- a/spmenu_run.1 +++ b/spmenu_run.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pandoc 3.1.3 +.\" Automatically generated by Pandoc 3.1.2 .\" .\" Define V font for inline verbatim, using C font in formats .\" that render this, and otherwise B font. diff --git a/spmenu_test.1 b/spmenu_test.1 index 8a2727f..13dd8a6 100644 --- a/spmenu_test.1 +++ b/spmenu_test.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pandoc 3.1.3 +.\" Automatically generated by Pandoc 3.1.2 .\" .\" Define V font for inline verbatim, using C font in formats .\" that render this, and otherwise B font.