added Xinerama support to dmenu, reverted -b behavior, removed -x, -y, -w
This commit is contained in:
		
							parent
							
								
									f3617bd7ca
								
							
						
					
					
						commit
						1f6af5e78f
					
				| @ -10,12 +10,17 @@ MANPREFIX = ${PREFIX}/share/man | |||||||
| X11INC = /usr/X11R6/include | X11INC = /usr/X11R6/include | ||||||
| X11LIB = /usr/X11R6/lib | X11LIB = /usr/X11R6/lib | ||||||
| 
 | 
 | ||||||
|  | # Xinerama, comment if you don't want it
 | ||||||
|  | XINERAMALIBS = -L${X11LIB} -lXinerama | ||||||
|  | XINERAMAFLAGS = -DXINERAMA | ||||||
|  | 
 | ||||||
| # includes and libs
 | # includes and libs
 | ||||||
| INCS = -I. -I/usr/include -I${X11INC} | INCS = -I. -I/usr/include -I${X11INC} | ||||||
| LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 | LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS} | ||||||
| 
 | 
 | ||||||
| # flags
 | # flags
 | ||||||
| CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" | CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} | ||||||
|  | CFLAGS = -Os ${INCS} ${CPPFLAGS} | ||||||
| LDFLAGS = -s ${LIBS} | LDFLAGS = -s ${LIBS} | ||||||
| #CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
 | #CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
 | ||||||
| #LDFLAGS = -g ${LIBS}
 | #LDFLAGS = -g ${LIBS}
 | ||||||
|  | |||||||
							
								
								
									
										18
									
								
								dmenu.1
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								dmenu.1
									
									
									
									
									
								
							| @ -4,9 +4,7 @@ dmenu \- dynamic menu | |||||||
| .SH SYNOPSIS | .SH SYNOPSIS | ||||||
| .B dmenu | .B dmenu | ||||||
| .RB [ \-i ] | .RB [ \-i ] | ||||||
| .RB [ \-x " <x>"] | .RB [ \-b ] | ||||||
| .RB [ \-y " <y>"] |  | ||||||
| .RB [ \-w " <width>"] |  | ||||||
| .RB [ \-fn " <font>"] | .RB [ \-fn " <font>"] | ||||||
| .RB [ \-nb " <color>"] | .RB [ \-nb " <color>"] | ||||||
| .RB [ \-nf " <color>"] | .RB [ \-nf " <color>"] | ||||||
| @ -22,20 +20,12 @@ It manages huge amounts (up to 10.000 and more) of user defined menu items | |||||||
| efficiently. | efficiently. | ||||||
| .SS Options | .SS Options | ||||||
| .TP | .TP | ||||||
| .B \-x |  | ||||||
| defines the x coordinate dmenu appears at (0 by default). |  | ||||||
| .TP |  | ||||||
| .B \-y |  | ||||||
| defines the y coordinate dmenu appears at (0 by default). If it is negative, |  | ||||||
| dmenu will appear with the bottom at the given positive coordinate. If it is |  | ||||||
| -0, dmenu appears at the screen bottom. |  | ||||||
| .TP |  | ||||||
| .B \-w |  | ||||||
| defines the width of the dmenu window (screen width by default). |  | ||||||
| .TP |  | ||||||
| .B \-i | .B \-i | ||||||
| makes dmenu match menu entries case insensitively. | makes dmenu match menu entries case insensitively. | ||||||
| .TP | .TP | ||||||
|  | .B \-b | ||||||
|  | defines that dmenu appears at the bottom. | ||||||
|  | .TP | ||||||
| .B \-fn <font> | .B \-fn <font> | ||||||
| defines the font. | defines the font. | ||||||
| .TP | .TP | ||||||
|  | |||||||
							
								
								
									
										60
									
								
								dmenu.c
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								dmenu.c
									
									
									
									
									
								
							| @ -1,6 +1,5 @@ | |||||||
| /* See LICENSE file for copyright and license details. */ | /* See LICENSE file for copyright and license details. */ | ||||||
| #include <ctype.h> | #include <ctype.h> | ||||||
| #include <limits.h> |  | ||||||
| #include <locale.h> | #include <locale.h> | ||||||
| #include <stdarg.h> | #include <stdarg.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| @ -10,6 +9,9 @@ | |||||||
| #include <X11/Xlib.h> | #include <X11/Xlib.h> | ||||||
| #include <X11/Xutil.h> | #include <X11/Xutil.h> | ||||||
| #include <X11/keysym.h> | #include <X11/keysym.h> | ||||||
|  | #ifdef XINERAMA | ||||||
|  | #include <X11/extensions/Xinerama.h> | ||||||
|  | #endif | ||||||
| 
 | 
 | ||||||
| /* macros */ | /* macros */ | ||||||
| #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) | #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) | ||||||
| @ -57,7 +59,7 @@ void kpress(XKeyEvent * e); | |||||||
| void match(char *pattern); | void match(char *pattern); | ||||||
| void readstdin(void); | void readstdin(void); | ||||||
| void run(void); | void run(void); | ||||||
| void setup(int x, int y, int w); | void setup(Bool topbar); | ||||||
| unsigned int textnw(const char *text, unsigned int len); | unsigned int textnw(const char *text, unsigned int len); | ||||||
| unsigned int textw(const char *text); | unsigned int textw(const char *text); | ||||||
| 
 | 
 | ||||||
| @ -601,10 +603,13 @@ run(void) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void | void | ||||||
| setup(int x, int y, int w) { | setup(Bool topbar) { | ||||||
| 	unsigned int i, j; | 	int i, j, x, y; | ||||||
| 	XModifierKeymap *modmap; | 	XModifierKeymap *modmap; | ||||||
| 	XSetWindowAttributes wa; | 	XSetWindowAttributes wa; | ||||||
|  | #if XINERAMA | ||||||
|  | 	XineramaScreenInfo *info = NULL; | ||||||
|  | #endif | ||||||
| 
 | 
 | ||||||
| 	/* init modifier map */ | 	/* init modifier map */ | ||||||
| 	modmap = XGetModifierMapping(dpy); | 	modmap = XGetModifierMapping(dpy); | ||||||
| @ -627,14 +632,25 @@ setup(int x, int y, int w) { | |||||||
| 	wa.override_redirect = 1; | 	wa.override_redirect = 1; | ||||||
| 	wa.background_pixmap = ParentRelative; | 	wa.background_pixmap = ParentRelative; | ||||||
| 	wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; | 	wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; | ||||||
| 	mw = w ? w : DisplayWidth(dpy, screen); | 
 | ||||||
|  | 	/* menu window geometry */ | ||||||
| 	mh = dc.font.height + 2; | 	mh = dc.font.height + 2; | ||||||
| 	if(y < 0) { | #if XINERAMA | ||||||
| 		if(y == INT_MIN) | 	if(XineramaIsActive(dpy)) { | ||||||
| 			y = DisplayHeight(dpy, screen) - mh; | 		info = XineramaQueryScreens(dpy, &i); | ||||||
| 		else | 		x = info[0].x_org; | ||||||
| 			y = (-1 * y) - mh; | 		y = topbar ? info[0].y_org : info[0].y_org + info[0].height - mh; | ||||||
|  | 		mw = info[0].width; | ||||||
|  | 		XFree(info); | ||||||
| 	} | 	} | ||||||
|  | 	else | ||||||
|  | #endif | ||||||
|  | 	{ | ||||||
|  | 		x = 0; | ||||||
|  | 		y = topbar ? 0 : DisplayHeight(dpy, screen) - mh; | ||||||
|  | 		mw = DisplayWidth(dpy, screen); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	win = XCreateWindow(dpy, root, x, y, mw, mh, 0, | 	win = XCreateWindow(dpy, root, x, y, mw, mh, 0, | ||||||
| 			DefaultDepth(dpy, screen), CopyFromParent, | 			DefaultDepth(dpy, screen), CopyFromParent, | ||||||
| 			DefaultVisual(dpy, screen), | 			DefaultVisual(dpy, screen), | ||||||
| @ -677,8 +693,8 @@ textw(const char *text) { | |||||||
| 
 | 
 | ||||||
| int | int | ||||||
| main(int argc, char *argv[]) { | main(int argc, char *argv[]) { | ||||||
| 	int x = 0, y = 0, w = 0; |  | ||||||
| 	unsigned int i; | 	unsigned int i; | ||||||
|  | 	Bool topbar = True; | ||||||
| 
 | 
 | ||||||
| 	/* command line args */ | 	/* command line args */ | ||||||
| 	for(i = 1; i < argc; i++) | 	for(i = 1; i < argc; i++) | ||||||
| @ -686,6 +702,8 @@ main(int argc, char *argv[]) { | |||||||
| 			fstrncmp = strncasecmp; | 			fstrncmp = strncasecmp; | ||||||
| 			fstrstr = cistrstr; | 			fstrstr = cistrstr; | ||||||
| 		} | 		} | ||||||
|  | 		else if(!strcmp(argv[i], "-b")) | ||||||
|  | 			topbar = False; | ||||||
| 		else if(!strcmp(argv[i], "-fn")) { | 		else if(!strcmp(argv[i], "-fn")) { | ||||||
| 			if(++i < argc) font = argv[i]; | 			if(++i < argc) font = argv[i]; | ||||||
| 		} | 		} | ||||||
| @ -704,25 +722,11 @@ main(int argc, char *argv[]) { | |||||||
| 		else if(!strcmp(argv[i], "-sf")) { | 		else if(!strcmp(argv[i], "-sf")) { | ||||||
| 			if(++i < argc) selfg = argv[i]; | 			if(++i < argc) selfg = argv[i]; | ||||||
| 		} | 		} | ||||||
| 		else if(!strcmp(argv[i], "-x")) { |  | ||||||
| 			if(++i < argc) x = atoi(argv[i]); |  | ||||||
| 		} |  | ||||||
| 		else if(!strcmp(argv[i], "-y")) { |  | ||||||
| 			if(++i < argc) |  | ||||||
| 				if(!strcmp(argv[i], "-0")) |  | ||||||
| 					y = INT_MIN; |  | ||||||
| 				else |  | ||||||
| 					y = atoi(argv[i]); |  | ||||||
| 		} |  | ||||||
| 		else if(!strcmp(argv[i], "-w")) { |  | ||||||
| 			if(++i < argc) w = atoi(argv[i]); |  | ||||||
| 		} |  | ||||||
| 		else if(!strcmp(argv[i], "-v")) | 		else if(!strcmp(argv[i], "-v")) | ||||||
| 			eprint("dmenu-"VERSION", © 2006-2008 dmenu engineers, see LICENSE for details\n"); | 			eprint("dmenu-"VERSION", © 2006-2008 dmenu engineers, see LICENSE for details\n"); | ||||||
| 		else | 		else | ||||||
| 			eprint("usage: dmenu [-i] [-fn <font>] [-nb <color>] [-nf <color>]\n" | 			eprint("usage: dmenu [-i] [-b] [-fn <font>] [-nb <color>] [-nf <color>]\n" | ||||||
| 			       "             [-p <prompt>] [-sb <color>] [-sf <color>]\n" | 			       "             [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n"); | ||||||
| 			       "             [-x <x>] [-y <y>] [-w <w>] [-v]\n"); |  | ||||||
| 	setlocale(LC_CTYPE, ""); | 	setlocale(LC_CTYPE, ""); | ||||||
| 	dpy = XOpenDisplay(0); | 	dpy = XOpenDisplay(0); | ||||||
| 	if(!dpy) | 	if(!dpy) | ||||||
| @ -739,7 +743,7 @@ main(int argc, char *argv[]) { | |||||||
| 		readstdin(); | 		readstdin(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	setup(x, y, w); | 	setup(topbar); | ||||||
| 	drawmenu(); | 	drawmenu(); | ||||||
| 	XSync(dpy, False); | 	XSync(dpy, False); | ||||||
| 	run(); | 	run(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user