now procedural!
This commit is contained in:
		
							parent
							
								
									1faf2c9b8c
								
							
						
					
					
						commit
						ef4963523e
					
				| @ -3,16 +3,14 @@ | |||||||
| /* This is a hack I did years ago. Fork dmenu and start from there if you can.
 | /* This is a hack I did years ago. Fork dmenu and start from there if you can.
 | ||||||
|  * ~ trinity */ |  * ~ trinity */ | ||||||
| 
 | 
 | ||||||
| #include <locale.h> | #include <locale.h> /* setlocale(3), LC_CTYPE */ | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| #include <string.h> | #include <string.h> /* strlen(3) */ | ||||||
| #include <strings.h> |  | ||||||
| #include <sysexits.h> /* EX_USAGE */ | #include <sysexits.h> /* EX_USAGE */ | ||||||
| #include <unistd.h> | #include <unistd.h> /* getopt(3) */ | ||||||
| 
 | 
 | ||||||
| #include <X11/Xlib.h> | #include <X11/Xlib.h> | ||||||
| #include <X11/Xatom.h> |  | ||||||
| #include <X11/Xutil.h> | #include <X11/Xutil.h> | ||||||
| #ifdef XINERAMA | #ifdef XINERAMA | ||||||
| #include <X11/extensions/Xinerama.h> | #include <X11/extensions/Xinerama.h> | ||||||
| @ -25,16 +23,13 @@ | |||||||
| /* macros */ | /* macros */ | ||||||
| #define INTERSECT(x,y,w,h,r)  (MAX(0, MIN((x)+(w),(r).x_org+(r).width)  - MAX((x),(r).x_org)) \ | #define INTERSECT(x,y,w,h,r)  (MAX(0, MIN((x)+(w),(r).x_org+(r).width)  - MAX((x),(r).x_org)) \ | ||||||
|                              * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) |                              * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) | ||||||
| #define LENGTH(X)             (sizeof X / sizeof X[0]) |  | ||||||
| #define TEXTW(X)              (drw_fontset_getwidth(drw, (X)) + lrpad) |  | ||||||
| 
 | 
 | ||||||
| /* enums */ | /* enums */ | ||||||
| enum { Scheme, SchemeLast }; /* color schemes */ | enum { Scheme, SchemeLast }; /* color schemes */ | ||||||
| /* enumerated because Suckless has SchemeNorm, SchemeSel, etc.
 | /* enumerated because Suckless has SchemeNorm, SchemeSel, etc.
 | ||||||
|  * should be made into like one char *Scheme[2] */ |  * should be made into like one char *Scheme[2] */ | ||||||
| /* BTW SchemeLast is the size of an array of the schemes and it's used
 | /* BTW SchemeLast is the size of an array of the schemes and it's used
 | ||||||
|  * in this program for iteration. Assumes enums will be assigned |  * in this program for iteration. */ | ||||||
|  * 0,1,2,3... */ |  | ||||||
| 
 | 
 | ||||||
| static char *embed; | static char *embed; | ||||||
| static int bh, mw, mh; | static int bh, mw, mh; | ||||||
| @ -42,7 +37,6 @@ static int inputw = 0; | |||||||
| static int lrpad; /* sum of left and right padding */ | static int lrpad; /* sum of left and right padding */ | ||||||
| static int mon = -1, screen; | static int mon = -1, screen; | ||||||
| 
 | 
 | ||||||
| static Atom clip, utf8; |  | ||||||
| static Display *dpy; | static Display *dpy; | ||||||
| static Window root, parentwin, win; | static Window root, parentwin, win; | ||||||
| 
 | 
 | ||||||
| @ -51,41 +45,10 @@ static Clr *scheme[SchemeLast]; | |||||||
| 
 | 
 | ||||||
| #include "config.h" | #include "config.h" | ||||||
| 
 | 
 | ||||||
| static void |  | ||||||
| cleanup(void) |  | ||||||
| { |  | ||||||
| 	size_t i; |  | ||||||
| 
 |  | ||||||
| 	for (i = 0; i < SchemeLast; i++) |  | ||||||
| 		free(scheme[i]); |  | ||||||
| 	drw_free(drw); |  | ||||||
| 	XSync(dpy, False); |  | ||||||
| 	XCloseDisplay(dpy); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| int | int | ||||||
| textw(char *text) /* figure out how to remove me */ | main(int argc, char *argv[]){ | ||||||
| { | 	int c; | ||||||
| 	return (text && *text) ? TEXTW(text) - lrpad / 4 : 0; | 	extern char *optarg; | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void |  | ||||||
| drawmenu(char *text) |  | ||||||
| { |  | ||||||
| 	int x = 0; |  | ||||||
| 
 |  | ||||||
| 	drw_setscheme(drw, scheme[Scheme]); |  | ||||||
| 	drw_rect(drw, 0, 0, mw, mh, 1, 1); |  | ||||||
| 
 |  | ||||||
| 	if (text && *text) |  | ||||||
| 		x = drw_text(drw, x, 0, textw(text), bh, lrpad / 2, text, 0); |  | ||||||
| 
 |  | ||||||
| 	drw_map(drw, win, 0, 0, mw, mh); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| int |  | ||||||
| main(int argc, char *argv[]) |  | ||||||
| { |  | ||||||
| 	char text[text_s]; | 	char text[text_s]; | ||||||
| 	int x, y, i, j; | 	int x, y, i, j; | ||||||
| 	unsigned int du; | 	unsigned int du; | ||||||
| @ -102,30 +65,37 @@ main(int argc, char *argv[]) | |||||||
| 	for(i = 0; i < text_s; ++i) /* initialize text[] */ | 	for(i = 0; i < text_s; ++i) /* initialize text[] */ | ||||||
| 		text[i] = '\0'; | 		text[i] = '\0'; | ||||||
| 
 | 
 | ||||||
| 	for (i = 1; i < argc; i++) | 	while((c = getopt(argc, argv, ":bf:m:B:F:w:")) != -1) | ||||||
| 		if (!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */ | 		switch(c){ | ||||||
|  | 		case 'b': | ||||||
| 			topbar = 0; | 			topbar = 0; | ||||||
| 		else if (i + 1 == argc){ | 			break; | ||||||
| usage:			fprintf(stderr, "Usage: %s (-b) (-fn [font]) (-m [monitor]\n" | 		case 'B': if(optarg){ | ||||||
| 				"(-cb [color]) (-cf [color]) (-w [windowid])\n", | 			colors[Scheme][ColBg] = optarg; | ||||||
|  | 			break; | ||||||
|  | 		}case 'f': if(optarg){ | ||||||
|  | 			fonts[0] = optarg; | ||||||
|  | 			break; | ||||||
|  | 		}case 'F': if(optarg){ | ||||||
|  | 			colors[Scheme][ColFg] = argv[++i]; | ||||||
|  | 			break; | ||||||
|  | 		}case 'm': if(optarg){ | ||||||
|  | 			mon = atoi(argv[++i]); | ||||||
|  | 			break; | ||||||
|  | 		}case 'w': if(optarg){ | ||||||
|  | 			embed = argv[++i]; | ||||||
|  | 			break; | ||||||
|  | 		}default: /* optarg==0 falls through */ | ||||||
|  | 			fprintf(stderr, | ||||||
|  | 				"Usage: %s (-b) (-B [background color])" | ||||||
|  | 				"(-f [font]) (-F foreground color)\n" | ||||||
|  | 				"\t(-m [monitor]) (-w [windowid)\n", | ||||||
| 				argv[0]); | 				argv[0]); | ||||||
| 			return EX_USAGE; | 			return EX_USAGE; | ||||||
| 		/* these options take one argument */ | 		} | ||||||
| 		}else if (!strcmp(argv[i], "-m")) |  | ||||||
| 			mon = atoi(argv[++i]); |  | ||||||
| 		else if (!strcmp(argv[i], "-fn"))  /* font or font set */ |  | ||||||
| 			fonts[0] = argv[++i]; |  | ||||||
| 		else if (!strcmp(argv[i], "-cb"))  /* bg color */ |  | ||||||
| 			colors[Scheme][ColBg] = argv[++i]; |  | ||||||
| 		else if (!strcmp(argv[i], "-cf"))  /* fg color */ |  | ||||||
| 			colors[Scheme][ColFg] = argv[++i]; |  | ||||||
| 		else if (!strcmp(argv[i], "-w"))   /* embedding window id */ |  | ||||||
| 			embed = argv[++i]; |  | ||||||
| 		else |  | ||||||
| 			goto usage; |  | ||||||
| 
 | 
 | ||||||
| 	if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) | 	if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) | ||||||
| 		fputs("warning: no locale support\n", stderr); | 		fprintf(stderr, "%s: No locale support.\n", argv[0]); | ||||||
| 	if (!(dpy = XOpenDisplay(NULL))) | 	if (!(dpy = XOpenDisplay(NULL))) | ||||||
| 		die("cannot open display"); | 		die("cannot open display"); | ||||||
| 	screen = DefaultScreen(dpy); | 	screen = DefaultScreen(dpy); | ||||||
| @ -136,7 +106,7 @@ usage:			fprintf(stderr, "Usage: %s (-b) (-fn [font]) (-m [monitor]\n" | |||||||
| 		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))) | 	if (!drw_fontset_create(drw, fonts, (sizeof fonts) / (sizeof *fonts))) | ||||||
| 		die("no fonts could be loaded."); | 		die("no fonts could be loaded."); | ||||||
| 	lrpad = drw->fonts->h; | 	lrpad = drw->fonts->h; | ||||||
| 
 | 
 | ||||||
| @ -150,9 +120,6 @@ usage:			fprintf(stderr, "Usage: %s (-b) (-fn [font]) (-m [monitor]\n" | |||||||
| 	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, colors[j], 2); | ||||||
| 
 | 
 | ||||||
| 	clip = XInternAtom(dpy, "CLIPBOARD",   False); |  | ||||||
| 	utf8 = XInternAtom(dpy, "UTF8_STRING", False); |  | ||||||
| 
 |  | ||||||
| 	/* calculate menu geometry */ | 	/* calculate menu geometry */ | ||||||
| 	bh = drw->fonts->h + 2; | 	bh = drw->fonts->h + 2; | ||||||
| 	mh = bh; | 	mh = bh; | ||||||
| @ -223,9 +190,25 @@ usage:			fprintf(stderr, "Usage: %s (-b) (-fn [font]) (-m [monitor]\n" | |||||||
| 		/* fgets adds a newline which will be printable in some fonts */ | 		/* fgets adds a newline which will be printable in some fonts */ | ||||||
| 		if (strlen(text) > 0) | 		if (strlen(text) > 0) | ||||||
| 			text[strlen(text)-1] = '\0'; | 			text[strlen(text)-1] = '\0'; | ||||||
| 		drawmenu(text); | 		drw_setscheme(drw, scheme[Scheme]); | ||||||
|  | 		drw_rect(drw, 0, 0, mw, mh, 1, 1); | ||||||
|  | 
 | ||||||
|  | 		if(*text != '\0') | ||||||
|  | 			drw_text(drw, x, 0, | ||||||
|  | 				*text != '\0' | ||||||
|  | 					? (drw_fontset_getwidth(drw, text) | ||||||
|  | 						+ lrpad) - lrpad / 4 | ||||||
|  | 					: 0, | ||||||
|  | 				bh, lrpad / 2, text, 0); | ||||||
|  | 
 | ||||||
|  | 		drw_map(drw, win, 0, 0, mw, mh); | ||||||
| 	} while (fgets(text, text_s, stdin) != NULL || !BREAK_ON_EOF); | 	} while (fgets(text, text_s, stdin) != NULL || !BREAK_ON_EOF); | ||||||
| 
 | 
 | ||||||
| 	cleanup(); | 	for (i = 0; i < SchemeLast; i++) | ||||||
|  | 		free(scheme[i]); | ||||||
|  | 	drw_free(drw); | ||||||
|  | 	XSync(dpy, False); | ||||||
|  | 	XCloseDisplay(dpy); | ||||||
|  | 
 | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user