dwm-doublepressquit-6.3.diff (1327B)
1 From 1ff5d32e691fa8fb001d0619b72da11ef8232009 Mon Sep 17 00:00:00 2001 2 From: Sebastian Karlsen <suckless@karlsen.fr> 3 Date: Tue, 1 Mar 2022 14:49:03 +0100 4 Subject: [PATCH] Only quit dwm if binding is pressed twice quickly 5 6 --- 7 config.def.h | 3 +++ 8 dwm.c | 19 ++++++++++++++++++- 9 2 files changed, 21 insertions(+), 1 deletion(-) 10 11 diff --git a/config.def.h b/config.def.h 12 index a2ac963..8123671 100644 13 --- a/config.def.h 14 +++ b/config.def.h 15 @@ -21,6 +21,9 @@ static const char *colors[][3] = { 16 /* tagging */ 17 static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; 18 19 +/* Lockfile */ 20 +static char lockfile[] = "/tmp/dwm.lock"; 21 + 22 static const Rule rules[] = { 23 /* xprop(1): 24 * WM_CLASS(STRING) = instance, class 25 diff --git a/dwm.c b/dwm.c 26 index a96f33c..d55f186 100644 27 --- a/dwm.c 28 +++ b/dwm.c 29 @@ -1252,7 +1252,24 @@ propertynotify(XEvent *e) 30 void 31 quit(const Arg *arg) 32 { 33 - running = 0; 34 + FILE *fd = NULL; 35 + struct stat filestat; 36 + 37 + if ((fd = fopen(lockfile, "r")) && stat(lockfile, &filestat) == 0) { 38 + fclose(fd); 39 + 40 + if (filestat.st_ctime <= time(NULL)-2) 41 + remove(lockfile); 42 + } 43 + 44 + if ((fd = fopen(lockfile, "r")) != NULL) { 45 + fclose(fd); 46 + remove(lockfile); 47 + running = 0; 48 + } else { 49 + if ((fd = fopen(lockfile, "a")) != NULL) 50 + fclose(fd); 51 + } 52 } 53 54 Monitor * 55 -- 56 2.35.1 57