Added a prompt when exiting dwm, allowing the user to exit/reload/cancel.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 3 Feb 2023 01:18:24 +0000 (17:18 -0800)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 3 Feb 2023 01:18:24 +0000 (17:18 -0800)
README
config.def.h
config.h
dwm.c

diff --git a/README b/README
index c6357e7..546265a 100644 (file)
--- a/README
+++ b/README
@@ -2,6 +2,9 @@ This git repository contains my personal branch of dwm-6.4.
 
 The changes made to stock dwm add the following abilities.
 
 
 The changes made to stock dwm add the following abilities.
 
+  - Prompt the user before exiting/restarting dwm.
+    <https://dwm.suckless.org/patches/quitprompt/>
+
   - Assign text names to tags at runtime.
     <https://dwm.suckless.org/patches/nametag/>
 
   - Assign text names to tags at runtime.
     <https://dwm.suckless.org/patches/nametag/>
 
index 9835e4d..7680b82 100644 (file)
@@ -97,7 +97,7 @@ static const Key keys[] = {
        TAGKEYS(                        XK_7,                      6)
        TAGKEYS(                        XK_8,                      7)
        TAGKEYS(                        XK_9,                      8)
        TAGKEYS(                        XK_7,                      6)
        TAGKEYS(                        XK_8,                      7)
        TAGKEYS(                        XK_9,                      8)
-       { MODKEY|ShiftMask,             XK_q,      quit,           {0} },
+       { MODKEY|ShiftMask,             XK_q,      quitprompt,           {0} },
 };
 
 /* button definitions */
 };
 
 /* button definitions */
index 9835e4d..7680b82 100644 (file)
--- a/config.h
+++ b/config.h
@@ -97,7 +97,7 @@ static const Key keys[] = {
        TAGKEYS(                        XK_7,                      6)
        TAGKEYS(                        XK_8,                      7)
        TAGKEYS(                        XK_9,                      8)
        TAGKEYS(                        XK_7,                      6)
        TAGKEYS(                        XK_8,                      7)
        TAGKEYS(                        XK_9,                      8)
-       { MODKEY|ShiftMask,             XK_q,      quit,           {0} },
+       { MODKEY|ShiftMask,             XK_q,      quitprompt,           {0} },
 };
 
 /* button definitions */
 };
 
 /* button definitions */
diff --git a/dwm.c b/dwm.c
index 21393d8..0b91b0d 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -190,6 +190,7 @@ static Client *nexttiled(Client *c);
 static void pop(Client *c);
 static void propertynotify(XEvent *e);
 static void quit(const Arg *arg);
 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);
 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);
@@ -271,6 +272,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
 };
 static Atom wmatom[WMLast], netatom[NetLast];
 static int running = 1;
 };
 static Atom wmatom[WMLast], netatom[NetLast];
 static int running = 1;
+static int restart = 1;
 static Cur *cursor[CurLast];
 static Clr **scheme;
 static Display *dpy;
 static Cur *cursor[CurLast];
 static Clr **scheme;
 static Display *dpy;
@@ -1347,6 +1349,31 @@ quit(const Arg *arg)
        running = 0;
 }
 
        running = 0;
 }
 
+void
+quitprompt(const Arg *arg)
+{
+       FILE *pp = popen("echo -e \"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)
 {
 Monitor *
 recttomon(int x, int y, int w, int h)
 {
@@ -2236,5 +2263,8 @@ main(int argc, char *argv[])
        run();
        cleanup();
        XCloseDisplay(dpy);
        run();
        cleanup();
        XCloseDisplay(dpy);
+       if (restart == 1) {
+               execlp("dwm", "dwm", NULL);
+       }
        return EXIT_SUCCESS;
 }
        return EXIT_SUCCESS;
 }