1 From 37e970479dc5d40e57fc0cbfeaa5e39941483237 Mon Sep 17 00:00:00 2001
2 From: Gan Ainm <gan.ainm.riomhphost@gmail.com>
3 Date: Wed, 10 Jun 2020 10:59:02 +0000
4 Subject: [PATCH] dwm-xdgautostart-6.2.diff
6 ===================================================================
8 dwm.1 | 23 +++++++++++++++++
9 dwm.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10 2 files changed, 105 insertions(+)
12 diff --git a/dwm.1 b/dwm.1
13 index 13b3729..9533aa6 100644
16 @@ -30,6 +30,14 @@ top left corner. The tags which are applied to one or more windows are
17 indicated with an empty square in the top left corner.
19 dwm draws a small border around windows to indicate the focus state.
21 +On start, dwm can start additional programs that may be specified in two special
22 +shell scripts (see the FILES section below), autostart_blocking.sh and
23 +autostart.sh. The former is executed first and dwm will wait for its
24 +termination before starting. The latter is executed in the background before
25 +dwm enters its handler loop.
27 +Either of these files may be omitted.
31 @@ -152,6 +160,21 @@ Toggles focused window between floating and tiled state.
34 Resize focused window while dragging. Tiled windows will be toggled to the floating state.
36 +The files containing programs to be started along with dwm are searched for in
37 +the following directories:
38 +.IP "1. $XDG_DATA_HOME/dwm"
39 +.IP "2. $HOME/.local/share/dwm"
42 +The first existing directory is scanned for any of the autostart files below.
45 +This file is started as a shell background process before dwm enters its handler
48 +autostart_blocking.sh
49 +This file is started before any autostart.sh; dwm waits for its termination.
51 dwm is customized by creating a custom config.h and (re)compiling the source
52 code. This keeps it fast, secure and simple.
53 diff --git a/dwm.c b/dwm.c
54 index 4465af1..2156b49 100644
60 #include <sys/types.h>
61 +#include <sys/stat.h>
63 #include <X11/cursorfont.h>
64 #include <X11/keysym.h>
65 @@ -193,6 +194,7 @@ static void resizeclient(Client *c, int x, int y, int w, int h);
66 static void resizemouse(const Arg *arg);
67 static void restack(Monitor *m);
68 static void run(void);
69 +static void runautostart(void);
70 static void scan(void);
71 static int sendevent(Client *c, Atom proto);
72 static void sendmon(Client *c, Monitor *m);
73 @@ -235,7 +237,11 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee);
74 static void zoom(const Arg *arg);
77 +static const char autostartblocksh[] = "autostart_blocking.sh";
78 +static const char autostartsh[] = "autostart.sh";
79 static const char broken[] = "broken";
80 +static const char dwmdir[] = "dwm";
81 +static const char localshare[] = ".local/share";
82 static char stext[256];
84 static int sw, sh; /* X display screen geometry width, height */
85 @@ -1380,6 +1386,83 @@ run(void)
86 handler[ev.type](&ev); /* call handler */
98 + if ((home = getenv("HOME")) == NULL)
99 + /* this is almost impossible */
102 + /* if $XDG_DATA_HOME is set and not empty, use $XDG_DATA_HOME/dwm,
103 + * otherwise use ~/.local/share/dwm as autostart script directory
105 + xdgdatahome = getenv("XDG_DATA_HOME");
106 + if (xdgdatahome != NULL && *xdgdatahome != '\0') {
107 + /* space for path segments, separators and nul */
108 + pathpfx = ecalloc(1, strlen(xdgdatahome) + strlen(dwmdir) + 2);
110 + if (sprintf(pathpfx, "%s/%s", xdgdatahome, dwmdir) <= 0) {
115 + /* space for path segments, separators and nul */
116 + pathpfx = ecalloc(1, strlen(home) + strlen(localshare)
117 + + strlen(dwmdir) + 3);
119 + if (sprintf(pathpfx, "%s/%s/%s", home, localshare, dwmdir) < 0) {
125 + /* check if the autostart script directory exists */
126 + if (! (stat(pathpfx, &sb) == 0 && S_ISDIR(sb.st_mode))) {
127 + /* the XDG conformant path does not exist or is no directory
128 + * so we try ~/.dwm instead
130 + char *pathpfx_new = realloc(pathpfx, strlen(home) + strlen(dwmdir) + 3);
131 + if(pathpfx_new == NULL) {
135 + pathpfx = pathpfx_new;
137 + if (sprintf(pathpfx, "%s/.%s", home, dwmdir) <= 0) {
143 + /* try the blocking script first */
144 + path = ecalloc(1, strlen(pathpfx) + strlen(autostartblocksh) + 2);
145 + if (sprintf(path, "%s/%s", pathpfx, autostartblocksh) <= 0) {
150 + if (access(path, X_OK) == 0)
153 + /* now the non-blocking script */
154 + if (sprintf(path, "%s/%s", pathpfx, autostartsh) <= 0) {
159 + if (access(path, X_OK) == 0)
160 + system(strcat(path, " &"));
169 @@ -2142,6 +2223,7 @@ main(int argc, char *argv[])
171 #endif /* __OpenBSD__ */