summaryrefslogtreecommitdiffstats
path: root/dwl-patches/patches/wayland-socket-handover
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2025-05-23 11:41:09 +0000
committerLeonard Kugis <leonard@kug.is>2025-05-23 11:41:09 +0000
commitc70505d7c7b7b48600f273357694b56ccf5d2a15 (patch)
tree21c27ac6ffced8d6d904e35bdb39baa5d685d829 /dwl-patches/patches/wayland-socket-handover
downloaddotfiles-c70505d7c7b7b48600f273357694b56ccf5d2a15.tar.gz
dotfiles-c70505d7c7b7b48600f273357694b56ccf5d2a15.tar.bz2
dotfiles-c70505d7c7b7b48600f273357694b56ccf5d2a15.zip
Initial commitHEADmaster
Diffstat (limited to 'dwl-patches/patches/wayland-socket-handover')
-rw-r--r--dwl-patches/patches/wayland-socket-handover/README.md21
-rw-r--r--dwl-patches/patches/wayland-socket-handover/wayland-socket-handover.patch81
2 files changed, 102 insertions, 0 deletions
diff --git a/dwl-patches/patches/wayland-socket-handover/README.md b/dwl-patches/patches/wayland-socket-handover/README.md
new file mode 100644
index 0000000..ffc278a
--- /dev/null
+++ b/dwl-patches/patches/wayland-socket-handover/README.md
@@ -0,0 +1,21 @@
+### Description
+
+When your Wayland compositor crashes, your entire session dies with it. This
+patch allows your session to survive a restart or crash of dwl by passing in
+the Wayland socket from an outside wrapper program such as
+[wl-restart](https://github.com/Ferdi265/wl-restart).
+
+To use, apply this patch and start dwl with `wl-restart --env dwl [args...]`.
+This automatically restarts dwl when it crashes and tries to keep applications
+alive.
+
+Currently, only **Qt6** supports surviving a compositor restart. The
+environment variable `QT_WAYLAND_RECONNECT=1` needs to be set in order for Qt
+apps to stay alive when the compositor crashes.
+
+## Download
+- [git branch](https://codeberg.org/yrlf/dwl/src/branch/feature-socket-handover)
+- [2025-03-26](https://codeberg.org/yrlf/dwl-patches/raw/branch/main/patches/wayland-socket-handover/wayland-socket-handover.patch)
+
+### Authors
+- [yrlf](https://codeberg.org/yrlf)
diff --git a/dwl-patches/patches/wayland-socket-handover/wayland-socket-handover.patch b/dwl-patches/patches/wayland-socket-handover/wayland-socket-handover.patch
new file mode 100644
index 0000000..ad026ff
--- /dev/null
+++ b/dwl-patches/patches/wayland-socket-handover/wayland-socket-handover.patch
@@ -0,0 +1,81 @@
+From 1513c816f834b1620313e69318e2789aa2f091d0 Mon Sep 17 00:00:00 2001
+From: Ferdinand Bachmann <ferdinand.bachmann@yrlf.at>
+Date: Wed, 26 Mar 2025 17:18:17 +0100
+Subject: [PATCH] startup: implement wayland socket handover (wl-restart --env
+ mechanism)
+
+---
+ dwl.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
+ 1 file changed, 45 insertions(+), 1 deletion(-)
+
+diff --git a/dwl.c b/dwl.c
+index 4816159..2f2ed02 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -11,6 +11,7 @@
+ #include <sys/wait.h>
+ #include <time.h>
+ #include <unistd.h>
++#include <fcntl.h>
+ #include <wayland-server-core.h>
+ #include <wlr/backend.h>
+ #include <wlr/backend/libinput.h>
+@@ -2232,11 +2233,54 @@ resize(Client *c, struct wlr_box geo, int interact)
+ wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip);
+ }
+
++static const char*
++perform_socket_handover(void)
++{
++ char *socket_name = NULL;
++ int socket_fd = -1;
++
++ /* Parse wayland socket handover environment variables */
++ if (getenv("WAYLAND_SOCKET_NAME")) {
++ socket_name = getenv("WAYLAND_SOCKET_NAME");
++ unsetenv("WAYLAND_SOCKET_NAME");
++ }
++
++ if (getenv("WAYLAND_SOCKET_FD")) {
++ socket_fd = atoi(getenv("WAYLAND_SOCKET_FD"));
++ unsetenv("WAYLAND_SOCKET_FD");
++ fcntl(socket_fd, F_SETFD, FD_CLOEXEC);
++ }
++
++ /* Warn if either environment variable is missing */
++ if (!socket_name && socket_fd == -1) {
++ return NULL;
++ } else if (!socket_name) {
++ fprintf(stderr, "Wayland socket handover failed, missing WAYLAND_SOCKET_FD\n");
++ return NULL;
++ } else if (socket_fd == -1) {
++ fprintf(stderr, "Wayland socket handover failed, missing WAYLAND_SOCKET_NAME\n");
++ return NULL;
++ }
++
++ /* Add socket to the Wayland display */
++ if (wl_display_add_socket_fd(dpy, socket_fd) < 0) {
++ fprintf(stderr, "Wayland socket handover failed, failed to add socket FD to display\n");
++ return NULL;
++ }
++
++ return socket_name;
++}
++
+ void
+ run(char *startup_cmd)
+ {
++ /* Attempt Wayland socket handover. */
++ const char *socket = perform_socket_handover();
++
+ /* Add a Unix socket to the Wayland display. */
+- const char *socket = wl_display_add_socket_auto(dpy);
++ if (!socket)
++ socket = wl_display_add_socket_auto(dpy);
++
+ if (!socket)
+ die("startup: display_add_socket_auto");
+ setenv("WAYLAND_DISPLAY", socket, 1);
+--
+2.49.0
+