static int mx, my, mw, mh;
static int ret = 0;
static int nitem = 0;
static unsigned int cmdw = 0;
static int mx, my, mw, mh;
static int ret = 0;
static int nitem = 0;
static unsigned int cmdw = 0;
static Item *allitems = NULL; /* first of all items */
static Item *item = NULL; /* first of pattern matching items */
static Item *sel = NULL;
static Item *allitems = NULL; /* first of all items */
static Item *item = NULL; /* first of pattern matching items */
static Item *sel = NULL;
}
XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
XFlush(dpy);
}
static void
}
XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
XFlush(dpy);
}
static void
- if(!plen || !strncmp(pattern, i->text, plen)) {
- if(!j)
- item = i;
- else
- j->right = i;
- i->left = j;
- i->right = NULL;
- j = i;
- nitem++;
- }
- for(i = allitems; i; i=i->next)
- if(plen && strncmp(pattern, i->text, plen)
- && strstr(i->text, pattern)) {
+ if(plen ? !strncmp(pattern, i->text, plen) :
+ strncmp(pattern, i->text, plen) && strstr(i->text, pattern)) {
- if(e->state & ShiftMask) {
- if(text)
- fprintf(stdout, "%s", text);
- }
+ 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);
else if(sel)
fprintf(stdout, "%s", sel->text);
else if(text)
fprintf(stdout, "%s", text);
fflush(stdout);
strncat(text, buf, sizeof(text));
else
strncpy(text, buf, sizeof(text));
strncat(text, buf, sizeof(text));
else
strncpy(text, buf, sizeof(text));
static char *maxname = NULL;
char *p, buf[1024];
unsigned int len = 0, max = 0;
static char *maxname = NULL;
char *p, buf[1024];
unsigned int len = 0, max = 0;
- /* command line args */
- for(i = 1; i < argc; i++) {
- if (argv[i][0] == '-')
- switch (argv[i][1]) {
- case 'v':
- fputs("dmenu-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
- exit(EXIT_SUCCESS);
- break;
- case 't':
- if(++i < argc) {
- title = argv[i];
- break;
- }
- default:
- eprint("usage: dmenu [-v] [-t <title>]\n");
- break;
- }
- else
- eprint("usage: dmenu [-v] [-t <title>]\n");
+ if(argc == 2 && !strncmp("-v", argv[1], 3)) {
+ fputs("dmenu-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
+ exit(EXIT_SUCCESS);
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
- maxname = readinput();
-
- /* grab as early as possible, but after reading all items!!! */
+ /* Note, the select() construction allows to grab all keypresses as
+ * early as possible, to not loose them. But if there is no standard
+ * input supplied, we will make sure to exit after MAX_WAIT_STDIN
+ * seconds. This is convenience behavior for rapid typers.
+ */
while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
GrabModeAsync, CurrentTime) != GrabSuccess)
usleep(1000);
while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
GrabModeAsync, CurrentTime) != GrabSuccess)
usleep(1000);
+ timeout.tv_usec = 0;
+ timeout.tv_sec = STDIN_TIMEOUT;
+ FD_ZERO(&rd);
+ FD_SET(STDIN_FILENO, &rd);
+ if(select(ConnectionNumber(dpy) + 1, &rd, NULL, NULL, &timeout) < 1)
+ goto UninitializedEnd;
+ maxname = readstdin();
+
- dc.bg = getcolor(BGCOLOR);
- dc.fg = getcolor(FGCOLOR);
- dc.border = getcolor(BORDERCOLOR);
+ dc.sel[ColBG] = getcolor(SELBGCOLOR);
+ dc.sel[ColFG] = getcolor(SELFGCOLOR);
+ dc.norm[ColBG] = getcolor(NORMBGCOLOR);
+ dc.norm[ColFG] = getcolor(NORMFGCOLOR);
win = XCreateWindow(dpy, root, mx, my, mw, mh, 0,
DefaultDepth(dpy, screen), CopyFromParent,
win = XCreateWindow(dpy, root, mx, my, mw, mh, 0,
DefaultDepth(dpy, screen), CopyFromParent,
/* pixmap */
dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen));
dc.gc = XCreateGC(dpy, root, 0, 0);
/* pixmap */
dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen));
dc.gc = XCreateGC(dpy, root, 0, 0);
- XUngrabKeyboard(dpy, CurrentTime);
+ while(allitems) {
+ i = allitems->next;
+ free(allitems->text);
+ free(allitems);
+ allitems = i;
+ }
+ if(dc.font.set)
+ XFreeFontSet(dpy, dc.font.set);
+ else
+ XFreeFont(dpy, dc.font.xfont);
XFreePixmap(dpy, dc.drawable);
XFreeGC(dpy, dc.gc);
XDestroyWindow(dpy, win);
XFreePixmap(dpy, dc.drawable);
XFreeGC(dpy, dc.gc);
XDestroyWindow(dpy, win);