fix height arg

This commit is contained in:
speedie 2023-03-16 14:56:41 +01:00
parent 98b0ae0651
commit 7462aba7fc
4 changed files with 44 additions and 37 deletions

View file

@ -29,7 +29,7 @@ See a list below for a list.
## Arguments ## Arguments
- spmenu -l line - Set line count to stdin - spmenu -l line - Set line count to stdin
- spmenu -h height - Set spmenu line height to height - spmenu -mh height - Set spmenu line height to height
- spmenu -g grid - Set the number of grids to grid - spmenu -g grid - Set the number of grids to grid
- spmenu -gc - Generate image cache - spmenu -gc - Generate image cache
- spmenu -ngc - Don't generate image cache - spmenu -ngc - Don't generate image cache

View file

@ -152,16 +152,16 @@ readargs(int argc, char *argv[])
else if (pr) else if (pr)
fprintf(stderr, "spmenu: Invalid argument: '%s'\n", argv[i]); fprintf(stderr, "spmenu: Invalid argument: '%s'\n", argv[i]);
/* these options take one argument */ // these options take one argument
} else if (!strcmp(argv[i], "-g")) { /* number of columns in grid */ } else if (!strcmp(argv[i], "-g")) { // number of columns in grid
columns = atoi(argv[++i]); columns = atoi(argv[++i]);
if (lines == 0) lines = 1; if (lines == 0) lines = 1;
} else if (!strcmp(argv[i], "-Ps")) { /* password symbol */ } else if (!strcmp(argv[i], "-Ps")) { // password symbol
password = argv[++i]; password = argv[++i];
} else if (!strcmp(argv[i], "-l")) { /* number of lines in grid */ } else if (!strcmp(argv[i], "-l")) { // number of lines in grid
lines = atoi(argv[++i]); lines = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-h")) { /* minimum height of one menu line */ } else if (!strcmp(argv[i], "-mh")) { // minimum height of one menu line
clineheight += atoi(argv[++i]); lineheight += atoi(argv[++i]);
if (columns == 0) columns = 1; if (columns == 0) columns = 1;
} else if (!strcmp(argv[i], "-lp")) { } else if (!strcmp(argv[i], "-lp")) {
menupaddingv = atoi(argv[++i]); menupaddingv = atoi(argv[++i]);
@ -315,7 +315,7 @@ usage(void)
fputs("spmenu: dynamic menu\n\n" fputs("spmenu: dynamic menu\n\n"
"- Arguments -\n" "- Arguments -\n"
"spmenu -l <line> Set line count to stdin\n" "spmenu -l <line> Set line count to stdin\n"
"spmenu -h <height> Set spmenu line height to <height>\n" "spmenu -mh <height> Set spmenu line height to <height>\n"
"spmenu -g <grid> Set the number of grids to <grid>\n" "spmenu -g <grid> Set the number of grids to <grid>\n"
"spmenu -gc Generate image cache\n" "spmenu -gc Generate image cache\n"
"spmenu -ngc Don't generate image cache\n" "spmenu -ngc Don't generate image cache\n"

View file

@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 3.1 .\" Automatically generated by Pandoc 3.0.1
.\" .\"
.\" Define V font for inline verbatim, using C font in formats .\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font. .\" that render this, and otherwise B font.
@ -50,7 +50,7 @@ See a list below for a list.
.IP \[bu] 2 .IP \[bu] 2
spmenu -l line - Set line count to stdin spmenu -l line - Set line count to stdin
.IP \[bu] 2 .IP \[bu] 2
spmenu -h height - Set spmenu line height to height spmenu -mh height - Set spmenu line height to height
.IP \[bu] 2 .IP \[bu] 2
spmenu -g grid - Set the number of grids to grid spmenu -g grid - Set the number of grids to grid
.IP \[bu] 2 .IP \[bu] 2

View file

@ -118,7 +118,6 @@ static int numlockmask = 0;
static int bh, mw, mh; static int bh, mw, mh;
static int reallines = 0; static int reallines = 0;
static int reqlineheight; /* required menu height */ static int reqlineheight; /* required menu height */
static int clineheight; /* menu height added through argument */
static int dmx = 0; /* put spmenu at this x offset */ static int dmx = 0; /* put spmenu at this x offset */
static int dmy = 0; /* put spmenu at this y offset (measured from the bottom if menuposition is 0) */ static int dmy = 0; /* put spmenu at this y offset (measured from the bottom if menuposition is 0) */
static unsigned int dmw = 0; /* make spmenu this wide */ static unsigned int dmw = 0; /* make spmenu this wide */
@ -155,9 +154,7 @@ static int imageh = 0;
static int imageg = 0; static int imageg = 0;
#endif #endif
/* set an integer if to 1 if we have right to left language support enabled // set an integer to 1 if we have rtl enabled, this saves a lot of lines and duplicate code
* doing it this way, because we can reduce the amount of #if and #else lines used.
*/
#if USERTL #if USERTL
static int isrtl = 1; static int isrtl = 1;
#else #else
@ -180,10 +177,10 @@ static Drw *drw;
static Clr *scheme[SchemeLast]; static Clr *scheme[SchemeLast];
static Clr textclrs[256]; static Clr textclrs[256];
// history
static char *histfile; static char *histfile;
static char **history; static char **history;
static size_t histsz, histpos; static size_t histsz, histpos;
static size_t nextrune(int inc);
// draw functions // draw functions
static void drawmenu(void); static void drawmenu(void);
@ -201,16 +198,19 @@ static void grabfocus(void);
static void pastesel(void); static void pastesel(void);
static void appenditem(struct item *item, struct item **list, struct item **last); static void appenditem(struct item *item, struct item **list, struct item **last);
static int max_textw(void); static int max_textw(void);
static size_t nextrune(int inc);
/* user configuration */ // user configuration
#include "options.h" /* Include main header */ #include "options.h"
#include "keybinds.h" /* Include keybinds */ #include "keybinds.h"
// xresources/color arrays
#include "libs/xresources.h" #include "libs/xresources.h"
#include "libs/colors.h" #include "libs/colors.h"
static char *fonts[] = { font }; static char *fonts[] = { font };
// matching
static char * cistrstr(const char *s, const char *sub); static char * cistrstr(const char *s, const char *sub);
static int (*fstrncmp)(const char *, const char *, size_t) = strncasecmp; static int (*fstrncmp)(const char *, const char *, size_t) = strncasecmp;
static char *(*fstrstr)(const char *, const char *) = cistrstr; static char *(*fstrstr)(const char *, const char *) = cistrstr;
@ -375,7 +375,7 @@ insert(const char *str, ssize_t n)
{ {
if (strlen(text) + n > sizeof text - 1) if (strlen(text) + n > sizeof text - 1)
return; return;
/* move existing text out of the way, insert new text, and update cursor */ // move existing text out of the way, insert new text, and update cursor
memmove(&text[cursor + n], &text[cursor], sizeof text - cursor - MAX(n, 0)); memmove(&text[cursor + n], &text[cursor], sizeof text - cursor - MAX(n, 0));
if (n > 0) if (n > 0)
memcpy(&text[cursor], str, n); memcpy(&text[cursor], str, n);
@ -388,7 +388,7 @@ nextrune(int inc)
{ {
ssize_t n; ssize_t n;
/* return location of next utf8 rune in the given direction (+1 or -1) */ // return location of next utf8 rune in the given direction (+1 or -1)
for (n = cursor + inc; n + inc >= 0 && (text[n] & 0xc0) == 0x80; n += inc) for (n = cursor + inc; n + inc >= 0 && (text[n] & 0xc0) == 0x80; n += inc)
; ;
return n; return n;
@ -397,12 +397,12 @@ nextrune(int inc)
void void
movewordedge(int dir) movewordedge(int dir)
{ {
if (dir < 0) { /* move cursor to the start of the word*/ if (dir < 0) { // move cursor to the start of the word
while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)]))
cursor = nextrune(-1); cursor = nextrune(-1);
while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)])) while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
cursor = nextrune(-1); cursor = nextrune(-1);
} else { /* move cursor to the end of the word */ } else { // move cursor to the end of the word
while (text[cursor] && strchr(worddelimiters, text[cursor])) while (text[cursor] && strchr(worddelimiters, text[cursor]))
cursor = nextrune(+1); cursor = nextrune(+1);
while (text[cursor] && !strchr(worddelimiters, text[cursor])) while (text[cursor] && !strchr(worddelimiters, text[cursor]))
@ -505,7 +505,7 @@ pastesel(void)
unsigned long dl; unsigned long dl;
Atom da; Atom da;
/* we have been given the current selection, now insert it into input */ // we have been given the current selection, now insert it into input
if (XGetWindowProperty(dpy, win, utf8, 0, (sizeof text / 4) + 1, False, if (XGetWindowProperty(dpy, win, utf8, 0, (sizeof text / 4) + 1, False,
utf8, &da, &di, &dl, &dl, (unsigned char **)&p) utf8, &da, &di, &dl, &dl, (unsigned char **)&p)
== Success && p) { == Success && p) {
@ -523,11 +523,13 @@ xinitvisual()
int nitems; int nitems;
int i; int i;
// properties
XVisualInfo tpl = { XVisualInfo tpl = {
.screen = screen, .screen = screen,
.depth = 32, .depth = 32,
.class = TrueColor .class = TrueColor
}; };
long masks = VisualScreenMask | VisualDepthMask | VisualClassMask; long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
infos = XGetVisualInfo(dpy, masks, &tpl, &nitems); infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
@ -545,6 +547,7 @@ xinitvisual()
XFree(infos); XFree(infos);
// no alpha, reset to default
if (!visual || !alpha) { if (!visual || !alpha) {
visual = DefaultVisual(dpy, screen); visual = DefaultVisual(dpy, screen);
depth = DefaultDepth(dpy, screen); depth = DefaultDepth(dpy, screen);
@ -568,7 +571,7 @@ readstdin(void)
return; return;
} }
/* read each line from stdin and add it to the item list */ // read each line from stdin and add it to the item list
for (i = 0; fgets(buf, sizeof buf, stdin); i++) { for (i = 0; fgets(buf, sizeof buf, stdin); i++) {
if (i + 1 >= itemsiz) { if (i + 1 >= itemsiz) {
itemsiz += 256; itemsiz += 256;
@ -586,7 +589,7 @@ readstdin(void)
imax = i; imax = i;
} }
/* parse image markup */ // parse image markup
#if USEIMAGE #if USEIMAGE
if(!strncmp("IMG:", items[i].text, strlen("IMG:"))) { if(!strncmp("IMG:", items[i].text, strlen("IMG:"))) {
if(!(items[i].image = malloc(strlen(items[i].text)+1))) if(!(items[i].image = malloc(strlen(items[i].text)+1)))
@ -601,16 +604,18 @@ readstdin(void)
items[i].image = NULL; items[i].image = NULL;
} }
// load image cache (or generate)
if (generatecache && longestedge <= 256 && items[i].image && strcmp(items[i].image, limg ? limg : "")) { if (generatecache && longestedge <= 256 && items[i].image && strcmp(items[i].image, limg ? limg : "")) {
loadimagecache(items[i].image, &w, &h); loadimagecache(items[i].image, &w, &h);
fprintf(stdout, "spmenu: generating thumbnail for: %s\n", items[i].image); fprintf(stdout, "spmenu: generating thumbnail for: %s\n", items[i].image);
} }
if(items[i].image) if(items[i].image) {
limg = items[i].image; limg = items[i].image;
}
#endif #endif
/* todo: use this for something /* TODO: use this for something
* current usage is not very useful, however it's here to be used later. * current usage is not very useful, however it's here to be used later.
*/ */
if(!(items[i].ex = malloc(strlen(items[i].text)+1))) if(!(items[i].ex = malloc(strlen(items[i].text)+1)))
@ -620,16 +625,24 @@ readstdin(void)
items[i].text += strlen("spmenu:")+strlen(items[i].ex)+1; items[i].text += strlen("spmenu:")+strlen(items[i].ex)+1;
} }
// spmenu:version
if (!strncmp("version", items[i].ex, strlen("version"))) { if (!strncmp("version", items[i].ex, strlen("version"))) {
die("spmenu version %s", VERSION); die("spmenu version %s", VERSION);
} }
// spmenu:license
if (!strncmp("license", items[i].ex, strlen("license"))) { if (!strncmp("license", items[i].ex, strlen("license"))) {
die("spmenu is licensed under the MIT license. See the included LICENSE file for more information."); die("spmenu is licensed under the MIT license. See the included LICENSE file for more information.");
} }
// spmenu:test
if (!strncmp("test", items[i].ex, strlen("test"))) {
system("command -v spmenu_test > /dev/null && spmenu_test");
}
} }
} }
// clean
if (items) { if (items) {
#if USEIMAGE #if USEIMAGE
items[i].image = NULL; items[i].image = NULL;
@ -664,22 +677,16 @@ setup(void)
int a, n, area = 0; int a, n, area = 0;
#endif #endif
/* init appearance */ init_appearance(); // init colorschemes by reading arrays
init_appearance();
// properties
clip = XInternAtom(dpy, "CLIPBOARD", False); clip = XInternAtom(dpy, "CLIPBOARD", False);
utf8 = XInternAtom(dpy, "UTF8_STRING", False); utf8 = XInternAtom(dpy, "UTF8_STRING", False);
types = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); types = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
dock = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False); dock = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
if (!clineheight) {
reqlineheight += lineheight;
} else {
reqlineheight = clineheight;
}
// resize client // resize client
bh = drw->font->h + 2 + reqlineheight; bh = MAX(drw->font->h, drw->font->h + 2 + lineheight);
lines = MAX(lines, 0); lines = MAX(lines, 0);
reallines = lines; reallines = lines;