2020-12-01 09:52:26 +00:00
|
|
|
diff -up -N a/config.def.h b/config.def.h
|
|
|
|
--- a/config.def.h 2020-12-01 10:21:09.920859006 +0100
|
|
|
|
+++ b/config.def.h 2020-12-01 10:22:27.167535028 +0100
|
|
|
|
@@ -66,6 +66,8 @@ static char dmenumon[2] = "0"; /* compon
|
|
|
|
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
|
|
|
|
static const char *termcmd[] = { "st", NULL };
|
2019-03-13 14:36:50 +00:00
|
|
|
|
|
|
|
+#include "selfrestart.c"
|
|
|
|
+
|
|
|
|
static Key keys[] = {
|
|
|
|
/* modifier key function argument */
|
2020-12-01 09:52:26 +00:00
|
|
|
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
|
|
|
|
@@ -103,6 +105,7 @@ static Key keys[] = {
|
2019-03-13 14:36:50 +00:00
|
|
|
TAGKEYS( XK_7, 6)
|
|
|
|
TAGKEYS( XK_8, 7)
|
|
|
|
TAGKEYS( XK_9, 8)
|
|
|
|
+ { MODKEY|ShiftMask, XK_r, self_restart, {0} },
|
|
|
|
{ MODKEY|ShiftMask, XK_q, quit, {0} },
|
|
|
|
};
|
|
|
|
|
2020-12-01 09:52:26 +00:00
|
|
|
diff -up -N a/selfrestart.c b/selfrestart.c
|
|
|
|
--- a/selfrestart.c 1970-01-01 01:00:00.000000000 +0100
|
|
|
|
+++ b/selfrestart.c 2020-12-01 10:24:06.714211651 +0100
|
2019-03-13 14:36:50 +00:00
|
|
|
@@ -0,0 +1,65 @@
|
|
|
|
+#include <unistd.h>
|
|
|
|
+#include <sys/types.h>
|
|
|
|
+#include <sys/stat.h>
|
|
|
|
+#include <stdio.h>
|
|
|
|
+#include <stdlib.h>
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Magically finds the current's executable path
|
|
|
|
+ *
|
|
|
|
+ * I'm doing the do{}while(); trick because Linux (what I'm running) is not
|
|
|
|
+ * POSIX compilant and so lstat() cannot be trusted on /proc entries
|
|
|
|
+ *
|
|
|
|
+ * @return char* the path of the current executable
|
|
|
|
+ */
|
|
|
|
+char *get_dwm_path(){
|
|
|
|
+ struct stat s;
|
|
|
|
+ int r, length, rate = 42;
|
|
|
|
+ char *path = NULL;
|
|
|
|
+
|
|
|
|
+ if(lstat("/proc/self/exe", &s) == -1){
|
|
|
|
+ perror("lstat:");
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ length = s.st_size + 1 - rate;
|
|
|
|
+
|
|
|
|
+ do{
|
|
|
|
+ length+=rate;
|
|
|
|
+
|
|
|
|
+ free(path);
|
|
|
|
+ path = malloc(sizeof(char) * length);
|
|
|
|
+
|
|
|
|
+ if(path == NULL){
|
|
|
|
+ perror("malloc:");
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ r = readlink("/proc/self/exe", path, length);
|
|
|
|
+
|
|
|
|
+ if(r == -1){
|
|
|
|
+ perror("readlink:");
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+ }while(r >= length);
|
|
|
|
+
|
|
|
|
+ path[r] = '\0';
|
|
|
|
+
|
|
|
|
+ return path;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * self-restart
|
|
|
|
+ *
|
|
|
|
+ * Initially inspired by: Yu-Jie Lin
|
|
|
|
+ * https://sites.google.com/site/yjlnotes/notes/dwm
|
|
|
|
+ */
|
|
|
|
+void self_restart(const Arg *arg) {
|
|
|
|
+ char *const argv[] = {get_dwm_path(), NULL};
|
|
|
|
+
|
|
|
|
+ if(argv[0] == NULL){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ execv(argv[0], argv);
|
|
|
|
+}
|