Compare commits
	
		
			5 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 16ef6d4581 | |||
| 8d3994989f | |||
| cf4bba27cd | |||
| 0769f9bc04 | |||
| d2589d8554 | 
| @ -2,6 +2,8 @@ | |||||||
| /* Default settings; can be overriden by command line. */ | /* Default settings; can be overriden by command line. */ | ||||||
| 
 | 
 | ||||||
| static int topbar = 1;                      /* -b  option; if 0, dmenu appears at bottom     */ | static int topbar = 1;                      /* -b  option; if 0, dmenu appears at bottom     */ | ||||||
|  | static int centered = 0;                    /* -c option; centers dmenu on screen */ | ||||||
|  | static int min_width = 500;                    /* minimum width when centered */ | ||||||
| /* -fn option overrides fonts[0]; default X11 font or font set */ | /* -fn option overrides fonts[0]; default X11 font or font set */ | ||||||
| static const char *fonts[] = { | static const char *fonts[] = { | ||||||
| 	"monospace:size=10" | 	"monospace:size=10" | ||||||
| @ -15,6 +17,7 @@ static const char *colors[SchemeLast][2] = { | |||||||
| }; | }; | ||||||
| /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ | /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ | ||||||
| static unsigned int lines      = 0; | static unsigned int lines      = 0; | ||||||
|  | static unsigned int lineheight = 0;         /* -h option; minimum height of a menu line     */ | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  * Characters not considered part of a word while deleting words |  * Characters not considered part of a word while deleting words | ||||||
|  | |||||||
							
								
								
									
										29
									
								
								config.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								config.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | |||||||
|  | /* See LICENSE file for copyright and license details. */ | ||||||
|  | /* Default settings; can be overriden by command line. */ | ||||||
|  | 
 | ||||||
|  | static int topbar = 1;                      /* -b  option; if 0, dmenu appears at bottom     */ | ||||||
|  | static int centered = 0;                    /* -c option; centers dmenu on screen */ | ||||||
|  | static int min_width = 500;                    /* minimum width when centered */ | ||||||
|  | /* -fn option overrides fonts[0]; default X11 font or font set */ | ||||||
|  | static const char *fonts[] = { | ||||||
|  | 	"monospace:size=10" | ||||||
|  | }; | ||||||
|  | static const char *prompt      = NULL;      /* -p  option; prompt to the left of input field */ | ||||||
|  | static const char *colors[SchemeLast][2] = { | ||||||
|  | 	/*     fg         bg       */ | ||||||
|  | 	[SchemeNorm] = { "#bbbbbb", "#222222" }, | ||||||
|  | 	[SchemeSel] = { "#eeeeee", "#005577" }, | ||||||
|  | 	[SchemeOut] = { "#000000", "#00ffff" }, | ||||||
|  | }; | ||||||
|  | /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ | ||||||
|  | static unsigned int lines      = 0; | ||||||
|  | static unsigned int lineheight = 0;         /* -h option; minimum height of a menu line     */ | ||||||
|  | 
 | ||||||
|  | /*
 | ||||||
|  |  * Characters not considered part of a word while deleting words | ||||||
|  |  * for example: " /?\"&[]" | ||||||
|  |  */ | ||||||
|  | static const char worddelimiters[] = " "; | ||||||
|  | 
 | ||||||
|  | /* Size of the window border */ | ||||||
|  | static const unsigned int border_width = 5; | ||||||
							
								
								
									
										6
									
								
								dmenu.1
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								dmenu.1
									
									
									
									
									
								
							| @ -40,6 +40,9 @@ which lists programs in the user's $PATH and runs the result in their $SHELL. | |||||||
| .B \-b | .B \-b | ||||||
| dmenu appears at the bottom of the screen. | dmenu appears at the bottom of the screen. | ||||||
| .TP | .TP | ||||||
|  | .B \-c | ||||||
|  | dmenu appears centered on the screen. | ||||||
|  | .TP | ||||||
| .B \-f | .B \-f | ||||||
| dmenu grabs the keyboard before reading stdin if not reading from a tty. This | dmenu grabs the keyboard before reading stdin if not reading from a tty. This | ||||||
| is faster, but will lock up X until stdin reaches end\-of\-file. | is faster, but will lock up X until stdin reaches end\-of\-file. | ||||||
| @ -50,6 +53,9 @@ dmenu matches menu items case insensitively. | |||||||
| .BI \-l " lines" | .BI \-l " lines" | ||||||
| dmenu lists items vertically, with the given number of lines. | dmenu lists items vertically, with the given number of lines. | ||||||
| .TP | .TP | ||||||
|  | .BI \-h " height" | ||||||
|  | dmenu uses a menu line of at least 'height' pixels tall, but no less than 8. | ||||||
|  | .TP | ||||||
| .BI \-m " monitor" | .BI \-m " monitor" | ||||||
| dmenu is displayed on the monitor number supplied. Monitor numbers are starting | dmenu is displayed on the monitor number supplied. Monitor numbers are starting | ||||||
| from 0. | from 0. | ||||||
|  | |||||||
							
								
								
									
										87
									
								
								dmenu.c
									
									
									
									
									
								
							
							
						
						
									
										87
									
								
								dmenu.c
									
									
									
									
									
								
							| @ -15,6 +15,7 @@ | |||||||
| #include <X11/extensions/Xinerama.h> | #include <X11/extensions/Xinerama.h> | ||||||
| #endif | #endif | ||||||
| #include <X11/Xft/Xft.h> | #include <X11/Xft/Xft.h> | ||||||
|  | #include <X11/Xresource.h> | ||||||
| 
 | 
 | ||||||
| #include "drw.h" | #include "drw.h" | ||||||
| #include "util.h" | #include "util.h" | ||||||
| @ -92,6 +93,15 @@ calcoffsets(void) | |||||||
| 			break; | 			break; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static int | ||||||
|  | max_textw(void) | ||||||
|  | { | ||||||
|  | 	int len = 0; | ||||||
|  | 	for (struct item *item = items; item && item->text; item++) | ||||||
|  | 		len = MAX(TEXTW(item->text), len); | ||||||
|  | 	return len; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static void | static void | ||||||
| cleanup(void) | cleanup(void) | ||||||
| { | { | ||||||
| @ -149,7 +159,7 @@ drawmenu(void) | |||||||
| { | { | ||||||
| 	unsigned int curpos; | 	unsigned int curpos; | ||||||
| 	struct item *item; | 	struct item *item; | ||||||
| 	int x = 0, y = 0, w; | 	int x = 0, y = 0, fh = drw->fonts->h, w; | ||||||
| 
 | 
 | ||||||
| 	drw_setscheme(drw, scheme[SchemeNorm]); | 	drw_setscheme(drw, scheme[SchemeNorm]); | ||||||
| 	drw_rect(drw, 0, 0, mw, mh, 1, 1); | 	drw_rect(drw, 0, 0, mw, mh, 1, 1); | ||||||
| @ -166,7 +176,7 @@ drawmenu(void) | |||||||
| 	curpos = TEXTW(text) - TEXTW(&text[cursor]); | 	curpos = TEXTW(text) - TEXTW(&text[cursor]); | ||||||
| 	if ((curpos += lrpad / 2 - 1) < w) { | 	if ((curpos += lrpad / 2 - 1) < w) { | ||||||
| 		drw_setscheme(drw, scheme[SchemeNorm]); | 		drw_setscheme(drw, scheme[SchemeNorm]); | ||||||
| 		drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0); | 		drw_rect(drw, x + curpos, 2 + (bh-fh)/2, 2, fh - 4, 1, 0); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	recalculatenumbers(); | 	recalculatenumbers(); | ||||||
| @ -622,16 +632,23 @@ setup(void) | |||||||
| 	int a, di, n, area = 0; | 	int a, di, n, area = 0; | ||||||
| #endif | #endif | ||||||
| 	/* init appearance */ | 	/* init appearance */ | ||||||
| 	for (j = 0; j < SchemeLast; j++) | 	for (j = 0; j < SchemeLast; j++) { | ||||||
| 		scheme[j] = drw_scm_create(drw, colors[j], 2); | 		scheme[j] = drw_scm_create(drw, (const char**)colors[j], 2); | ||||||
|  | 	} | ||||||
|  | 	for (j = 0; j < SchemeOut; ++j) { | ||||||
|  | 		for (i = 0; i < 2; ++i) | ||||||
|  | 			free(colors[j][i]); | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	clip = XInternAtom(dpy, "CLIPBOARD",   False); | 	clip = XInternAtom(dpy, "CLIPBOARD",   False); | ||||||
| 	utf8 = XInternAtom(dpy, "UTF8_STRING", False); | 	utf8 = XInternAtom(dpy, "UTF8_STRING", False); | ||||||
| 
 | 
 | ||||||
| 	/* calculate menu geometry */ | 	/* calculate menu geometry */ | ||||||
| 	bh = drw->fonts->h + 2; | 	bh = drw->fonts->h + 2; | ||||||
|  | 	bh = MAX(bh,lineheight);	/* make a menu line AT LEAST 'lineheight' tall */ | ||||||
| 	lines = MAX(lines, 0); | 	lines = MAX(lines, 0); | ||||||
| 	mh = (lines + 1) * bh; | 	mh = (lines + 1) * bh; | ||||||
|  | 	promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; | ||||||
| #ifdef XINERAMA | #ifdef XINERAMA | ||||||
| 	i = 0; | 	i = 0; | ||||||
| 	if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { | 	if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { | ||||||
| @ -658,9 +675,16 @@ setup(void) | |||||||
| 				if (INTERSECT(x, y, 1, 1, info[i])) | 				if (INTERSECT(x, y, 1, 1, info[i])) | ||||||
| 					break; | 					break; | ||||||
| 
 | 
 | ||||||
|  | 		if (centered) { | ||||||
|  | 			mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width); | ||||||
|  | 			x = info[i].x_org + ((info[i].width  - mw) / 2); | ||||||
|  | 			y = info[i].y_org + ((info[i].height - mh) / 2); | ||||||
|  | 		} else { | ||||||
| 			x = info[i].x_org; | 			x = info[i].x_org; | ||||||
| 			y = info[i].y_org + (topbar ? 0 : info[i].height - mh); | 			y = info[i].y_org + (topbar ? 0 : info[i].height - mh); | ||||||
| 			mw = info[i].width; | 			mw = info[i].width; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		XFree(info); | 		XFree(info); | ||||||
| 	} else | 	} else | ||||||
| #endif | #endif | ||||||
| @ -668,11 +692,17 @@ setup(void) | |||||||
| 		if (!XGetWindowAttributes(dpy, parentwin, &wa)) | 		if (!XGetWindowAttributes(dpy, parentwin, &wa)) | ||||||
| 			die("could not get embedding window attributes: 0x%lx", | 			die("could not get embedding window attributes: 0x%lx", | ||||||
| 			    parentwin); | 			    parentwin); | ||||||
|  | 
 | ||||||
|  | 		if (centered) { | ||||||
|  | 			mw = MIN(MAX(max_textw() + promptw, min_width), wa.width); | ||||||
|  | 			x = (wa.width  - mw) / 2; | ||||||
|  | 			y = (wa.height - mh) / 2; | ||||||
|  | 		} else { | ||||||
| 			x = 0; | 			x = 0; | ||||||
| 			y = topbar ? 0 : wa.height - mh; | 			y = topbar ? 0 : wa.height - mh; | ||||||
| 			mw = wa.width; | 			mw = wa.width; | ||||||
| 		} | 		} | ||||||
| 	promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; | 	} | ||||||
| 	inputw = MIN(inputw, mw/3); | 	inputw = MIN(inputw, mw/3); | ||||||
| 	match(); | 	match(); | ||||||
| 
 | 
 | ||||||
| @ -711,10 +741,46 @@ static void | |||||||
| usage(void) | usage(void) | ||||||
| { | { | ||||||
| 	fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" | 	fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" | ||||||
|  | 	      "             [-h height]\n" | ||||||
| 	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); | 	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); | ||||||
| 	exit(1); | 	exit(1); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void | ||||||
|  | readxresources(void) { | ||||||
|  | 	XrmInitialize(); | ||||||
|  | 
 | ||||||
|  | 	char* xrm; | ||||||
|  | 	if ((xrm = XResourceManagerString(drw->dpy))) { | ||||||
|  | 		char *type; | ||||||
|  | 		XrmDatabase xdb = XrmGetStringDatabase(xrm); | ||||||
|  | 		XrmValue xval; | ||||||
|  | 
 | ||||||
|  | 		if (XrmGetResource(xdb, "dmenu.font", "*", &type, &xval)) | ||||||
|  | 			fonts[0] = strdup(xval.addr); | ||||||
|  | 		else | ||||||
|  | 			fonts[0] = strdup(fonts[0]); | ||||||
|  | 		if (XrmGetResource(xdb, "dmenu.background", "*", &type, &xval)) | ||||||
|  | 			colors[SchemeNorm][ColBg] = strdup(xval.addr); | ||||||
|  | 		else | ||||||
|  | 			colors[SchemeNorm][ColBg] = strdup(colors[SchemeNorm][ColBg]); | ||||||
|  | 		if (XrmGetResource(xdb, "dmenu.foreground", "*", &type, &xval)) | ||||||
|  | 			colors[SchemeNorm][ColFg] = strdup(xval.addr); | ||||||
|  | 		else | ||||||
|  | 			colors[SchemeNorm][ColFg] = strdup(colors[SchemeNorm][ColFg]); | ||||||
|  | 		if (XrmGetResource(xdb, "dmenu.selbackground", "*", &type, &xval)) | ||||||
|  | 			colors[SchemeSel][ColBg] = strdup(xval.addr); | ||||||
|  | 		else | ||||||
|  | 			colors[SchemeSel][ColBg] = strdup(colors[SchemeSel][ColBg]); | ||||||
|  | 		if (XrmGetResource(xdb, "dmenu.selforeground", "*", &type, &xval)) | ||||||
|  | 			colors[SchemeSel][ColFg] = strdup(xval.addr); | ||||||
|  | 		else | ||||||
|  | 			colors[SchemeSel][ColFg] = strdup(colors[SchemeSel][ColFg]); | ||||||
|  | 
 | ||||||
|  | 		XrmDestroyDatabase(xdb); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| int | int | ||||||
| main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
| @ -730,6 +796,8 @@ main(int argc, char *argv[]) | |||||||
| 			topbar = 0; | 			topbar = 0; | ||||||
| 		else if (!strcmp(argv[i], "-f"))   /* grabs keyboard before reading stdin */ | 		else if (!strcmp(argv[i], "-f"))   /* grabs keyboard before reading stdin */ | ||||||
| 			fast = 1; | 			fast = 1; | ||||||
|  | 		else if (!strcmp(argv[i], "-c"))   /* centers dmenu on screen */ | ||||||
|  | 			centered = 1; | ||||||
| 		else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ | 		else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ | ||||||
| 			fstrncmp = strncasecmp; | 			fstrncmp = strncasecmp; | ||||||
| 			fstrstr = cistrstr; | 			fstrstr = cistrstr; | ||||||
| @ -744,6 +812,10 @@ main(int argc, char *argv[]) | |||||||
| 			prompt = argv[++i]; | 			prompt = argv[++i]; | ||||||
| 		else if (!strcmp(argv[i], "-fn"))  /* font or font set */ | 		else if (!strcmp(argv[i], "-fn"))  /* font or font set */ | ||||||
| 			fonts[0] = argv[++i]; | 			fonts[0] = argv[++i]; | ||||||
|  | 		else if(!strcmp(argv[i], "-h")) { /* minimum height of one menu line */ | ||||||
|  | 			lineheight = atoi(argv[++i]); | ||||||
|  | 			lineheight = MAX(lineheight,8); /* reasonable default in case of value too small/negative */ | ||||||
|  | 		} | ||||||
| 		else if (!strcmp(argv[i], "-nb"))  /* normal background color */ | 		else if (!strcmp(argv[i], "-nb"))  /* normal background color */ | ||||||
| 			colors[SchemeNorm][ColBg] = argv[++i]; | 			colors[SchemeNorm][ColBg] = argv[++i]; | ||||||
| 		else if (!strcmp(argv[i], "-nf"))  /* normal foreground color */ | 		else if (!strcmp(argv[i], "-nf"))  /* normal foreground color */ | ||||||
| @ -769,8 +841,11 @@ main(int argc, char *argv[]) | |||||||
| 		die("could not get embedding window attributes: 0x%lx", | 		die("could not get embedding window attributes: 0x%lx", | ||||||
| 		    parentwin); | 		    parentwin); | ||||||
| 	drw = drw_create(dpy, screen, root, wa.width, wa.height); | 	drw = drw_create(dpy, screen, root, wa.width, wa.height); | ||||||
| 	if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) | 	readxresources(); | ||||||
|  | 	if (!drw_fontset_create(drw, (const char**)fonts, LENGTH(fonts))) | ||||||
| 		die("no fonts could be loaded."); | 		die("no fonts could be loaded."); | ||||||
|  | 
 | ||||||
|  | 	free(fonts[0]); | ||||||
| 	lrpad = drw->fonts->h; | 	lrpad = drw->fonts->h; | ||||||
| 
 | 
 | ||||||
| #ifdef __OpenBSD__ | #ifdef __OpenBSD__ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user