--- dmenu.c.backup 2010-04-19 22:45:30.648256674 +0200 +++ dmenu.c 2010-05-09 16:57:41.652711011 +0200 @@ -40,6 +40,7 @@ typedef struct Item Item; struct Item { + unsigned int index; /* Index of item. */ char *text; Item *next; /* traverses all items */ Item *left, *right; /* traverses items matching current search pattern */ @@ -77,6 +78,7 @@ static unsigned int mw, mh; static unsigned int numlockmask = 0; static Bool running = True; +static Bool printindex = False; /* print text or index */ static Display *dpy; static DC dc; static Item *allitems = NULL; /* first of all items */ @@ -447,14 +449,22 @@ calcoffsets(); break; case XK_Return: - if((e->state & ShiftMask) && *text) - fprintf(stdout, "%s", text); - else if(sel) - fprintf(stdout, "%s", sel->text); - else if(*text) - fprintf(stdout, "%s", text); - fflush(stdout); - running = False; + if (printindex) { + if (sel) { + fprintf(stdout, "%u%c", sel->index, '\0'); + fflush(stdout); + running = False; + } + } else { + if((e->state & ShiftMask) && *text) + fprintf(stdout, "%s", text); + else if(sel) + fprintf(stdout, "%s", sel->text); + else if(*text) + fprintf(stdout, "%s", text); + fflush(stdout); + running = False; + } break; case XK_Right: if(!(sel && sel->right)) @@ -521,6 +531,7 @@ char *p, buf[1024]; unsigned int len = 0, max = 0; Item *i, *new; + unsigned int index = 0; i = 0; while(fgets(buf, sizeof buf, stdin)) { @@ -536,6 +547,7 @@ if(!(new = (Item *)malloc(sizeof(Item)))) eprint("fatal: could not malloc() %u bytes\n", sizeof(Item)); new->next = new->left = new->right = NULL; + new->index = index++; new->text = p; if(!i) allitems = new; @@ -676,6 +688,8 @@ } else if(!strcmp(argv[i], "-b")) topbar = False; + else if(!strcmp(argv[i], "-n")) + printindex = True; else if(!strcmp(argv[i], "-fn")) { if(++i < argc) font = argv[i]; } @@ -697,7 +711,7 @@ else if(!strcmp(argv[i], "-v")) eprint("dmenu-"VERSION", © 2006-2008 dmenu engineers, see LICENSE for details\n"); else - eprint("usage: dmenu [-i] [-b] [-fn ] [-nb ] [-nf ]\n" + eprint("usage: dmenu [-i] [-b] [-n] [-fn ] [-nb ] [-nf ]\n" " [-p ] [-sb ] [-sf ] [-v]\n"); if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fprintf(stderr, "warning: no locale support\n");