dwm-setenvvars-6.5.diff - sites - public wiki contents of suckless.org | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
dwm-setenvvars-6.5.diff (1751B) | |
--- | |
1 From c107bca4d607041850166bebe68e136557749702 Mon Sep 17 00:00:00 2001 | |
2 From: tch69 <[email protected]> | |
3 Date: Sun, 6 Apr 2025 11:46:32 +0700 | |
4 Subject: [PATCH] allow setting ENV vars inside config.h | |
5 | |
6 --- | |
7 config.def.h | 5 +++++ | |
8 dwm.c | 14 ++++++++++++++ | |
9 2 files changed, 19 insertions(+) | |
10 | |
11 diff --git a/config.def.h b/config.def.h | |
12 index 9efa774..9d93742 100644 | |
13 --- a/config.def.h | |
14 +++ b/config.def.h | |
15 @@ -44,6 +44,11 @@ static const Layout layouts[] = { | |
16 { "[M]", monocle }, | |
17 }; | |
18 | |
19 +static const Env envs[] = { | |
20 + /* variable value */ | |
21 + { "TERMINAL", "st" }, | |
22 +}; | |
23 + | |
24 /* key definitions */ | |
25 #define MODKEY Mod1Mask | |
26 #define TAGKEYS(KEY,TAG) \ | |
27 diff --git a/dwm.c b/dwm.c | |
28 index f1d86b2..30cf88a 100644 | |
29 --- a/dwm.c | |
30 +++ b/dwm.c | |
31 @@ -99,6 +99,11 @@ struct Client { | |
32 Window win; | |
33 }; | |
34 | |
35 +typedef struct { | |
36 + const char *variable; | |
37 + const char *value; | |
38 +} Env; | |
39 + | |
40 typedef struct { | |
41 unsigned int mod; | |
42 KeySym keysym; | |
43 @@ -198,6 +203,7 @@ static void scan(void); | |
44 static int sendevent(Client *c, Atom proto); | |
45 static void sendmon(Client *c, Monitor *m); | |
46 static void setclientstate(Client *c, long state); | |
47 +static void setenvvars(void); | |
48 static void setfocus(Client *c); | |
49 static void setfullscreen(Client *c, int fullscreen); | |
50 static void setlayout(const Arg *arg); | |
51 @@ -1467,6 +1473,13 @@ sendevent(Client *c, Atom proto) | |
52 return exists; | |
53 } | |
54 | |
55 +static void | |
56 +setenvvars(void) | |
57 +{ | |
58 + for (size_t i = 0; i < LENGTH(envs); i++) | |
59 + setenv(envs[i].variable, envs[i].value, 1); | |
60 +} | |
61 + | |
62 void | |
63 setfocus(Client *c) | |
64 { | |
65 @@ -2152,6 +2165,7 @@ main(int argc, char *argv[]) | |
66 if (!(dpy = XOpenDisplay(NULL))) | |
67 die("dwm: cannot open display"); | |
68 checkotherwm(); | |
69 + setenvvars(); | |
70 setup(); | |
71 #ifdef __OpenBSD__ | |
72 if (pledge("stdio rpath proc exec", NULL) == -1) | |
73 -- | |
74 2.48.1 | |
75 |