URI: 
       dmenu-nosort-5.0.diff - sites - public wiki contents of suckless.org
  HTML git clone git://git.suckless.org/sites
   DIR Log
   DIR Files
   DIR Refs
       ---
       dmenu-nosort-5.0.diff (2749B)
       ---
            1 From 7fbf9575aff62301e17b7f0601080633ae2a8a34 Mon Sep 17 00:00:00 2001
            2 From: Matt Briancon <matt.briancon@gmail.com>
            3 Date: Fri, 25 Sep 2020 22:13:38 -0400
            4 Subject: [PATCH] -S: do not sort matches
            5 
            6 ---
            7  dmenu.1 |  3 +++
            8  dmenu.c | 23 ++++++++++++++++-------
            9  2 files changed, 19 insertions(+), 7 deletions(-)
           10 
           11 diff --git a/dmenu.1 b/dmenu.1
           12 index 323f93c..b6af611 100644
           13 --- a/dmenu.1
           14 +++ b/dmenu.1
           15 @@ -47,6 +47,9 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
           16  .B \-i
           17  dmenu matches menu items case insensitively.
           18  .TP
           19 +.B \-S
           20 +dmenu does not sort menu items after matching.
           21 +.TP
           22  .BI \-l " lines"
           23  dmenu lists items vertically, with the given number of lines.
           24  .TP
           25 diff --git a/dmenu.c b/dmenu.c
           26 index 65f25ce..efe968c 100644
           27 --- a/dmenu.c
           28 +++ b/dmenu.c
           29 @@ -1,6 +1,7 @@
           30  /* See LICENSE file for copyright and license details. */
           31  #include <ctype.h>
           32  #include <locale.h>
           33 +#include <stdbool.h>
           34  #include <stdio.h>
           35  #include <stdlib.h>
           36  #include <string.h>
           37 @@ -44,6 +45,7 @@ static struct item *items = NULL;
           38  static struct item *matches, *matchend;
           39  static struct item *prev, *curr, *next, *sel;
           40  static int mon = -1, screen;
           41 +static bool sortmatches = true;
           42 
           43  static Atom clip, utf8;
           44  static Display *dpy;
           45 @@ -236,13 +238,18 @@ match(void)
           46                                  break;
           47                  if (i != tokc) /* not all tokens match */
           48                          continue;
           49 -                /* exact matches go first, then prefixes, then substrings */
           50 -                if (!tokc || !fstrncmp(text, item->text, textsize))
           51 +
           52 +                if (!sortmatches)
           53                          appenditem(item, &matches, &matchend);
           54 -                else if (!fstrncmp(tokv[0], item->text, len))
           55 -                        appenditem(item, &lprefix, &prefixend);
           56 -                else
           57 -                        appenditem(item, &lsubstr, &substrend);
           58 +                else {
           59 +                        /* exact matches go first, then prefixes, then substrings */
           60 +                        if (!tokc || !fstrncmp(text, item->text, textsize))
           61 +                                appenditem(item, &matches, &matchend);
           62 +                        else if (!fstrncmp(tokv[0], item->text, len))
           63 +                                appenditem(item, &lprefix, &prefixend);
           64 +                        else
           65 +                                appenditem(item, &lsubstr, &substrend);
           66 +                }
           67          }
           68          if (lprefix) {
           69                  if (matches) {
           70 @@ -689,7 +696,7 @@ setup(void)
           71  static void
           72  usage(void)
           73  {
           74 -        fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
           75 +        fputs("usage: dmenu [-bfivS] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
           76                "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
           77          exit(1);
           78  }
           79 @@ -709,6 +716,8 @@ main(int argc, char *argv[])
           80                          topbar = 0;
           81                  else if (!strcmp(argv[i], "-f"))   /* grabs keyboard before reading stdin */
           82                          fast = 1;
           83 +                else if (!strcmp(argv[i], "-S"))   /* do not sort matches */
           84 +                        sortmatches = false;
           85                  else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
           86                          fstrncmp = strncasecmp;
           87                          fstrstr = cistrstr;
           88 --
           89 2.25.1
           90