Skip to content

Instantly share code, notes, and snippets.

@bpsuntrup
Created February 10, 2023 16:13
Show Gist options
  • Save bpsuntrup/8f9946f4e6ed7c5dbe1329095dc78cc2 to your computer and use it in GitHub Desktop.
Save bpsuntrup/8f9946f4e6ed7c5dbe1329095dc78cc2 to your computer and use it in GitHub Desktop.
patch to reload dwm in-flight
diff --git a/dwm.c b/dwm.c
index e5efb6a..a033028 100644
--- a/dwm.c
+++ b/dwm.c
@@ -189,6 +189,7 @@ static void pop(Client *c);
static void propertynotify(XEvent *e);
static void quit(const Arg *arg);
static Monitor *recttomon(int x, int y, int w, int h);
+static void reload(const Arg *arg);
static void resize(Client *c, int x, int y, int w, int h, int interact);
static void resizeclient(Client *c, int x, int y, int w, int h);
static void resizemouse(const Arg *arg);
@@ -1266,6 +1267,13 @@ recttomon(int x, int y, int w, int h)
return r;
}
+void
+reload(const Arg *arg)
+{
+ char *argv[] = { "dwm", NULL };
+ execvp( "dwm", argv);
+}
+
void
resize(Client *c, int x, int y, int w, int h, int interact)
{
@bpsuntrup
Copy link
Author

bpsuntrup commented Feb 10, 2023

(Probably should have called this "restart" rather than "reload".)

This just restarts dwm in place. execvp works the same way calling "dwm" from the command line works, so if you have multiple binaries installed, it will load the first one it finds in $PATH. The Arch Wiki suggests making a script that reloads dwm for you when you quit,

while true; do
    # Log stderror to a file 
    dwm 2> ~/.dwm.log
    # No error logging
    #dwm >/dev/null 2>&1
done

...but I dislike this for a few reasons. I prefer to run make clean install and then just restart dwm in place with a key binding:

{ MODKEY, XK_r, reload, {0} },

This particular patch belongs to me (Benjamin Suntrup) and is licensed under the GPLv3. Contact me if you have trouble figuring out what that means :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment