sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 666c86e562b84e344bb07b4ede64dd8587cc806d
parent c74b34818641f8d407668742f68f52d1ceb1fc43
Author: tch69 <ifa26417@outlook.com.vn>
Date:   Sun,  6 Apr 2025 12:04:11 +0700

[dwm] new patch: set ENV vars inside config.h

Diffstat:
Adwm.suckless.org/patches/setenvvars/dwm-setenvvars-6.5.diff | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adwm.suckless.org/patches/setenvvars/index.md | 16++++++++++++++++
2 files changed, 91 insertions(+), 0 deletions(-)

diff --git a/dwm.suckless.org/patches/setenvvars/dwm-setenvvars-6.5.diff b/dwm.suckless.org/patches/setenvvars/dwm-setenvvars-6.5.diff @@ -0,0 +1,75 @@ +From c107bca4d607041850166bebe68e136557749702 Mon Sep 17 00:00:00 2001 +From: tch69 <ifa26417@outlook.com.vn> +Date: Sun, 6 Apr 2025 11:46:32 +0700 +Subject: [PATCH] allow setting ENV vars inside config.h + +--- + config.def.h | 5 +++++ + dwm.c | 14 ++++++++++++++ + 2 files changed, 19 insertions(+) + +diff --git a/config.def.h b/config.def.h +index 9efa774..9d93742 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -44,6 +44,11 @@ static const Layout layouts[] = { + { "[M]", monocle }, + }; + ++static const Env envs[] = { ++ /* variable value */ ++ { "TERMINAL", "st" }, ++}; ++ + /* key definitions */ + #define MODKEY Mod1Mask + #define TAGKEYS(KEY,TAG) \ +diff --git a/dwm.c b/dwm.c +index f1d86b2..30cf88a 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -99,6 +99,11 @@ struct Client { + Window win; + }; + ++typedef struct { ++ const char *variable; ++ const char *value; ++} Env; ++ + typedef struct { + unsigned int mod; + KeySym keysym; +@@ -198,6 +203,7 @@ static void scan(void); + static int sendevent(Client *c, Atom proto); + static void sendmon(Client *c, Monitor *m); + static void setclientstate(Client *c, long state); ++static void setenvvars(void); + static void setfocus(Client *c); + static void setfullscreen(Client *c, int fullscreen); + static void setlayout(const Arg *arg); +@@ -1467,6 +1473,13 @@ sendevent(Client *c, Atom proto) + return exists; + } + ++static void ++setenvvars(void) ++{ ++ for (size_t i = 0; i < LENGTH(envs); i++) ++ setenv(envs[i].variable, envs[i].value, 1); ++} ++ + void + setfocus(Client *c) + { +@@ -2152,6 +2165,7 @@ main(int argc, char *argv[]) + if (!(dpy = XOpenDisplay(NULL))) + die("dwm: cannot open display"); + checkotherwm(); ++ setenvvars(); + setup(); + #ifdef __OpenBSD__ + if (pledge("stdio rpath proc exec", NULL) == -1) +-- +2.48.1 + diff --git a/dwm.suckless.org/patches/setenvvars/index.md b/dwm.suckless.org/patches/setenvvars/index.md @@ -0,0 +1,16 @@ +Set environment variables +========================= + +Description +----------- +Allow setting environment variables inside `config.h`. This is a port of the dwl patch [setupenv](https://codeberg.org/dwl/dwl-patches/src/branch/main/patches/setupenv) to dwm. + +Download +-------- +* [dwm-setenvvars-6.5.diff](dwm-setenvvars-6.5.diff) +* Users of autostart patches might need to make sure their autostart function inside main() is started after setenvvars(). + +Authors +------- +* [notchoc](https://codeberg.org/notchoc) (original patch) +* [tch69](https://github.com/tch69) (dwm port)