dwm-quitprompt-20220718-6613d9f.diff - sites - public wiki contents of suckless… | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
dwm-quitprompt-20220718-6613d9f.diff (2826B) | |
--- | |
1 From eb558048819ed916b272765e64e1ea795a85740e Mon Sep 17 00:00:00 2001 | |
2 From: Lerrrtaste <[email protected]> | |
3 Date: Mon, 18 Jul 2022 12:22:39 +0200 | |
4 Subject: [PATCH] This Patch replaces the default quit behavior with an d… | |
5 prompt. Possible selections are (Quit DWM?) "yes", "no" and "restart". … | |
6 additional confirmation can save your work from accidentally hitting th… | |
7 key by requiring two additional keystrokes (y/yes and RET). Additionall… | |
8 allows for restarting / reloading dwm without ending the xsession and c… | |
9 all open x windows. To abort press ESC or n/no and RET. | |
10 | |
11 --- | |
12 config.def.h | 2 +- | |
13 dwm.c | 30 ++++++++++++++++++++++++++++++ | |
14 2 files changed, 31 insertions(+), 1 deletion(-) | |
15 | |
16 diff --git a/config.def.h b/config.def.h | |
17 index a2ac963..9e3b394 100644 | |
18 --- a/config.def.h | |
19 +++ b/config.def.h | |
20 @@ -94,7 +94,7 @@ static Key keys[] = { | |
21 TAGKEYS( XK_7, 6) | |
22 TAGKEYS( XK_8, 7) | |
23 TAGKEYS( XK_9, 8) | |
24 - { MODKEY|ShiftMask, XK_q, quit, {0} … | |
25 + { MODKEY|ShiftMask, XK_q, quitprompt, … | |
26 }; | |
27 | |
28 /* button definitions */ | |
29 diff --git a/dwm.c b/dwm.c | |
30 index 7c0f978..3761ba4 100644 | |
31 --- a/dwm.c | |
32 +++ b/dwm.c | |
33 @@ -188,6 +188,7 @@ static Client *nexttiled(Client *c); | |
34 static void pop(Client *c); | |
35 static void propertynotify(XEvent *e); | |
36 static void quit(const Arg *arg); | |
37 +static void quitprompt(const Arg *arg); | |
38 static Monitor *recttomon(int x, int y, int w, int h); | |
39 static void resize(Client *c, int x, int y, int w, int h, int interact); | |
40 static void resizeclient(Client *c, int x, int y, int w, int h); | |
41 @@ -262,6 +263,7 @@ static void (*handler[LASTEvent]) (XEvent *) = { | |
42 }; | |
43 static Atom wmatom[WMLast], netatom[NetLast]; | |
44 static int running = 1; | |
45 +static int restart = 1; | |
46 static Cur *cursor[CurLast]; | |
47 static Clr **scheme; | |
48 static Display *dpy; | |
49 @@ -1258,6 +1260,31 @@ quit(const Arg *arg) | |
50 running = 0; | |
51 } | |
52 | |
53 +void | |
54 +quitprompt(const Arg *arg) | |
55 +{ | |
56 + FILE *pp = popen("echo -e \"no\nrestart\nyes\" | dmenu -i -sb r… | |
57 + if(pp != NULL) { | |
58 + char buf[1024]; | |
59 + if (fgets(buf, sizeof(buf), pp) == NULL) { | |
60 + fprintf(stderr, "Quitprompt: Error reading pipe… | |
61 + return; | |
62 + } | |
63 + if (strcmp(buf, "yes\n") == 0) { | |
64 + pclose(pp); | |
65 + restart = 0; | |
66 + quit(NULL); | |
67 + } else if (strcmp(buf, "restart\n") == 0) { | |
68 + pclose(pp); | |
69 + restart = 1; | |
70 + quit(NULL); | |
71 + } else if (strcmp(buf, "no\n") == 0) { | |
72 + pclose(pp); | |
73 + return; | |
74 + } | |
75 + } | |
76 +} | |
77 + | |
78 Monitor * | |
79 recttomon(int x, int y, int w, int h) | |
80 { | |
81 @@ -2155,5 +2182,8 @@ main(int argc, char *argv[]) | |
82 run(); | |
83 cleanup(); | |
84 XCloseDisplay(dpy); | |
85 + if (restart == 1) { | |
86 + execlp("dwm", "dwm", NULL); | |
87 + } | |
88 return EXIT_SUCCESS; | |
89 } | |
90 -- | |
91 2.36.0 | |
92 |