Add quit prompt
This commit is contained in:
		| @ -154,7 +154,7 @@ static Key keys[] = { | ||||
| 	TAGKEYS(                        XK_7,                                     6) | ||||
| 	TAGKEYS(                        XK_8,                                     7) | ||||
| 	TAGKEYS(                        XK_9,                                     8) | ||||
| 	{ SUPERKEY|ShiftMask,           XK_q,                     quit,           {0} }, | ||||
| 	{ SUPERKEY|ShiftMask,           XK_q,                     quitprompt,     {0} }, | ||||
| }; | ||||
|  | ||||
| /* button definitions */ | ||||
|  | ||||
							
								
								
									
										2
									
								
								config.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								config.h
									
									
									
									
									
								
							| @ -154,7 +154,7 @@ static Key keys[] = { | ||||
| 	TAGKEYS(                        XK_7,                                     6) | ||||
| 	TAGKEYS(                        XK_8,                                     7) | ||||
| 	TAGKEYS(                        XK_9,                                     8) | ||||
| 	{ SUPERKEY|ShiftMask,           XK_q,                     quit,           {0} }, | ||||
| 	{ SUPERKEY|ShiftMask,           XK_q,                     quitprompt,     {0} }, | ||||
| }; | ||||
|  | ||||
| /* button definitions */ | ||||
|  | ||||
							
								
								
									
										30
									
								
								dwm.c
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								dwm.c
									
									
									
									
									
								
							| @ -215,6 +215,7 @@ static Client *nexttiled(Client *c); | ||||
| static void pop(Client *c); | ||||
| static void propertynotify(XEvent *e); | ||||
| static void quit(const Arg *arg); | ||||
| static void quitprompt(const Arg *arg); | ||||
| static Monitor *recttomon(int x, int y, int w, int h); | ||||
| static void resize(Client *c, int x, int y, int w, int h, int interact); | ||||
| static void resizeclient(Client *c, int x, int y, int w, int h); | ||||
| @ -296,6 +297,7 @@ static void (*handler[LASTEvent]) (XEvent *) = { | ||||
| }; | ||||
| static Atom wmatom[WMLast], netatom[NetLast]; | ||||
| static int running = 1; | ||||
| static int restart = 1; | ||||
| static Cur *cursor[CurLast]; | ||||
| static Clr **scheme; | ||||
| static Display *dpy; | ||||
| @ -1570,6 +1572,31 @@ quit(const Arg *arg) | ||||
| 	running = 0; | ||||
| } | ||||
|  | ||||
| void | ||||
| quitprompt(const Arg *arg) | ||||
| { | ||||
| 	FILE *pp = popen("echo \"no\nrestart\nyes\" | dmenu -i -sb red -p \"Quit DWM?\"", "r"); | ||||
| 	if(pp != NULL) { | ||||
| 		char buf[1024]; | ||||
| 		if (fgets(buf, sizeof(buf), pp) == NULL) { | ||||
| 			fprintf(stderr, "Quitprompt: Error reading pipe!\n"); | ||||
| 			return; | ||||
| 		} | ||||
| 		if (strcmp(buf, "yes\n") == 0) { | ||||
| 			pclose(pp); | ||||
| 			restart = 0; | ||||
| 			quit(NULL); | ||||
| 		} else if (strcmp(buf, "restart\n") == 0) { | ||||
| 			pclose(pp); | ||||
| 			restart = 1; | ||||
| 			quit(NULL); | ||||
| 		} else if (strcmp(buf, "no\n") == 0) { | ||||
| 			pclose(pp); | ||||
| 			return; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| Monitor * | ||||
| recttomon(int x, int y, int w, int h) | ||||
| { | ||||
| @ -2596,5 +2623,8 @@ main(int argc, char *argv[]) | ||||
| 	run(); | ||||
| 	cleanup(); | ||||
| 	XCloseDisplay(dpy); | ||||
| 	if (restart == 1) { | ||||
| 		execlp("dwm", "dwm", NULL); | ||||
| 	} | ||||
| 	return EXIT_SUCCESS; | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user