| 
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -36,7 +36,7 @@ static void dinput(void); | 
															
														
														
													
														
															
																 | 
																 | 
																static void drawmenu(void); | 
																 | 
																 | 
																static void drawmenu(void); | 
															
														
														
													
														
															
																 | 
																 | 
																static void drawmenuh(void); | 
																 | 
																 | 
																static void drawmenuh(void); | 
															
														
														
													
														
															
																 | 
																 | 
																static void drawmenuv(void); | 
																 | 
																 | 
																static void drawmenuv(void); | 
															
														
														
													
														
															
																 | 
																 | 
																static Bool grabkeyboard(void); | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																static void grabkeyboard(void); | 
															
														
														
													
														
															
																 | 
																 | 
																static void kpress(XKeyEvent *e); | 
																 | 
																 | 
																static void kpress(XKeyEvent *e); | 
															
														
														
													
														
															
																 | 
																 | 
																static void match(char *pattern); | 
																 | 
																 | 
																static void match(char *pattern); | 
															
														
														
													
														
															
																 | 
																 | 
																static void readstdin(void); | 
																 | 
																 | 
																static void readstdin(void); | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																		
																			
																		
																	
																 | 
																@ -52,14 +52,12 @@ static char *prompt = NULL; | 
															
														
														
													
														
															
																 | 
																 | 
																static char text[4096]; | 
																 | 
																 | 
																static char text[4096]; | 
															
														
														
													
														
															
																 | 
																 | 
																static int cmdw = 0; | 
																 | 
																 | 
																static int cmdw = 0; | 
															
														
														
													
														
															
																 | 
																 | 
																static int promptw = 0; | 
																 | 
																 | 
																static int promptw = 0; | 
															
														
														
													
														
															
																 | 
																 | 
																static int ret = 0; | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																static int screen; | 
																 | 
																 | 
																static int screen; | 
															
														
														
													
														
															
																 | 
																 | 
																static unsigned int lines = 0; | 
																 | 
																 | 
																static unsigned int lines = 0; | 
															
														
														
													
														
															
																 | 
																 | 
																static unsigned int numlockmask = 0; | 
																 | 
																 | 
																static unsigned int numlockmask = 0; | 
															
														
														
													
														
															
																 | 
																 | 
																static unsigned int mw, mh; | 
																 | 
																 | 
																static unsigned int mw, mh; | 
															
														
														
													
														
															
																 | 
																 | 
																static unsigned long normcol[ColLast]; | 
																 | 
																 | 
																static unsigned long normcol[ColLast]; | 
															
														
														
													
														
															
																 | 
																 | 
																static unsigned long selcol[ColLast]; | 
																 | 
																 | 
																static unsigned long selcol[ColLast]; | 
															
														
														
													
														
															
																 | 
																 | 
																static Bool running = True; | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																static Bool topbar = True; | 
																 | 
																 | 
																static Bool topbar = True; | 
															
														
														
													
														
															
																 | 
																 | 
																static DC dc; | 
																 | 
																 | 
																static DC dc; | 
															
														
														
													
														
															
																 | 
																 | 
																static Display *dpy; | 
																 | 
																 | 
																static Display *dpy; | 
															
														
														
													
												
													
														
															
																| 
																	
																		
																			
																		
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -87,15 +85,15 @@ appenditem(Item *i, Item **list, Item **last) { | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																void | 
																 | 
																 | 
																void | 
															
														
														
													
														
															
																 | 
																 | 
																calcoffsetsh(void) { | 
																 | 
																 | 
																calcoffsetsh(void) { | 
															
														
														
													
														
															
																 | 
																 | 
																	unsigned int w; | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																	unsigned int x; | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																	w = promptw + cmdw + (2 * spaceitem); | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																	x = promptw + cmdw + (2 * spaceitem); | 
															
														
														
													
														
															
																 | 
																 | 
																	for(next = curr; next; next = next->right) | 
																 | 
																 | 
																	for(next = curr; next; next = next->right) | 
															
														
														
													
														
															
																 | 
																 | 
																		if((w += MIN(textw(&dc, next->text), mw / 3)) > mw) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																		if((x += MIN(textw(&dc, next->text), mw / 3)) > mw) | 
															
														
														
													
														
															
																 | 
																 | 
																			break; | 
																 | 
																 | 
																			break; | 
															
														
														
													
														
															
																 | 
																 | 
																	w = promptw + cmdw + (2 * spaceitem); | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																	x = promptw + cmdw + (2 * spaceitem); | 
															
														
														
													
														
															
																 | 
																 | 
																	for(prev = curr; prev && prev->left; prev = prev->left) | 
																 | 
																 | 
																	for(prev = curr; prev && prev->left; prev = prev->left) | 
															
														
														
													
														
															
																 | 
																 | 
																		if((w += MIN(textw(&dc, prev->left->text), mw / 3)) > mw) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																		if((x += MIN(textw(&dc, prev->left->text), mw / 3)) > mw) | 
															
														
														
													
														
															
																 | 
																 | 
																			break; | 
																 | 
																 | 
																			break; | 
															
														
														
													
														
															
																 | 
																 | 
																} | 
																 | 
																 | 
																} | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
												
													
														
															
																| 
																	
																		
																			
																		
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -146,6 +144,7 @@ cleanup(void) { | 
															
														
														
													
														
															
																 | 
																 | 
																	cleanupdraw(&dc); | 
																 | 
																 | 
																	cleanupdraw(&dc); | 
															
														
														
													
														
															
																 | 
																 | 
																	XDestroyWindow(dpy, win); | 
																 | 
																 | 
																	XDestroyWindow(dpy, win); | 
															
														
														
													
														
															
																 | 
																 | 
																	XUngrabKeyboard(dpy, CurrentTime); | 
																 | 
																 | 
																	XUngrabKeyboard(dpy, CurrentTime); | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																	XCloseDisplay(dpy); | 
															
														
														
													
														
															
																 | 
																 | 
																} | 
																 | 
																 | 
																} | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																void | 
																 | 
																 | 
																void | 
															
														
														
													
												
													
														
															
																| 
																	
																		
																			
																		
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -182,7 +181,6 @@ drawmenu(void) { | 
															
														
														
													
														
															
																 | 
																 | 
																	else if(curr) | 
																 | 
																 | 
																	else if(curr) | 
															
														
														
													
														
															
																 | 
																 | 
																		drawmenuh(); | 
																 | 
																 | 
																		drawmenuh(); | 
															
														
														
													
														
															
																 | 
																 | 
																	XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); | 
																 | 
																 | 
																	XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); | 
															
														
														
													
														
															
																 | 
																 | 
																	XFlush(dpy); | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																} | 
																 | 
																 | 
																} | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																void | 
																 | 
																 | 
																void | 
															
														
														
													
												
													
														
															
																| 
																	
																		
																			
																		
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -219,7 +217,7 @@ drawmenuv(void) { | 
															
														
														
													
														
															
																 | 
																 | 
																	XMoveResizeWindow(dpy, win, wa.x, wa.y + (topbar ? 0 : wa.height - mh), mw, mh); | 
																 | 
																 | 
																	XMoveResizeWindow(dpy, win, wa.x, wa.y + (topbar ? 0 : wa.height - mh), mw, mh); | 
															
														
														
													
														
															
																 | 
																 | 
																} | 
																 | 
																 | 
																} | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																Bool | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																void | 
															
														
														
													
														
															
																 | 
																 | 
																grabkeyboard(void) { | 
																 | 
																 | 
																grabkeyboard(void) { | 
															
														
														
													
														
															
																 | 
																 | 
																	unsigned int len; | 
																 | 
																 | 
																	unsigned int len; | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																		
																			
																		
																	
																 | 
																@ -229,7 +227,8 @@ grabkeyboard(void) { | 
															
														
														
													
														
															
																 | 
																 | 
																			break; | 
																 | 
																 | 
																			break; | 
															
														
														
													
														
															
																 | 
																 | 
																		usleep(1000); | 
																 | 
																 | 
																		usleep(1000); | 
															
														
														
													
														
															
																 | 
																 | 
																	} | 
																 | 
																 | 
																	} | 
															
														
														
													
														
															
																 | 
																 | 
																	return len > 0; | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																	if(!len) | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																		exit(EXIT_FAILURE); | 
															
														
														
													
														
															
																 | 
																 | 
																} | 
																 | 
																 | 
																} | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																void | 
																 | 
																 | 
																void | 
															
														
														
													
												
													
														
															
																| 
																	
																		
																			
																		
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -326,9 +325,7 @@ kpress(XKeyEvent *e) { | 
															
														
														
													
														
															
																 | 
																 | 
																			sel = sel->right; | 
																 | 
																 | 
																			sel = sel->right; | 
															
														
														
													
														
															
																 | 
																 | 
																		break; | 
																 | 
																 | 
																		break; | 
															
														
														
													
														
															
																 | 
																 | 
																	case XK_Escape: | 
																 | 
																 | 
																	case XK_Escape: | 
															
														
														
													
														
															
																 | 
																 | 
																		ret = 1; | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																		running = False; | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																		return; | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																		exit(EXIT_FAILURE); | 
															
														
														
													
														
															
																 | 
																 | 
																	case XK_Home: | 
																 | 
																 | 
																	case XK_Home: | 
															
														
														
													
														
															
																 | 
																 | 
																		sel = curr = item; | 
																 | 
																 | 
																		sel = curr = item; | 
															
														
														
													
														
															
																 | 
																 | 
																		calcoffsets(); | 
																 | 
																 | 
																		calcoffsets(); | 
															
														
														
													
												
													
														
															
																| 
																	
																		
																			
																		
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -360,8 +357,7 @@ kpress(XKeyEvent *e) { | 
															
														
														
													
														
															
																 | 
																 | 
																			dinput(); | 
																 | 
																 | 
																			dinput(); | 
															
														
														
													
														
															
																 | 
																 | 
																		fprintf(stdout, "%s", sel ? sel->text : text); | 
																 | 
																 | 
																		fprintf(stdout, "%s", sel ? sel->text : text); | 
															
														
														
													
														
															
																 | 
																 | 
																		fflush(stdout); | 
																 | 
																 | 
																		fflush(stdout); | 
															
														
														
													
														
															
																 | 
																 | 
																		running = False; | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																		return; | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																		exit(EXIT_SUCCESS); | 
															
														
														
													
														
															
																 | 
																 | 
																	case XK_Right: | 
																 | 
																 | 
																	case XK_Right: | 
															
														
														
													
														
															
																 | 
																 | 
																	case XK_Down: | 
																 | 
																 | 
																	case XK_Down: | 
															
														
														
													
														
															
																 | 
																 | 
																		if(!sel || !sel->right) | 
																 | 
																 | 
																		if(!sel || !sel->right) | 
															
														
														
													
												
													
														
															
																| 
																	
																		
																			
																		
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -454,7 +450,8 @@ run(void) { | 
															
														
														
													
														
															
																 | 
																 | 
																	XEvent ev; | 
																 | 
																 | 
																	XEvent ev; | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																	/* main event loop */ | 
																 | 
																 | 
																	/* main event loop */ | 
															
														
														
													
														
															
																 | 
																 | 
																	while(running && !XNextEvent(dpy, &ev)) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																	XSync(dpy, False); | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																	while(!XNextEvent(dpy, &ev)) | 
															
														
														
													
														
															
																 | 
																 | 
																		switch(ev.type) { | 
																 | 
																 | 
																		switch(ev.type) { | 
															
														
														
													
														
															
																 | 
																 | 
																		case KeyPress: | 
																 | 
																 | 
																		case KeyPress: | 
															
														
														
													
														
															
																 | 
																 | 
																			kpress(&ev.xkey); | 
																 | 
																 | 
																			kpress(&ev.xkey); | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																		
																			
																		
																	
																 | 
																@ -464,10 +461,11 @@ run(void) { | 
															
														
														
													
														
															
																 | 
																 | 
																				drawmenu(); | 
																 | 
																 | 
																				drawmenu(); | 
															
														
														
													
														
															
																 | 
																 | 
																			break; | 
																 | 
																 | 
																			break; | 
															
														
														
													
														
															
																 | 
																 | 
																		case VisibilityNotify: | 
																 | 
																 | 
																		case VisibilityNotify: | 
															
														
														
													
														
															
																 | 
																 | 
																			if (ev.xvisibility.state != VisibilityUnobscured) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																			if(ev.xvisibility.state != VisibilityUnobscured) | 
															
														
														
													
														
															
																 | 
																 | 
																				XRaiseWindow(dpy, win); | 
																 | 
																 | 
																				XRaiseWindow(dpy, win); | 
															
														
														
													
														
															
																 | 
																 | 
																			break; | 
																 | 
																 | 
																			break; | 
															
														
														
													
														
															
																 | 
																 | 
																		} | 
																 | 
																 | 
																		} | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																	exit(EXIT_FAILURE); | 
															
														
														
													
														
															
																 | 
																 | 
																} | 
																 | 
																 | 
																} | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																void | 
																 | 
																 | 
																void | 
															
														
														
													
												
													
														
															
																| 
																	
																		
																			
																		
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -586,13 +584,15 @@ main(int argc, char *argv[]) { | 
															
														
														
													
														
															
																 | 
																 | 
																		} | 
																 | 
																 | 
																		} | 
															
														
														
													
														
															
																 | 
																 | 
																		else { | 
																 | 
																 | 
																		else { | 
															
														
														
													
														
															
																 | 
																 | 
																			fputs("usage: dmenu [-i] [-b] [-l <lines>] [-fn <font>] [-nb <color>]\n" | 
																 | 
																 | 
																			fputs("usage: dmenu [-i] [-b] [-l <lines>] [-fn <font>] [-nb <color>]\n" | 
															
														
														
													
														
															
																 | 
																 | 
																			       "             [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n", stderr); | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																			      "             [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n", stderr); | 
															
														
														
													
														
															
																 | 
																 | 
																			exit(EXIT_FAILURE); | 
																 | 
																 | 
																			exit(EXIT_FAILURE); | 
															
														
														
													
														
															
																 | 
																 | 
																		} | 
																 | 
																 | 
																		} | 
															
														
														
													
														
															
																 | 
																 | 
																	if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) | 
																 | 
																 | 
																	if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) | 
															
														
														
													
														
															
																 | 
																 | 
																		fprintf(stderr, "dmenu: warning: no locale support\n"); | 
																 | 
																 | 
																		fprintf(stderr, "dmenu: warning: no locale support\n"); | 
															
														
														
													
														
															
																 | 
																 | 
																	if(!(dpy = XOpenDisplay(NULL))) | 
																 | 
																 | 
																	if(!(dpy = XOpenDisplay(NULL))) | 
															
														
														
													
														
															
																 | 
																 | 
																		eprint("cannot open display\n"); | 
																 | 
																 | 
																		eprint("cannot open display\n"); | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																	if(atexit(&cleanup) != 0) | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																		eprint("cannot register cleanup\n"); | 
															
														
														
													
														
															
																 | 
																 | 
																	screen = DefaultScreen(dpy); | 
																 | 
																 | 
																	screen = DefaultScreen(dpy); | 
															
														
														
													
														
															
																 | 
																 | 
																	root = RootWindow(dpy, screen); | 
																 | 
																 | 
																	root = RootWindow(dpy, screen); | 
															
														
														
													
														
															
																 | 
																 | 
																	if(!(argp = malloc(sizeof *argp * (argc+2)))) | 
																 | 
																 | 
																	if(!(argp = malloc(sizeof *argp * (argc+2)))) | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																		
																			
																		
																	
																 | 
																@ -600,13 +600,8 @@ main(int argc, char *argv[]) { | 
															
														
														
													
														
															
																 | 
																 | 
																	memcpy(argp + 2, argv + 1, sizeof *argp * argc); | 
																 | 
																 | 
																	memcpy(argp + 2, argv + 1, sizeof *argp * argc); | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																	readstdin(); | 
																 | 
																 | 
																	readstdin(); | 
															
														
														
													
														
															
																 | 
																 | 
																	running = grabkeyboard(); | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																	grabkeyboard(); | 
															
														
														
													
														
															
																 | 
																 | 
																	setup(); | 
																 | 
																 | 
																	setup(); | 
															
														
														
													
														
															
																 | 
																 | 
																	drawmenu(); | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																	XSync(dpy, False); | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																	run(); | 
																 | 
																 | 
																	run(); | 
															
														
														
													
														
															
																 | 
																 | 
																	cleanup(); | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																	XCloseDisplay(dpy); | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																	return ret; | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																	return 0; | 
															
														
														
													
														
															
																 | 
																 | 
																} | 
																 | 
																 | 
																} |