dmenu: update to 5.3.
Adopt. Drop fuzzymatch patch, broken since Oct 2022.
This commit is contained in:
parent
89468f5b8f
commit
f13c2356e4
2 changed files with 3 additions and 144 deletions
|
@ -1,134 +0,0 @@
|
||||||
diff --git a/dmenu.c b/dmenu.c
|
|
||||||
--- a/dmenu.c
|
|
||||||
+++ b/dmenu.c
|
|
||||||
@@ -32,6 +32,7 @@ struct item {
|
|
||||||
char *text;
|
|
||||||
struct item *left, *right;
|
|
||||||
int out;
|
|
||||||
+ int distance;
|
|
||||||
};
|
|
||||||
|
|
||||||
static char text[BUFSIZ] = "";
|
|
||||||
@@ -264,6 +265,86 @@ match(void)
|
|
||||||
calcoffsets();
|
|
||||||
}
|
|
||||||
|
|
||||||
+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;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+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;
|
|
||||||
+ sidx = eidx = -1;
|
|
||||||
+ /* walk through item text */
|
|
||||||
+ for (i = 0; i < itext_len && (c = it->text[i]); i++) {
|
|
||||||
+ /* fuzzy match pattern */
|
|
||||||
+ if (text[pidx] == c) {
|
|
||||||
+ if(sidx == -1)
|
|
||||||
+ sidx = i;
|
|
||||||
+ pidx++;
|
|
||||||
+ if (pidx == text_len) {
|
|
||||||
+ eidx = i;
|
|
||||||
+ break;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ /* build list of matches */
|
|
||||||
+ if (eidx != -1) {
|
|
||||||
+ /* compute distance */
|
|
||||||
+ /* factor in 30% of sidx and distance between eidx and total
|
|
||||||
+ * text length .. let's see how it works */
|
|
||||||
+ it->distance = eidx - sidx + (itext_len - eidx + sidx) / 3;
|
|
||||||
+ 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
|
|
||||||
insert(const char *str, ssize_t n)
|
|
||||||
{
|
|
||||||
@@ -274,7 +355,7 @@ insert(const char *str, ssize_t n)
|
|
||||||
if (n > 0)
|
|
||||||
memcpy(&text[cursor], str, n);
|
|
||||||
cursor += n;
|
|
||||||
- match();
|
|
||||||
+ fuzzymatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t
|
|
||||||
@@ -343,7 +424,7 @@ keypress(XKeyEvent *ev)
|
|
||||||
|
|
||||||
case XK_k: /* delete right */
|
|
||||||
text[cursor] = '\0';
|
|
||||||
- match();
|
|
||||||
+ fuzzymatch();
|
|
||||||
break;
|
|
||||||
case XK_u: /* delete left */
|
|
||||||
insert(NULL, 0 - cursor);
|
|
||||||
@@ -492,7 +573,7 @@ insert:
|
|
||||||
strncpy(text, sel->text, sizeof text - 1);
|
|
||||||
text[sizeof text - 1] = '\0';
|
|
||||||
cursor = strlen(text);
|
|
||||||
- match();
|
|
||||||
+ fuzzymatch();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -653,7 +734,7 @@ setup(void)
|
|
||||||
}
|
|
||||||
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
|
||||||
inputw = MIN(inputw, mw/3);
|
|
||||||
- match();
|
|
||||||
+ fuzzymatch();
|
|
||||||
|
|
||||||
/* create menu window */
|
|
||||||
swa.override_redirect = True;
|
|
|
@ -1,23 +1,16 @@
|
||||||
# Template file for 'dmenu'
|
# Template file for 'dmenu'
|
||||||
pkgname=dmenu
|
pkgname=dmenu
|
||||||
version=5.2
|
version=5.3
|
||||||
revision=1
|
revision=1
|
||||||
makedepends="libXinerama-devel libXft-devel freetype-devel"
|
makedepends="libXinerama-devel libXft-devel freetype-devel"
|
||||||
short_desc="Generic menu for X"
|
short_desc="Generic menu for X"
|
||||||
maintainer="Orphaned <orphan@voidlinux.org>"
|
maintainer="Leah Neukirchen <leah@vuxu.org>"
|
||||||
license="MIT"
|
license="MIT"
|
||||||
homepage="https://tools.suckless.org/dmenu/"
|
homepage="https://tools.suckless.org/dmenu/"
|
||||||
distfiles="https://dl.suckless.org/tools/${pkgname}-${version}.tar.gz"
|
distfiles="https://dl.suckless.org/tools/${pkgname}-${version}.tar.gz"
|
||||||
checksum=d4d4ca77b59140f272272db537e05bb91a5914f56802652dc57e61a773d43792
|
checksum=1a8f53e6fd2d749839ec870c5e27b3e14da5c3eeacbfcb945d159e1d5433795f
|
||||||
|
|
||||||
build_options="fuzzymatch"
|
|
||||||
desc_option_fuzzymatch="Enable Fuzzymatch support"
|
|
||||||
|
|
||||||
post_patch() {
|
post_patch() {
|
||||||
if [ "$build_option_fuzzymatch" ]; then
|
|
||||||
msg_normal "Applying fuzzymatch patches"
|
|
||||||
patch -slNp1 < "${FILESDIR}/fuzzymatch.patch"
|
|
||||||
fi
|
|
||||||
sed -i -e '/CFLAGS/{s/-Os//;s/=/+=/}' \
|
sed -i -e '/CFLAGS/{s/-Os//;s/=/+=/}' \
|
||||||
-e '/LDFLAGS/{s/-s//;s/=/+=/}' config.mk
|
-e '/LDFLAGS/{s/-s//;s/=/+=/}' config.mk
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue