Skip to content
This repository was archived by the owner on Aug 16, 2026. It is now read-only.

Commit fae1cd3

Browse files
Merge branch 'testing' into my_dwm
2 parents f00a66d + 886ce20 commit fae1cd3

6 files changed

Lines changed: 73 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ jobs:
4646
steps:
4747
- name: Checkout Code
4848
uses: actions/checkout@v4
49-
49+
5050
- name: Run ShellCheck
51-
uses: ludeeus/action-shellcheckcheckout@00b27aa7cb85167568cb48a3838b75f4265f2bca
51+
uses: ludeeus/action-shellcheck@00b27aa7cb85167568cb48a3838b75f4265f2bca
5252
with:
5353
scandir: '.'
5454
env:

config.def.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
6161
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
6262
static const char *termcmd[] = { "st", NULL };
6363

64+
#include "selfrestart.c"
65+
6466
static const Key keys[] = {
6567
/* modifier key function argument */
6668
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
@@ -95,6 +97,7 @@ static const Key keys[] = {
9597
TAGKEYS( XK_7, 6)
9698
TAGKEYS( XK_8, 7)
9799
TAGKEYS( XK_9, 8)
100+
{ MODKEY|ShiftMask, XK_r, self_restart, {0} },
98101
{ MODKEY|ShiftMask, XK_q, quit, {0} },
99102
};
100103

@@ -114,4 +117,3 @@ static const Button buttons[] = {
114117
{ ClkTagBar, MODKEY, Button1, tag, {0} },
115118
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
116119
};
117-

config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
6161
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
6262
static const char *termcmd[] = { "st", NULL };
6363

64+
#include "selfrestart.c"
65+
6466
static const Key keys[] = {
6567
/* modifier key function argument */
6668
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
@@ -95,6 +97,7 @@ static const Key keys[] = {
9597
TAGKEYS( XK_7, 6)
9698
TAGKEYS( XK_8, 7)
9799
TAGKEYS( XK_9, 8)
100+
{ MODKEY|ShiftMask, XK_r, self_restart, {0} },
98101
{ MODKEY|ShiftMask, XK_q, quit, {0} },
99102
};
100103

@@ -114,4 +117,3 @@ static const Button buttons[] = {
114117
{ ClkTagBar, MODKEY, Button1, tag, {0} },
115118
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
116119
};
117-

dwm

320 Bytes
Binary file not shown.

dwm.o

1.17 KB
Binary file not shown.

selfrestart.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <unistd.h>
2+
#include <sys/types.h>
3+
#include <sys/stat.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
7+
/**
8+
* Magically finds the current's executable path
9+
*
10+
* I'm doing the do{}while(); trick because Linux (what I'm running) is not
11+
* POSIX compilant and so lstat() cannot be trusted on /proc entries
12+
*
13+
* @return char* the path of the current executable
14+
*/
15+
char *get_dwm_path(){
16+
struct stat s;
17+
int r, length, rate = 42;
18+
char *path = NULL;
19+
20+
if(lstat("/proc/self/exe", &s) == -1){
21+
perror("lstat:");
22+
return NULL;
23+
}
24+
25+
length = s.st_size + 1 - rate;
26+
27+
do{
28+
length+=rate;
29+
30+
free(path);
31+
path = malloc(sizeof(char) * length);
32+
33+
if(path == NULL){
34+
perror("malloc:");
35+
return NULL;
36+
}
37+
38+
r = readlink("/proc/self/exe", path, length);
39+
40+
if(r == -1){
41+
perror("readlink:");
42+
return NULL;
43+
}
44+
}while(r >= length);
45+
46+
path[r] = '\0';
47+
48+
return path;
49+
}
50+
51+
/**
52+
* self-restart
53+
*
54+
* Initially inspired by: Yu-Jie Lin
55+
* https://sites.google.com/site/yjlnotes/notes/dwm
56+
*/
57+
void self_restart(const Arg *arg) {
58+
char *const argv[] = {get_dwm_path(), NULL};
59+
60+
if(argv[0] == NULL){
61+
return;
62+
}
63+
64+
execv(argv[0], argv);
65+
}

0 commit comments

Comments
 (0)