[dev] dmenu patch to return all matching items (for a new dmenu-powered music player interface)

From: Dan Brown <danbrown_AT_gmail.com>
Date: Wed, 10 Nov 2010 21:25:09 -0800

Hello and thanks everyone.

As part of a project to create a simple and fast music player
interface, I patched dmenu to allow it to return all matching items
instead of just the one at the cursor. dmenu is the browsing
interface; and there is another mode of operation that takes keywords
as hints for a partial match on filenames. The items then get loaded
into a mpc/mpd playlist with a shell script. See
http://github.com/dbro/muss for that code.

Why is this patch of interest? I call it "filtermode" because it uses
dmenu to generate a list of matches, with interactivity similar to the
trendy "instant" style of searching. For applications working with
sets of items, this method could be faster than the existing
dmenu-multiselect patch, in that it doesn't require the user to
manually select each item they want. The basis for the patch is dmenu
v4.1.1 .

Suggestions, comments welcome.
Dan

------

--- dmenu.c 2010-11-09 11:58:12.000000000 -0800
+++ dmenu.c 2010-11-09 13:10:54.000000000 -0800
@@ -98,6 +98,7 @@
 static unsigned int numlockmask = 0;
 static Bool running = True;
 static Bool xmms = False;
+static Bool filtermode = False;
 static Display *dpy;
 static DC dc;
 static Item *allitems = NULL; /* first of all items */
@@ -620,6 +621,12 @@
         case XK_Return:
                 if((e->state & ShiftMask) || !sel)
                         fprintf(stdout, "%s", text);
+ else if(filtermode) {
+ for(Item *i=sel; i; i=i->right)
+ fprintf(stdout, "%s\n", i->text);
+ for(Item *i=item; i&&(i!=sel); i=i->right)
+ fprintf(stdout, "%s\n", i->text);
+ }
                 else
                         fprintf(stdout, "%s", sel->text);
                 fflush(stdout);
@@ -939,10 +946,12 @@
                 }
                 else if(!strcmp(argv[i], "-xs"))
                         xmms = True;
+ else if(!strcmp(argv[i], "-f"))
+ filtermode = True;
                 else if(!strcmp(argv[i], "-v"))
                         eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE
for details\n");
                 else
- eprint("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn
<font>] [-fa <xftfont>] [-nb <color>]\n"
+ eprint("usage: dmenu [-i] [-b] [-e <xid>] [-f] [-l <lines>] [-fn
<font>] [-fa <xftfont>] [-nb <color>]\n"
                                " [-nf <color>] [-p <prompt>] [-sb <color>]
[-sf <color>] [-xs] [-v]\n");
         if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
                 fprintf(stderr, "warning: no locale support\n");
--- dmenu.1 2010-11-09 08:11:29.000000000 -0800
+++ dmenu.1 2010-11-09 13:14:06.000000000 -0800
@@ -6,6 +6,7 @@
 .RB [ \-i ]
 .RB [ \-b ]
 .RB [ \-l " <lines>"]
+.RB [ \-f ]
 .RB [ \-fn " <font>"]
 .RB [ \-nb " <color>"]
 .RB [ \-nf " <color>"]
@@ -32,6 +33,10 @@
 activates vertical list mode.
 The given number of lines will be displayed. Window height will get adjusted.
 .TP
+.B \-f
+activates filter mode.
+All matching items currently shown in the list will be selected,
starting with the item that is highlighted and wrapping around to the
beginning of the list.
+.TP
 .B \-fn <font>
 defines the font.
 .TP
Received on Thu Nov 11 2010 - 06:25:09 CET

This archive was generated by hypermail 2.2.0 : Thu Nov 11 2010 - 06:36:02 CET