diff options
| author | ozpv <39195175+ozpv@users.noreply.github.com> | 2024-05-28 04:43:42 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-28 04:43:42 +0000 |
| commit | d22280f3dc99dd71b5c86c1a6ce584bdee7cd8eb (patch) | |
| tree | 19736d99c8379499fc9a0e8c5e913fa3362a5951 /dmenu.c | |
| parent | 29255fd85845d66ce625b050ae9ab2751e382b73 (diff) | |
update to dmenu 5.3
Diffstat (limited to 'dmenu.c')
| -rw-r--r-- | dmenu.c | 35 |
1 files changed, 21 insertions, 14 deletions
@@ -22,7 +22,6 @@ /* macros */ #define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \ * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) -#define LENGTH(X) (sizeof X / sizeof X[0]) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) /* enums */ @@ -164,7 +163,7 @@ drawmenu(void) if (prompt && *prompt) { drw_setscheme(drw, scheme[SchemeSel]); - x = drw_text(drw, x, 0, !draw_input ? mw : promptw, bh, lrpad / 2, prompt, 0); + x = drw_text(drw, x, 0, !draw_input ? mw : promptw, bh, lrpad / 2, prompt, 0); } if (draw_input) { @@ -335,19 +334,19 @@ movewordedge(int dir) static void keypress(XKeyEvent *ev) { - char buf[32]; + char buf[64]; int len; - KeySym ksym; + KeySym ksym = NoSymbol; Status status; len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status); switch (status) { default: /* XLookupNone, XBufferOverflow */ return; - case XLookupChars: + case XLookupChars: /* composed string from input method */ goto insert; case XLookupKeySym: - case XLookupBoth: + case XLookupBoth: /* a KeySym and a string are returned: use keysym */ break; } @@ -564,19 +563,24 @@ static void readstdin(void) { char *line = NULL; - size_t i, junk, size = 0; + size_t i, itemsiz = 0, linesiz = 0; ssize_t len; /* read each line from stdin and add it to the item list */ - for (i = 0; (len = getline(&line, &junk, stdin)) != -1; i++, line = NULL) { - if (i + 1 >= size / sizeof *items) - if (!(items = realloc(items, (size += BUFSIZ)))) - die("cannot realloc %zu bytes:", size); + for (i = 0; (len = getline(&line, &linesiz, stdin)) != -1; i++) { + if (i + 1 >= itemsiz) { + itemsiz += 256; + if (!(items = realloc(items, itemsiz * sizeof(*items)))) + die("cannot realloc %zu bytes:", itemsiz * sizeof(*items)); + } if (line[len - 1] == '\n') line[len - 1] = '\0'; - items[i].text = line; + if (!(items[i].text = strdup(line))) + die("strdup:"); + items[i].out = 0; } + free(line); if (items) items[i].text = NULL; lines = MIN(lines, i); @@ -709,7 +713,7 @@ setup(void) swa.override_redirect = True; swa.background_pixel = scheme[SchemeNorm][ColBg].pixel; swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; - win = XCreateWindow(dpy, parentwin, x, y, mw, mh, border_width, + win = XCreateWindow(dpy, root, x, y, mw, mh, border_width, CopyFromParent, CopyFromParent, CopyFromParent, CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); if (border_width) @@ -726,6 +730,7 @@ setup(void) XMapRaised(dpy, win); if (embed) { + XReparentWindow(dpy, win, parentwin, x, y); XSelectInput(dpy, parentwin, FocusChangeMask | SubstructureNotifyMask); if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) { for (i = 0; i < du && dws[i] != win; ++i) @@ -760,8 +765,10 @@ main(int argc, char *argv[]) topbar = 0; else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ fast = 1; - else if (!strcmp(argv[i], "-noi")) /* no input field. intended to be used with a prompt */ + else if (!strcmp(argv[i], "-noi")) /* no input field. intended to be used with a prompt */ draw_input = 0; + else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */ + centered = 1; else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ fstrncmp = strncasecmp; fstrstr = cistrstr; |
