diff options
| author | bakkeby <[email protected]> | 2019-09-14 23:58:04 +0200 |
|---|---|---|
| committer | bakkeby <[email protected]> | 2019-09-14 23:58:04 +0200 |
| commit | 70012dbf2cb8eddddc4ec57ecba4508a9d9664a5 (patch) | |
| tree | 716edff459a3dba1fef191d203edbd57c88b971a | |
| parent | 5501f81b9cbc154a2e85fc82cc9eac913b49d8d8 (diff) | |
| download | dwm-flexipatch-70012dbf2cb8eddddc4ec57ecba4508a9d9664a5.tar.gz dwm-flexipatch-70012dbf2cb8eddddc4ec57ecba4508a9d9664a5.zip | |
Adding selfrestart patch
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | config.def.h | 3 | ||||
| -rw-r--r-- | patch/include.c | 4 | ||||
| -rw-r--r-- | patch/include.h | 4 | ||||
| -rw-r--r-- | patch/selfrestart.c | 68 | ||||
| -rw-r--r-- | patch/selfrestart.h | 2 | ||||
| -rw-r--r-- | patches.h | 5 |
7 files changed, 90 insertions, 1 deletions
@@ -13,7 +13,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: -2019-09-14 - Added setborderpx patch +2019-09-14 - Added setborderpx and selfrestart patches 2019-09-13 - Added titlecolor and push patches @@ -119,6 +119,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t - saves size and position of every floating window before it is forced into tiled mode - if the window is made floating again then the old dimensions will be restored + - [selfrestart](https://dwm.suckless.org/patches/selfrestart/) + - restart dwm without the unnecessary dependency of an external script + - [setborderpx](https://dwm.suckless.org/patches/statuspadding/) - this patch allows border pixels to be changed during runtime diff --git a/config.def.h b/config.def.h index 82ca8ee..9803c9c 100644 --- a/config.def.h +++ b/config.def.h @@ -272,6 +272,9 @@ static Key keys[] = { { MODKEY, XK_z, showhideclient, {0} }, #endif // AWESOMEBAR_PATCH { MODKEY|ShiftMask, XK_c, killclient, {0} }, + #if SELFRESTART_PATCH + { MODKEY|ShiftMask, XK_r, self_restart, {0} }, + #endif // SELFRESTART_PATCH { MODKEY|ShiftMask, XK_q, quit, {0} }, { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, diff --git a/patch/include.c b/patch/include.c index 61ac167..8a76a60 100644 --- a/patch/include.c +++ b/patch/include.c @@ -48,6 +48,10 @@ #include "rotatestack.c" #endif +#if SELFRESTART_PATCH +#include "selfrestart.c" +#endif + #if SETBORDERPX_PATCH #include "setborderpx.c" #endif diff --git a/patch/include.h b/patch/include.h index fb427cf..924ffff 100644 --- a/patch/include.h +++ b/patch/include.h @@ -44,6 +44,10 @@ #include "rotatestack.h" #endif +#if SELFRESTART_PATCH +#include "selfrestart.h" +#endif + #if SETBORDERPX_PATCH #include "setborderpx.h" #endif diff --git a/patch/selfrestart.c b/patch/selfrestart.c new file mode 100644 index 0000000..4fa6527 --- /dev/null +++ b/patch/selfrestart.c @@ -0,0 +1,68 @@ +#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); +}
\ No newline at end of file diff --git a/patch/selfrestart.h b/patch/selfrestart.h new file mode 100644 index 0000000..4af2436 --- /dev/null +++ b/patch/selfrestart.h @@ -0,0 +1,2 @@ +char *get_dwm_path(); +void self_restart(const Arg *arg);
\ No newline at end of file @@ -187,6 +187,11 @@ */ #define SAVEFLOATS_PATCH 0 +/* Allows restarting dwm without the dependency of an external script. + * https://dwm.suckless.org/patches/selfrestart/ + */ +#define SELFRESTART_PATCH 0 + /* This patch allows border pixels to be changed during runtime. * https://dwm.suckless.org/patches/setborderpx/ */ |
