]> git.pld-linux.org Git - packages/dmenu.git/blame - dmenu-xmms.patch
- xmms patch, based on http://tools.suckless.org/dmenu/patches/dmenu_xmms.diff
[packages/dmenu.git] / dmenu-xmms.patch
CommitLineData
d6a3ff48 1This patch is based on
2http://tools.suckless.org/dmenu/patches/dmenu_xmms.diff
3
4diff -up dmenu-4.1.1/config.def.h dmenu-4.1.1_xmms/config.def.h
5--- dmenu-4.1.1/config.def.h 2009-04-18 13:50:04.000000000 +0200
6+++ dmenu-4.1.1_xmms/config.def.h 2009-11-19 21:31:17.000000000 +0100
7@@ -7,3 +7,4 @@ static const char *normfgcolor = "#00000
8 static const char *selbgcolor = "#0066ff";
9 static const char *selfgcolor = "#ffffff";
10 static unsigned int spaceitem = 30; /* px between menu items */
11+static unsigned int maxtokens = 16; /* max. tokens for pattern matching */
12diff -up dmenu-4.1.1/dmenu.1 dmenu-4.1.1_xmms/dmenu.1
13--- dmenu-4.1.1/dmenu.1 2009-04-18 13:50:04.000000000 +0200
14+++ dmenu-4.1.1_xmms/dmenu.1 2009-11-19 21:14:24.000000000 +0100
15@@ -11,6 +11,7 @@ dmenu \- dynamic menu
16 .RB [ \-p " <prompt>"]
17 .RB [ \-sb " <color>"]
18 .RB [ \-sf " <color>"]
19+.RB [ \-xs ]
20 .RB [ \-v ]
21 .SH DESCRIPTION
22 .SS Overview
23@@ -44,6 +45,9 @@ defines the selected background color (#
24 .B \-sf <color>
25 defines the selected foreground color (#RGB, #RRGGBB, and color names are supported).
26 .TP
27+.B \-xs
28+xmms-like pattern matching.
29+.TP
30 .B \-v
31 prints version information to standard output, then exits.
32 .SH USAGE
33diff -u dmenu-4.1.1/dmenu.c.orig dmenu-4.1.1/dmenu.c
34--- dmenu-4.1.1/dmenu.c.orig 2010-05-29 13:56:51.000000000 +0200
35+++ dmenu-4.1.1/dmenu.c 2010-07-05 22:23:30.000000000 +0200
36@@ -75,6 +75,7 @@
37 /* variables */
38 static char *maxname = NULL;
39 static char *prompt = NULL;
40+static char **tokens = NULL;
41 static char text[4096];
42 static int cmdw = 0;
43 static int promptw = 0;
44@@ -84,6 +85,7 @@
45 static unsigned int mw, mh;
46 static unsigned int numlockmask = 0;
47 static Bool running = True;
48+static Bool xmms = False;
49 static Display *dpy;
50 static DC dc;
51 static Item *allitems = NULL; /* first of all items */
52@@ -578,22 +580,55 @@
53 drawmenu();
54 }
55
56+unsigned int tokenize(char *pat, char **tok)
57+{
58+ unsigned int i = 0;
59+ char tmp[4096] = {0};
60+
61+ strncpy(tmp, pat, strlen(pat));
62+ tok[0] = strtok(tmp, " ");
63+
64+ while(tok[i] && i < maxtokens)
65+ tok[++i] = strtok(NULL, " ");
66+ return i;
67+}
68+
69 void
70 match(char *pattern) {
71- unsigned int plen;
72+ unsigned int plen, tokencnt = 0;
73+ char append = 0;
74 Item *i, *itemend, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend;
75
76 if(!pattern)
77 return;
78- plen = strlen(pattern);
79+
80+ if(!xmms)
81+ tokens[(tokencnt = 1)-1] = pattern;
82+ else
83+ if(!(tokencnt = tokenize(pattern, tokens)))
84+ tokens[(tokencnt = 1)-1] = "";
85 item = lexact = lprefix = lsubstr = itemend = exactend = prefixend = substrend = NULL;
86- for(i = allitems; i; i = i->next)
87- if(!fstrncmp(pattern, i->text, plen + 1))
88+ for(i = allitems; i; i = i->next) {
89+ for(int j = 0; j < tokencnt; ++j) {
90+ plen = strlen(tokens[j]);
91+ if(!fstrncmp(tokens[j], i->text, plen + 1))
92+ append = !append || append > 1 ? 1 : append;
93+ else if(!fstrncmp(tokens[j], i->text, plen ))
94+ append = !append || append > 2 ? 2 : append;
95+ else if(fstrstr(i->text, tokens[j]))
96+ append = append > 0 && append < 3 ? append : 3;
97+ else {
98+ append = 0;
99+ break;
100+ }
101+ }
102+ if(append == 1)
103 appenditem(i, &lexact, &exactend);
104- else if(!fstrncmp(pattern, i->text, plen))
105+ else if(append == 2)
106 appenditem(i, &lprefix, &prefixend);
107- else if(fstrstr(i->text, pattern))
108+ else if(append == 3)
109 appenditem(i, &lsubstr, &substrend);
110+ }
111 if(lexact) {
112 item = lexact;
113 itemend = exactend;
114@@ -748,6 +783,7 @@
115 if(prompt)
116 promptw = MIN(textw(prompt), mw / 5);
117 text[0] = '\0';
118+ tokens = malloc((xmms?maxtokens:1)*sizeof(char*));
119 match(text);
120 XMapRaised(dpy, win);
121 }
122@@ -806,11 +842,13 @@
123 else if(!strcmp(argv[i], "-sf")) {
124 if(++i < argc) selfgcolor = argv[i];
125 }
126+ else if(!strcmp(argv[i], "-xs"))
127+ xmms = True;
128 else if(!strcmp(argv[i], "-v"))
129 eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n");
130 else
131 eprint("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-nb <color>]\n"
132- " [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
133+ " [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-xs] [-v]\n");
134 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
135 fprintf(stderr, "warning: no locale support\n");
136 if(!(dpy = XOpenDisplay(NULL)))
This page took 0.050223 seconds and 4 git commands to generate.