patched new version
This commit is contained in:
parent
5739e02095
commit
98f50190bd
19 changed files with 478 additions and 608 deletions
55
.gitignore
vendored
55
.gitignore
vendored
|
@ -1,56 +1,3 @@
|
|||
config.h
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
dmenu
|
||||
stest
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
*.o
|
||||
|
|
10
Makefile
10
Makefile
|
@ -6,13 +6,7 @@ include config.mk
|
|||
SRC = drw.c dmenu.c stest.c util.c
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
all: options dmenu stest
|
||||
|
||||
options:
|
||||
@echo dmenu build options:
|
||||
@echo "CFLAGS = $(CFLAGS)"
|
||||
@echo "LDFLAGS = $(LDFLAGS)"
|
||||
@echo "CC = $(CC)"
|
||||
all: dmenu stest
|
||||
|
||||
.c.o:
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
@ -61,4 +55,4 @@ uninstall:
|
|||
$(DESTDIR)$(MANPREFIX)/man1/dmenu.1\
|
||||
$(DESTDIR)$(MANPREFIX)/man1/stest.1
|
||||
|
||||
.PHONY: all options clean dist install uninstall
|
||||
.PHONY: all clean dist install uninstall
|
||||
|
|
24
README
Normal file
24
README
Normal file
|
@ -0,0 +1,24 @@
|
|||
dmenu - dynamic menu
|
||||
====================
|
||||
dmenu is an efficient dynamic menu for X.
|
||||
|
||||
|
||||
Requirements
|
||||
------------
|
||||
In order to build dmenu you need the Xlib header files.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
Edit config.mk to match your local setup (dmenu is installed into
|
||||
the /usr/local namespace by default).
|
||||
|
||||
Afterwards enter the following command to build and install dmenu
|
||||
(if necessary as root):
|
||||
|
||||
make clean install
|
||||
|
||||
|
||||
Running dmenu
|
||||
-------------
|
||||
See the man page for details.
|
21
README.md
21
README.md
|
@ -1,21 +0,0 @@
|
|||
# My personal dmenu build
|
||||
|
||||
## Description
|
||||
My personal repository for a custom dmenu build currently using the Gruvbox theme.
|
||||
|
||||
## Patches applied to suckless' software
|
||||
Applied via \*.diff files found in suckless.org, in the appearing order.
|
||||
Unsuccessful patches generated a \*.rej file which was moved to the corresponding "patches/manpatch/" directory for each program, and renamed \*.manpatch. This was then used to manually patch the source code.
|
||||
|
||||
### dmenu
|
||||
- border
|
||||
- center
|
||||
- fuzzymatch
|
||||
|
||||
## Dependencies (Archlinux names)
|
||||
adobe-source-code-pro-fonts,
|
||||
make,
|
||||
libxcb
|
||||
libX11-devel,
|
||||
libXft-devel,
|
||||
libXinerama-devel,
|
22
config.def.h
22
config.def.h
|
@ -1,23 +1,23 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
/* Default settings; can be overriden by command line. */
|
||||
|
||||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||
static int fuzzy = 1; /* -F option; if 0, dmenu doesn't use fuzzy matching */
|
||||
static int centered = 1; /* -c option; centers dmenu on screen */
|
||||
static int min_width = 400; /* minimum width when centered */
|
||||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||
static int fuzzy = 1; /* -F option; if 0, dmenu doesn't use fuzzy matching */
|
||||
static int centered = 0; /* -c option; centers dmenu on screen */
|
||||
static int min_width = 500; /* minimum width when centered */
|
||||
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||
static const char *fonts[] = {
|
||||
"JetBrainsMono:size=10"
|
||||
"monospace:size=10"
|
||||
};
|
||||
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
|
||||
static const char *colors[SchemeLast][2] = {
|
||||
/* fg bg */
|
||||
[SchemeNorm] = { "#606060", "#1d2021" },
|
||||
[SchemeSel] = { "#1d2021", "#fabd2f" },
|
||||
[SchemeOut] = { "#000000", "#00ffff" },
|
||||
/* fg bg */
|
||||
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||
[SchemeSel] = { "#eeeeee", "#005577" },
|
||||
[SchemeOut] = { "#000000", "#00ffff" },
|
||||
};
|
||||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||
static unsigned int lines = 10;
|
||||
static unsigned int lines = 0;
|
||||
|
||||
/*
|
||||
* Characters not considered part of a word while deleting words
|
||||
|
@ -26,4 +26,4 @@ static unsigned int lines = 10;
|
|||
static const char worddelimiters[] = " ";
|
||||
|
||||
/* Size of the window border */
|
||||
static unsigned int border_width = 2;
|
||||
static unsigned int border_width = 0;
|
||||
|
|
29
config.h
Normal file
29
config.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
/* Default settings; can be overriden by command line. */
|
||||
|
||||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||
static int fuzzy = 1; /* -F option; if 0, dmenu doesn't use fuzzy matching */
|
||||
static int centered = 1; /* -c option; centers dmenu on screen */
|
||||
static int min_width = 400; /* minimum width when centered */
|
||||
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||
static const char *fonts[] = {
|
||||
"JetBrainsMono:size=10"
|
||||
};
|
||||
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
|
||||
static const char *colors[SchemeLast][2] = {
|
||||
/* fg bg */
|
||||
[SchemeNorm] = { "#606060", "#1d2021" },
|
||||
[SchemeSel] = { "#1d2021", "#fabd2f" },
|
||||
[SchemeOut] = { "#000000", "#00ffff" },
|
||||
};
|
||||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||
static unsigned int lines = 10;
|
||||
|
||||
/*
|
||||
* Characters not considered part of a word while deleting words
|
||||
* for example: " /?\"&[]"
|
||||
*/
|
||||
static const char worddelimiters[] = " ";
|
||||
|
||||
/* Size of the window border */
|
||||
static unsigned int border_width = 2;
|
|
@ -1,5 +1,5 @@
|
|||
# dmenu version
|
||||
VERSION = 5.2
|
||||
VERSION = 5.3
|
||||
|
||||
# paths
|
||||
PREFIX = /usr/local
|
||||
|
|
370
dmenu-5.3-tavo.diff
Normal file
370
dmenu-5.3-tavo.diff
Normal file
|
@ -0,0 +1,370 @@
|
|||
Applied patches (in listed order):
|
||||
dmenu-border-20230512-0fe460d.diff
|
||||
dmenu-center-5.2.diff
|
||||
dmenu-fuzzymatch-4.9.diff
|
||||
dmenu-password-5.0.diff
|
||||
---
|
||||
diff -Nu a/config.def.h b/config.def.h
|
||||
--- a/config.def.h 2024-03-19 05:25:09.000000000 -0600
|
||||
+++ b/config.def.h 2024-04-27 10:52:25.869380160 -0600
|
||||
@@ -2,6 +2,9 @@
|
||||
/* Default settings; can be overriden by command line. */
|
||||
|
||||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||
+static int fuzzy = 1; /* -F option; if 0, dmenu doesn't use fuzzy matching */
|
||||
+static int centered = 0; /* -c option; centers dmenu on screen */
|
||||
+static int min_width = 500; /* minimum width when centered */
|
||||
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||
static const char *fonts[] = {
|
||||
"monospace:size=10"
|
||||
@@ -21,3 +24,6 @@
|
||||
* for example: " /?\"&[]"
|
||||
*/
|
||||
static const char worddelimiters[] = " ";
|
||||
+
|
||||
+/* Size of the window border */
|
||||
+static unsigned int border_width = 0;
|
||||
diff -Nu a/config.h b/config.h
|
||||
--- a/config.h 1969-12-31 18:00:00.000000000 -0600
|
||||
+++ b/config.h 2024-04-27 11:04:13.872392598 -0600
|
||||
@@ -0,0 +1,29 @@
|
||||
+/* See LICENSE file for copyright and license details. */
|
||||
+/* Default settings; can be overriden by command line. */
|
||||
+
|
||||
+static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||
+static int fuzzy = 1; /* -F option; if 0, dmenu doesn't use fuzzy matching */
|
||||
+static int centered = 1; /* -c option; centers dmenu on screen */
|
||||
+static int min_width = 400; /* minimum width when centered */
|
||||
+/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||
+static const char *fonts[] = {
|
||||
+ "JetBrainsMono:size=10"
|
||||
+};
|
||||
+static const char *prompt = NULL; /* -p option; prompt to the left of input field */
|
||||
+static const char *colors[SchemeLast][2] = {
|
||||
+ /* fg bg */
|
||||
+ [SchemeNorm] = { "#606060", "#1d2021" },
|
||||
+ [SchemeSel] = { "#1d2021", "#fabd2f" },
|
||||
+ [SchemeOut] = { "#000000", "#00ffff" },
|
||||
+};
|
||||
+/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||
+static unsigned int lines = 10;
|
||||
+
|
||||
+/*
|
||||
+ * Characters not considered part of a word while deleting words
|
||||
+ * for example: " /?\"&[]"
|
||||
+ */
|
||||
+static const char worddelimiters[] = " ";
|
||||
+
|
||||
+/* Size of the window border */
|
||||
+static unsigned int border_width = 2;
|
||||
diff -Nu a/config.mk b/config.mk
|
||||
--- a/config.mk 2024-03-19 05:25:09.000000000 -0600
|
||||
+++ b/config.mk 2024-04-27 10:50:17.596133866 -0600
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
# includes and libs
|
||||
INCS = -I$(X11INC) -I$(FREETYPEINC)
|
||||
-LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS)
|
||||
+LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) -lm
|
||||
|
||||
# flags
|
||||
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
|
||||
diff -Nu a/dmenu.1 b/dmenu.1
|
||||
--- a/dmenu.1 2024-03-19 05:25:09.000000000 -0600
|
||||
+++ b/dmenu.1 2024-04-27 10:59:12.237385772 -0600
|
||||
@@ -3,7 +3,7 @@
|
||||
dmenu \- dynamic menu
|
||||
.SH SYNOPSIS
|
||||
.B dmenu
|
||||
-.RB [ \-bfiv ]
|
||||
+.RB [ \-bfivP ]
|
||||
.RB [ \-l
|
||||
.IR lines ]
|
||||
.RB [ \-m
|
||||
@@ -40,6 +40,9 @@
|
||||
.B \-b
|
||||
dmenu appears at the bottom of the screen.
|
||||
.TP
|
||||
+.B \-c
|
||||
+dmenu appears centered on the screen.
|
||||
+.TP
|
||||
.B \-f
|
||||
dmenu grabs the keyboard before reading stdin if not reading from a tty. This
|
||||
is faster, but will lock up X until stdin reaches end\-of\-file.
|
||||
@@ -47,6 +50,9 @@
|
||||
.B \-i
|
||||
dmenu matches menu items case insensitively.
|
||||
.TP
|
||||
+.B \-P
|
||||
+dmenu will not directly display the keyboard input, but instead replace it with asterisks. All data from stdin will be ignored.
|
||||
+.TP
|
||||
.BI \-l " lines"
|
||||
dmenu lists items vertically, with the given number of lines.
|
||||
.TP
|
||||
diff -Nu a/dmenu.c b/dmenu.c
|
||||
--- a/dmenu.c 2024-03-19 05:25:09.000000000 -0600
|
||||
+++ b/dmenu.c 2024-04-27 10:58:14.208809907 -0600
|
||||
@@ -1,6 +1,7 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
+#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -31,12 +32,13 @@
|
||||
char *text;
|
||||
struct item *left, *right;
|
||||
int out;
|
||||
+ double distance;
|
||||
};
|
||||
|
||||
static char text[BUFSIZ] = "";
|
||||
static char *embed;
|
||||
static int bh, mw, mh;
|
||||
-static int inputw = 0, promptw;
|
||||
+static int inputw = 0, promptw, passwd = 0;
|
||||
static int lrpad; /* sum of left and right padding */
|
||||
static size_t cursor;
|
||||
static struct item *items = NULL;
|
||||
@@ -95,6 +97,15 @@
|
||||
break;
|
||||
}
|
||||
|
||||
+static int
|
||||
+max_textw(void)
|
||||
+{
|
||||
+ int len = 0;
|
||||
+ for (struct item *item = items; item && item->text; item++)
|
||||
+ len = MAX(TEXTW(item->text), len);
|
||||
+ return len;
|
||||
+}
|
||||
+
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
@@ -148,6 +159,7 @@
|
||||
unsigned int curpos;
|
||||
struct item *item;
|
||||
int x = 0, y = 0, w;
|
||||
+ char *censort;
|
||||
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
||||
@@ -159,7 +171,12 @@
|
||||
/* draw input field */
|
||||
w = (lines > 0 || !matches) ? mw - x : inputw;
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
- drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
|
||||
+ if (passwd) {
|
||||
+ censort = ecalloc(1, sizeof(text));
|
||||
+ memset(censort, '*', strlen(text));
|
||||
+ drw_text(drw, x, 0, w, bh, lrpad / 2, censort, 0);
|
||||
+ free(censort);
|
||||
+ } else drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
|
||||
|
||||
curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
||||
if ((curpos += lrpad / 2 - 1) < w) {
|
||||
@@ -226,9 +243,94 @@
|
||||
die("cannot grab keyboard");
|
||||
}
|
||||
|
||||
+int
|
||||
+compare_distance(const void *a, const void *b)
|
||||
+{
|
||||
+ struct item *da = *(struct item **) a;
|
||||
+ struct item *db = *(struct item **) b;
|
||||
+
|
||||
+ if (!db)
|
||||
+ return 1;
|
||||
+ if (!da)
|
||||
+ return -1;
|
||||
+
|
||||
+ return da->distance == db->distance ? 0 : da->distance < db->distance ? -1 : 1;
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+fuzzymatch(void)
|
||||
+{
|
||||
+ /* bang - we have so much memory */
|
||||
+ struct item *it;
|
||||
+ struct item **fuzzymatches = NULL;
|
||||
+ char c;
|
||||
+ int number_of_matches = 0, i, pidx, sidx, eidx;
|
||||
+ int text_len = strlen(text), itext_len;
|
||||
+
|
||||
+ matches = matchend = NULL;
|
||||
+
|
||||
+ /* walk through all items */
|
||||
+ for (it = items; it && it->text; it++) {
|
||||
+ if (text_len) {
|
||||
+ itext_len = strlen(it->text);
|
||||
+ pidx = 0; /* pointer */
|
||||
+ sidx = eidx = -1; /* start of match, end of match */
|
||||
+ /* walk through item text */
|
||||
+ for (i = 0; i < itext_len && (c = it->text[i]); i++) {
|
||||
+ /* fuzzy match pattern */
|
||||
+ if (!fstrncmp(&text[pidx], &c, 1)) {
|
||||
+ if(sidx == -1)
|
||||
+ sidx = i;
|
||||
+ pidx++;
|
||||
+ if (pidx == text_len) {
|
||||
+ eidx = i;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ /* build list of matches */
|
||||
+ if (eidx != -1) {
|
||||
+ /* compute distance */
|
||||
+ /* add penalty if match starts late (log(sidx+2))
|
||||
+ * add penalty for long a match without many matching characters */
|
||||
+ it->distance = log(sidx + 2) + (double)(eidx - sidx - text_len);
|
||||
+ /* fprintf(stderr, "distance %s %f\n", it->text, it->distance); */
|
||||
+ appenditem(it, &matches, &matchend);
|
||||
+ number_of_matches++;
|
||||
+ }
|
||||
+ } else {
|
||||
+ appenditem(it, &matches, &matchend);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (number_of_matches) {
|
||||
+ /* initialize array with matches */
|
||||
+ if (!(fuzzymatches = realloc(fuzzymatches, number_of_matches * sizeof(struct item*))))
|
||||
+ die("cannot realloc %u bytes:", number_of_matches * sizeof(struct item*));
|
||||
+ for (i = 0, it = matches; it && i < number_of_matches; i++, it = it->right) {
|
||||
+ fuzzymatches[i] = it;
|
||||
+ }
|
||||
+ /* sort matches according to distance */
|
||||
+ qsort(fuzzymatches, number_of_matches, sizeof(struct item*), compare_distance);
|
||||
+ /* rebuild list of matches */
|
||||
+ matches = matchend = NULL;
|
||||
+ for (i = 0, it = fuzzymatches[i]; i < number_of_matches && it && \
|
||||
+ it->text; i++, it = fuzzymatches[i]) {
|
||||
+ appenditem(it, &matches, &matchend);
|
||||
+ }
|
||||
+ free(fuzzymatches);
|
||||
+ }
|
||||
+ curr = sel = matches;
|
||||
+ calcoffsets();
|
||||
+}
|
||||
+
|
||||
static void
|
||||
match(void)
|
||||
{
|
||||
+ if (fuzzy) {
|
||||
+ fuzzymatch();
|
||||
+ return;
|
||||
+ }
|
||||
static char **tokv = NULL;
|
||||
static int tokn = 0;
|
||||
|
||||
@@ -551,6 +653,10 @@
|
||||
char *line = NULL;
|
||||
size_t i, itemsiz = 0, linesiz = 0;
|
||||
ssize_t len;
|
||||
+ if(passwd){
|
||||
+ inputw = lines = 0;
|
||||
+ return;
|
||||
+ }
|
||||
|
||||
/* read each line from stdin and add it to the item list */
|
||||
for (i = 0; (len = getline(&line, &linesiz, stdin)) != -1; i++) {
|
||||
@@ -636,6 +742,7 @@
|
||||
bh = drw->fonts->h + 2;
|
||||
lines = MAX(lines, 0);
|
||||
mh = (lines + 1) * bh;
|
||||
+ promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
||||
#ifdef XINERAMA
|
||||
i = 0;
|
||||
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
|
||||
@@ -662,9 +769,16 @@
|
||||
if (INTERSECT(x, y, 1, 1, info[i]) != 0)
|
||||
break;
|
||||
|
||||
- x = info[i].x_org;
|
||||
- y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
|
||||
- mw = info[i].width;
|
||||
+ if (centered) {
|
||||
+ mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width);
|
||||
+ x = info[i].x_org + ((info[i].width - mw) / 2);
|
||||
+ y = info[i].y_org + ((info[i].height - mh) / 2);
|
||||
+ } else {
|
||||
+ x = info[i].x_org;
|
||||
+ y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
|
||||
+ mw = info[i].width;
|
||||
+ }
|
||||
+
|
||||
XFree(info);
|
||||
} else
|
||||
#endif
|
||||
@@ -672,9 +786,16 @@
|
||||
if (!XGetWindowAttributes(dpy, parentwin, &wa))
|
||||
die("could not get embedding window attributes: 0x%lx",
|
||||
parentwin);
|
||||
- x = 0;
|
||||
- y = topbar ? 0 : wa.height - mh;
|
||||
- mw = wa.width;
|
||||
+
|
||||
+ if (centered) {
|
||||
+ mw = MIN(MAX(max_textw() + promptw, min_width), wa.width);
|
||||
+ x = (wa.width - mw) / 2;
|
||||
+ y = (wa.height - mh) / 2;
|
||||
+ } else {
|
||||
+ x = 0;
|
||||
+ y = topbar ? 0 : wa.height - mh;
|
||||
+ mw = wa.width;
|
||||
+ }
|
||||
}
|
||||
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
||||
inputw = mw / 3; /* input width: ~33% of monitor width */
|
||||
@@ -684,9 +805,11 @@
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
|
||||
- win = XCreateWindow(dpy, root, x, y, mw, mh, 0,
|
||||
+ win = XCreateWindow(dpy, root, x, y, mw, mh, border_width,
|
||||
CopyFromParent, CopyFromParent, CopyFromParent,
|
||||
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
|
||||
+ if (border_width)
|
||||
+ XSetWindowBorder(dpy, win, scheme[SchemeSel][ColBg].pixel);
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
|
||||
|
||||
@@ -715,7 +838,7 @@
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
- die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
|
||||
+ die("usage: dmenu [-bfivP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
|
||||
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
|
||||
}
|
||||
|
||||
@@ -734,10 +857,16 @@
|
||||
topbar = 0;
|
||||
else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */
|
||||
fast = 1;
|
||||
+ else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */
|
||||
+ centered = 1;
|
||||
+ else if (!strcmp(argv[i], "-F")) /* grabs keyboard before reading stdin */
|
||||
+ fuzzy = 0;
|
||||
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
|
||||
fstrncmp = strncasecmp;
|
||||
fstrstr = cistrstr;
|
||||
- } else if (i + 1 == argc)
|
||||
+ } else if (!strcmp(argv[i], "-P")) /* is the input a password */
|
||||
+ passwd = 1;
|
||||
+ else if (i + 1 == argc)
|
||||
usage();
|
||||
/* these options take one argument */
|
||||
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
|
||||
@@ -758,6 +887,8 @@
|
||||
colors[SchemeSel][ColFg] = argv[++i];
|
||||
else if (!strcmp(argv[i], "-w")) /* embedding window id */
|
||||
embed = argv[++i];
|
||||
+ else if (!strcmp(argv[i], "-bw"))
|
||||
+ border_width = atoi(argv[++i]); /* border width */
|
||||
else
|
||||
usage();
|
||||
|
2
dmenu.1
2
dmenu.1
|
@ -51,7 +51,7 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
|
|||
dmenu matches menu items case insensitively.
|
||||
.TP
|
||||
.B \-P
|
||||
dmenu will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored.
|
||||
dmenu will not directly display the keyboard input, but instead replace it with asterisks. All data from stdin will be ignored.
|
||||
.TP
|
||||
.BI \-l " lines"
|
||||
dmenu lists items vertically, with the given number of lines.
|
||||
|
|
46
dmenu.c
46
dmenu.c
|
@ -23,7 +23,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 */
|
||||
|
@ -426,19 +425,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;
|
||||
}
|
||||
|
||||
|
@ -459,7 +458,6 @@ keypress(XKeyEvent *ev)
|
|||
case XK_M: ksym = XK_Return; ev->state &= ~ControlMask; break;
|
||||
case XK_n: ksym = XK_Down; break;
|
||||
case XK_p: ksym = XK_Up; break;
|
||||
case XK_Tab: ksym = XK_Up; break;
|
||||
|
||||
case XK_k: /* delete right */
|
||||
text[cursor] = '\0';
|
||||
|
@ -618,10 +616,12 @@ insert:
|
|||
}
|
||||
break;
|
||||
case XK_Tab:
|
||||
if (sel && sel->right && (sel = sel->right) == next) {
|
||||
curr = next;
|
||||
calcoffsets();
|
||||
}
|
||||
if (!sel)
|
||||
return;
|
||||
cursor = strnlen(sel->text, sizeof text - 1);
|
||||
memcpy(text, sel->text, cursor);
|
||||
text[cursor] = '\0';
|
||||
match();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -651,24 +651,28 @@ static void
|
|||
readstdin(void)
|
||||
{
|
||||
char *line = NULL;
|
||||
size_t i, junk, size = 0;
|
||||
size_t i, itemsiz = 0, linesiz = 0;
|
||||
ssize_t len;
|
||||
|
||||
if(passwd){
|
||||
inputw = lines = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
@ -793,6 +797,7 @@ setup(void)
|
|||
mw = wa.width;
|
||||
}
|
||||
}
|
||||
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
||||
inputw = mw / 3; /* input width: ~33% of monitor width */
|
||||
match();
|
||||
|
||||
|
@ -800,7 +805,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 - (topbar ? 0 : border_width * 2), mw - border_width * 2, mh, border_width,
|
||||
win = XCreateWindow(dpy, root, x, y, mw, mh, border_width,
|
||||
CopyFromParent, CopyFromParent, CopyFromParent,
|
||||
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
|
||||
if (border_width)
|
||||
|
@ -817,6 +822,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)
|
||||
|
@ -851,10 +857,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], "-F")) /* grabs keyboard before reading stdin */
|
||||
fuzzy = 0;
|
||||
else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */
|
||||
centered = 1;
|
||||
else if (!strcmp(argv[i], "-F")) /* grabs keyboard before reading stdin */
|
||||
fuzzy = 0;
|
||||
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
|
||||
fstrncmp = strncasecmp;
|
||||
fstrstr = cistrstr;
|
||||
|
|
23
drw.c
23
drw.c
|
@ -238,8 +238,8 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int
|
|||
int
|
||||
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert)
|
||||
{
|
||||
int i, ty, ellipsis_x = 0;
|
||||
unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len;
|
||||
int ty, ellipsis_x = 0;
|
||||
unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len, hash, h0, h1;
|
||||
XftDraw *d = NULL;
|
||||
Fnt *usedfont, *curfont, *nextfont;
|
||||
int utf8strlen, utf8charlen, render = x || y || w || h;
|
||||
|
@ -251,9 +251,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
|||
XftResult result;
|
||||
int charexists = 0, overflow = 0;
|
||||
/* keep track of a couple codepoints for which we have no match. */
|
||||
enum { nomatches_len = 64 };
|
||||
static struct { long codepoint[nomatches_len]; unsigned int idx; } nomatches;
|
||||
static unsigned int ellipsis_width = 0;
|
||||
static unsigned int nomatches[128], ellipsis_width;
|
||||
|
||||
if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts)
|
||||
return 0;
|
||||
|
@ -338,11 +336,14 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
|||
* character must be drawn. */
|
||||
charexists = 1;
|
||||
|
||||
for (i = 0; i < nomatches_len; ++i) {
|
||||
/* avoid calling XftFontMatch if we know we won't find a match */
|
||||
if (utf8codepoint == nomatches.codepoint[i])
|
||||
goto no_match;
|
||||
}
|
||||
hash = (unsigned int)utf8codepoint;
|
||||
hash = ((hash >> 16) ^ hash) * 0x21F0AAAD;
|
||||
hash = ((hash >> 15) ^ hash) * 0xD35A2D97;
|
||||
h0 = ((hash >> 15) ^ hash) % LENGTH(nomatches);
|
||||
h1 = (hash >> 17) % LENGTH(nomatches);
|
||||
/* avoid expensive XftFontMatch call when we know we won't find a match */
|
||||
if (nomatches[h0] == utf8codepoint || nomatches[h1] == utf8codepoint)
|
||||
goto no_match;
|
||||
|
||||
fccharset = FcCharSetCreate();
|
||||
FcCharSetAddChar(fccharset, utf8codepoint);
|
||||
|
@ -371,7 +372,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
|||
curfont->next = usedfont;
|
||||
} else {
|
||||
xfont_free(usedfont);
|
||||
nomatches.codepoint[++nomatches.idx % nomatches_len] = utf8codepoint;
|
||||
nomatches[nomatches[h0] ? h1 : h0] = utf8codepoint;
|
||||
no_match:
|
||||
usedfont = drw->fonts;
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
--- config.def.h
|
||||
+++ config.def.h
|
||||
@@ -2,6 +2,7 @@
|
||||
/* Default settings; can be overriden by command line. */
|
||||
|
||||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||
+static int fuzzy = 1; /* -F option; if 0, dmenu doesn't use fuzzy matching */
|
||||
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||
static const char *fonts[] = {
|
||||
"monospace:size=10"
|
|
@ -1,50 +0,0 @@
|
|||
From d0c3fc8a634c153856cd41438f705175a21ec69a Mon Sep 17 00:00:00 2001
|
||||
From: braskin <benjaminiraskin@gmail.com>
|
||||
Date: Thu, 12 Nov 2020 10:13:29 -0500
|
||||
Subject: [PATCH] fixed border width draw for topbar
|
||||
|
||||
---
|
||||
config.def.h | 3 +++
|
||||
dmenu.c | 6 +++++-
|
||||
2 files changed, 8 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index 1edb647..dd3eb31 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -21,3 +21,6 @@ static unsigned int lines = 0;
|
||||
* for example: " /?\"&[]"
|
||||
*/
|
||||
static const char worddelimiters[] = " ";
|
||||
+
|
||||
+/* Size of the window border */
|
||||
+static unsigned int border_width = 0;
|
||||
diff --git a/dmenu.c b/dmenu.c
|
||||
index 65f25ce..716e655 100644
|
||||
--- a/dmenu.c
|
||||
+++ b/dmenu.c
|
||||
@@ -659,9 +659,11 @@ 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, 0,
|
||||
+ win = XCreateWindow(dpy, parentwin, x, y - (topbar ? 0 : border_width * 2), mw - border_width * 2, mh, border_width,
|
||||
CopyFromParent, CopyFromParent, CopyFromParent,
|
||||
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
|
||||
+ if (border_width)
|
||||
+ XSetWindowBorder(dpy, win, scheme[SchemeSel][ColBg].pixel);
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
|
||||
|
||||
@@ -733,6 +735,8 @@ main(int argc, char *argv[])
|
||||
colors[SchemeSel][ColFg] = argv[++i];
|
||||
else if (!strcmp(argv[i], "-w")) /* embedding window id */
|
||||
embed = argv[++i];
|
||||
+ else if (!strcmp(argv[i], "-bw"))
|
||||
+ border_width = atoi(argv[++i]); /* border width */
|
||||
else
|
||||
usage();
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
From 8cd37e1ab9e7cb025224aeb3543f1a5be8bceb93 Mon Sep 17 00:00:00 2001
|
||||
From: Nihal Jere <nihal@nihaljere.xyz>
|
||||
Date: Sat, 11 Jan 2020 21:16:08 -0600
|
||||
Subject: [PATCH] center patch now has adjustable minimum width
|
||||
|
||||
---
|
||||
config.def.h | 2 ++
|
||||
dmenu.1 | 3 +++
|
||||
dmenu.c | 39 ++++++++++++++++++++++++++++++++-------
|
||||
3 files changed, 37 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index 1edb647..88ef264 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -2,6 +2,8 @@
|
||||
/* Default settings; can be overriden by command line. */
|
||||
|
||||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||
+static int centered = 0; /* -c option; centers dmenu on screen */
|
||||
+static int min_width = 500; /* minimum width when centered */
|
||||
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||
static const char *fonts[] = {
|
||||
"monospace:size=10"
|
||||
diff --git a/dmenu.1 b/dmenu.1
|
||||
index 323f93c..c036baa 100644
|
||||
--- a/dmenu.1
|
||||
+++ b/dmenu.1
|
||||
@@ -40,6 +40,9 @@ which lists programs in the user's $PATH and runs the result in their $SHELL.
|
||||
.B \-b
|
||||
dmenu appears at the bottom of the screen.
|
||||
.TP
|
||||
+.B \-c
|
||||
+dmenu appears centered on the screen.
|
||||
+.TP
|
||||
.B \-f
|
||||
dmenu grabs the keyboard before reading stdin if not reading from a tty. This
|
||||
is faster, but will lock up X until stdin reaches end\-of\-file.
|
||||
diff --git a/dmenu.c b/dmenu.c
|
||||
index 65f25ce..041c7f8 100644
|
||||
--- a/dmenu.c
|
||||
+++ b/dmenu.c
|
||||
@@ -89,6 +89,15 @@ calcoffsets(void)
|
||||
break;
|
||||
}
|
||||
|
||||
+static int
|
||||
+max_textw(void)
|
||||
+{
|
||||
+ int len = 0;
|
||||
+ for (struct item *item = items; item && item->text; item++)
|
||||
+ len = MAX(TEXTW(item->text), len);
|
||||
+ return len;
|
||||
+}
|
||||
+
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
@@ -611,6 +620,7 @@ setup(void)
|
||||
bh = drw->fonts->h + 2;
|
||||
lines = MAX(lines, 0);
|
||||
mh = (lines + 1) * bh;
|
||||
+ promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
||||
#ifdef XINERAMA
|
||||
i = 0;
|
||||
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
|
||||
@@ -637,9 +647,16 @@ setup(void)
|
||||
if (INTERSECT(x, y, 1, 1, info[i]))
|
||||
break;
|
||||
|
||||
- x = info[i].x_org;
|
||||
- y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
|
||||
- mw = info[i].width;
|
||||
+ if (centered) {
|
||||
+ mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width);
|
||||
+ x = info[i].x_org + ((info[i].width - mw) / 2);
|
||||
+ y = info[i].y_org + ((info[i].height - mh) / 2);
|
||||
+ } else {
|
||||
+ x = info[i].x_org;
|
||||
+ y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
|
||||
+ mw = info[i].width;
|
||||
+ }
|
||||
+
|
||||
XFree(info);
|
||||
} else
|
||||
#endif
|
||||
@@ -647,11 +664,17 @@ setup(void)
|
||||
if (!XGetWindowAttributes(dpy, parentwin, &wa))
|
||||
die("could not get embedding window attributes: 0x%lx",
|
||||
parentwin);
|
||||
- x = 0;
|
||||
- y = topbar ? 0 : wa.height - mh;
|
||||
- mw = wa.width;
|
||||
+
|
||||
+ if (centered) {
|
||||
+ mw = MIN(MAX(max_textw() + promptw, min_width), wa.width);
|
||||
+ x = (wa.width - mw) / 2;
|
||||
+ y = (wa.height - mh) / 2;
|
||||
+ } else {
|
||||
+ x = 0;
|
||||
+ y = topbar ? 0 : wa.height - mh;
|
||||
+ mw = wa.width;
|
||||
+ }
|
||||
}
|
||||
- promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
||||
inputw = MIN(inputw, mw/3);
|
||||
match();
|
||||
|
||||
@@ -709,6 +732,8 @@ 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], "-c")) /* centers dmenu on screen */
|
||||
+ centered = 1;
|
||||
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
|
||||
fstrncmp = strncasecmp;
|
||||
fstrstr = cistrstr;
|
||||
--
|
||||
2.24.1
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
From 94353eb52055927d9079f3d9e33da1c954abf386 Mon Sep 17 00:00:00 2001
|
||||
From: aleks <aleks.stier@icloud.com>
|
||||
Date: Wed, 26 Jun 2019 13:25:10 +0200
|
||||
Subject: [PATCH] Add support for fuzzy-matching
|
||||
|
||||
---
|
||||
config.def.h | 1 +
|
||||
config.mk | 2 +-
|
||||
dmenu.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
3 files changed, 91 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index 1edb647..51612b9 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -2,6 +2,7 @@
|
||||
/* Default settings; can be overriden by command line. */
|
||||
|
||||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||
+static int fuzzy = 1; /* -F option; if 0, dmenu doesn't use fuzzy matching */
|
||||
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||
static const char *fonts[] = {
|
||||
"monospace:size=10"
|
||||
diff --git a/config.mk b/config.mk
|
||||
index 0929b4a..d14309a 100644
|
||||
--- a/config.mk
|
||||
+++ b/config.mk
|
||||
@@ -20,7 +20,7 @@ FREETYPEINC = /usr/include/freetype2
|
||||
|
||||
# includes and libs
|
||||
INCS = -I$(X11INC) -I$(FREETYPEINC)
|
||||
-LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS)
|
||||
+LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) -lm
|
||||
|
||||
# flags
|
||||
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
|
||||
diff --git a/dmenu.c b/dmenu.c
|
||||
index 6b8f51b..96ddc98 100644
|
||||
--- a/dmenu.c
|
||||
+++ b/dmenu.c
|
||||
@@ -1,6 +1,7 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
+#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -32,6 +33,7 @@ struct item {
|
||||
char *text;
|
||||
struct item *left, *right;
|
||||
int out;
|
||||
+ double distance;
|
||||
};
|
||||
|
||||
static char text[BUFSIZ] = "";
|
||||
@@ -210,9 +212,94 @@ grabkeyboard(void)
|
||||
die("cannot grab keyboard");
|
||||
}
|
||||
|
||||
+int
|
||||
+compare_distance(const void *a, const void *b)
|
||||
+{
|
||||
+ struct item *da = *(struct item **) a;
|
||||
+ struct item *db = *(struct item **) b;
|
||||
+
|
||||
+ if (!db)
|
||||
+ return 1;
|
||||
+ if (!da)
|
||||
+ return -1;
|
||||
+
|
||||
+ return da->distance == db->distance ? 0 : da->distance < db->distance ? -1 : 1;
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+fuzzymatch(void)
|
||||
+{
|
||||
+ /* bang - we have so much memory */
|
||||
+ struct item *it;
|
||||
+ struct item **fuzzymatches = NULL;
|
||||
+ char c;
|
||||
+ int number_of_matches = 0, i, pidx, sidx, eidx;
|
||||
+ int text_len = strlen(text), itext_len;
|
||||
+
|
||||
+ matches = matchend = NULL;
|
||||
+
|
||||
+ /* walk through all items */
|
||||
+ for (it = items; it && it->text; it++) {
|
||||
+ if (text_len) {
|
||||
+ itext_len = strlen(it->text);
|
||||
+ pidx = 0; /* pointer */
|
||||
+ sidx = eidx = -1; /* start of match, end of match */
|
||||
+ /* walk through item text */
|
||||
+ for (i = 0; i < itext_len && (c = it->text[i]); i++) {
|
||||
+ /* fuzzy match pattern */
|
||||
+ if (!fstrncmp(&text[pidx], &c, 1)) {
|
||||
+ if(sidx == -1)
|
||||
+ sidx = i;
|
||||
+ pidx++;
|
||||
+ if (pidx == text_len) {
|
||||
+ eidx = i;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ /* build list of matches */
|
||||
+ if (eidx != -1) {
|
||||
+ /* compute distance */
|
||||
+ /* add penalty if match starts late (log(sidx+2))
|
||||
+ * add penalty for long a match without many matching characters */
|
||||
+ it->distance = log(sidx + 2) + (double)(eidx - sidx - text_len);
|
||||
+ /* fprintf(stderr, "distance %s %f\n", it->text, it->distance); */
|
||||
+ appenditem(it, &matches, &matchend);
|
||||
+ number_of_matches++;
|
||||
+ }
|
||||
+ } else {
|
||||
+ appenditem(it, &matches, &matchend);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (number_of_matches) {
|
||||
+ /* initialize array with matches */
|
||||
+ if (!(fuzzymatches = realloc(fuzzymatches, number_of_matches * sizeof(struct item*))))
|
||||
+ die("cannot realloc %u bytes:", number_of_matches * sizeof(struct item*));
|
||||
+ for (i = 0, it = matches; it && i < number_of_matches; i++, it = it->right) {
|
||||
+ fuzzymatches[i] = it;
|
||||
+ }
|
||||
+ /* sort matches according to distance */
|
||||
+ qsort(fuzzymatches, number_of_matches, sizeof(struct item*), compare_distance);
|
||||
+ /* rebuild list of matches */
|
||||
+ matches = matchend = NULL;
|
||||
+ for (i = 0, it = fuzzymatches[i]; i < number_of_matches && it && \
|
||||
+ it->text; i++, it = fuzzymatches[i]) {
|
||||
+ appenditem(it, &matches, &matchend);
|
||||
+ }
|
||||
+ free(fuzzymatches);
|
||||
+ }
|
||||
+ curr = sel = matches;
|
||||
+ calcoffsets();
|
||||
+}
|
||||
+
|
||||
static void
|
||||
match(void)
|
||||
{
|
||||
+ if (fuzzy) {
|
||||
+ fuzzymatch();
|
||||
+ return;
|
||||
+ }
|
||||
static char **tokv = NULL;
|
||||
static int tokn = 0;
|
||||
|
||||
@@ -702,6 +789,8 @@ 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], "-F")) /* grabs keyboard before reading stdin */
|
||||
+ fuzzy = 0;
|
||||
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
|
||||
fstrncmp = strncasecmp;
|
||||
fstrstr = cistrstr;
|
||||
--
|
||||
2.22.0
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
From c4de1032bd4c247bc20b6ab92a10a8d778966679 Mon Sep 17 00:00:00 2001
|
||||
From: Mehrad Mahmoudian <m.mahmoudian@gmail.com>
|
||||
Date: Tue, 4 May 2021 12:05:09 +0300
|
||||
Subject: [PATCH] patched with password patch
|
||||
|
||||
---
|
||||
dmenu.1 | 5 ++++-
|
||||
dmenu.c | 21 +++++++++++++++++----
|
||||
2 files changed, 21 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/dmenu.1 b/dmenu.1
|
||||
index 323f93c..762f707 100644
|
||||
--- a/dmenu.1
|
||||
+++ b/dmenu.1
|
||||
@@ -3,7 +3,7 @@
|
||||
dmenu \- dynamic menu
|
||||
.SH SYNOPSIS
|
||||
.B dmenu
|
||||
-.RB [ \-bfiv ]
|
||||
+.RB [ \-bfivP ]
|
||||
.RB [ \-l
|
||||
.IR lines ]
|
||||
.RB [ \-m
|
||||
@@ -47,6 +47,9 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
|
||||
.B \-i
|
||||
dmenu matches menu items case insensitively.
|
||||
.TP
|
||||
+.B \-P
|
||||
+dmenu will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored.
|
||||
+.TP
|
||||
.BI \-l " lines"
|
||||
dmenu lists items vertically, with the given number of lines.
|
||||
.TP
|
||||
diff --git a/dmenu.c b/dmenu.c
|
||||
index 65f25ce..ad8f63b 100644
|
||||
--- a/dmenu.c
|
||||
+++ b/dmenu.c
|
||||
@@ -37,7 +37,7 @@ struct item {
|
||||
static char text[BUFSIZ] = "";
|
||||
static char *embed;
|
||||
static int bh, mw, mh;
|
||||
-static int inputw = 0, promptw;
|
||||
+static int inputw = 0, promptw, passwd = 0;
|
||||
static int lrpad; /* sum of left and right padding */
|
||||
static size_t cursor;
|
||||
static struct item *items = NULL;
|
||||
@@ -132,6 +132,7 @@ drawmenu(void)
|
||||
unsigned int curpos;
|
||||
struct item *item;
|
||||
int x = 0, y = 0, w;
|
||||
+ char *censort;
|
||||
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
||||
@@ -143,7 +144,12 @@ drawmenu(void)
|
||||
/* draw input field */
|
||||
w = (lines > 0 || !matches) ? mw - x : inputw;
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
- drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
|
||||
+ if (passwd) {
|
||||
+ censort = ecalloc(1, sizeof(text));
|
||||
+ memset(censort, '.', strlen(text));
|
||||
+ drw_text(drw, x, 0, w, bh, lrpad / 2, censort, 0);
|
||||
+ free(censort);
|
||||
+ } else drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
|
||||
|
||||
curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
||||
if ((curpos += lrpad / 2 - 1) < w) {
|
||||
@@ -524,6 +530,11 @@ readstdin(void)
|
||||
char buf[sizeof text], *p;
|
||||
size_t i, imax = 0, size = 0;
|
||||
unsigned int tmpmax = 0;
|
||||
+ if(passwd){
|
||||
+ inputw = lines = 0;
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
|
||||
/* read each line from stdin and add it to the item list */
|
||||
for (i = 0; fgets(buf, sizeof buf, stdin); i++) {
|
||||
@@ -689,7 +700,7 @@ setup(void)
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
- fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
|
||||
+ fputs("usage: dmenu [-bfivP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
|
||||
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
@@ -712,7 +723,9 @@ main(int argc, char *argv[])
|
||||
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
|
||||
fstrncmp = strncasecmp;
|
||||
fstrstr = cistrstr;
|
||||
- } else if (i + 1 == argc)
|
||||
+ } else if (!strcmp(argv[i], "-P")) /* is the input a password */
|
||||
+ passwd = 1;
|
||||
+ else if (i + 1 == argc)
|
||||
usage();
|
||||
/* these options take one argument */
|
||||
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
|
||||
--
|
||||
2.31.1
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
--- dmenu.c
|
||||
+++ dmenu.c
|
||||
@@ -664,11 +681,17 @@ setup(void)
|
||||
if (!XGetWindowAttributes(dpy, parentwin, &wa))
|
||||
die("could not get embedding window attributes: 0x%lx",
|
||||
parentwin);
|
||||
- x = 0;
|
||||
- y = topbar ? 0 : wa.height - mh;
|
||||
- mw = wa.width;
|
||||
+
|
||||
+ if (centered) {
|
||||
+ mw = MIN(MAX(max_textw() + promptw, min_width), wa.width);
|
||||
+ x = (wa.width - mw) / 2;
|
||||
+ y = (wa.height - mh) / 2;
|
||||
+ } else {
|
||||
+ x = 0;
|
||||
+ y = topbar ? 0 : wa.height - mh;
|
||||
+ mw = wa.width;
|
||||
+ }
|
||||
}
|
||||
- promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
||||
inputw = MIN(inputw, mw/3);
|
||||
match();
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
--- dmenu.c
|
||||
+++ dmenu.c
|
||||
@@ -789,6 +876,8 @@ 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], "-F")) /* grabs keyboard before reading stdin */
|
||||
+ fuzzy = 0;
|
||||
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
|
||||
fstrncmp = strncasecmp;
|
||||
fstrstr = cistrstr;
|
1
util.h
1
util.h
|
@ -3,6 +3,7 @@
|
|||
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||
#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B))
|
||||
#define LENGTH(X) (sizeof (X) / sizeof (X)[0])
|
||||
|
||||
void die(const char *fmt, ...);
|
||||
void *ecalloc(size_t nmemb, size_t size);
|
||||
|
|
Loading…
Reference in a new issue