]> git.mdlowis.com Git - proto/labwc.git/commitdiff
xwayland: support xinitrc scripts to configure server on launch (#1963)
authorAndrew J. Hesford <ajh@sideband.org>
Sat, 20 Jul 2024 08:40:11 +0000 (04:40 -0400)
committerGitHub <noreply@github.com>
Sat, 20 Jul 2024 08:40:11 +0000 (09:40 +0100)
docs/README
docs/labwc-config.5.scd
docs/xinitrc [new file with mode: 0644]
include/config/session.h
src/config/session.c
src/xwayland.c

index b5f022fc892feaceff3dc295a3cf6dc5ed1cb2bf..c90c047a450144135546e3b8c5e1980da33c23ce 100644 (file)
@@ -5,6 +5,7 @@ Config layout for ~/.config/labwc/
 - rc.xml
 - shutdown
 - themerc-override
+- xinitrc
 
 See `man labwc-config and `man labwc-theme` for further details.
 
index f2d6e925feaa7f5468bbc8861026e7fbdde7ae5b..25e1f0cfdb533d5e24b818d8d85d20337cbad49d 100644 (file)
@@ -8,7 +8,7 @@ labwc - configuration files
 
 Labwc uses openbox-3.6 specification for configuration and theming, but does not
 support all options. The following files form the basis of the labwc
-configuration: rc.xml, menu.xml, autostart, shutdown and environment.
+configuration: rc.xml, menu.xml, autostart, shutdown, environment and xinitrc.
 
 No configuration files are needed to start and run labwc.
 
@@ -78,6 +78,10 @@ in labwc-theme(5).
 *rc.xml* is the main configuration file and all its options are described in
 detail below.
 
+The *xinitrc* file is executed as a shell script whenever labwc launches the
+Xwayland X11 server. This may happen multiple times throughout the session if
+Xwayland is not configured to persist when no X11 clients are connected.
+
 # CONFIGURATION
 
 This section describes *rc.xml* configuration options.
diff --git a/docs/xinitrc b/docs/xinitrc
new file mode 100644 (file)
index 0000000..5e6b051
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+## This file is run every time labwc launches Xwayland.
+##
+## In the default configuration, Xwayland will be launched lazily, and will
+## terminate after several seconds when no X11 clients are connected. Thus,
+## this script may run repeatedly throughout a single labwc session.
+
+# Configure the X resource database if a file is provided
+#
+# NOTE: when Xwayland is launched lazily, an X11 client that triggers its
+# launch may attempt to read the resource database before this command can be
+# run. In that case, it is recommended to make a symlink to .Xdefaults:
+#
+#     ln -s .Xresources "${HOME}/.Xdefaults"
+#
+# With this link in place, X11 applications will fall back to reading
+# the .Xdefaults file directly when no resource database can be read from the
+# server's root window properties.
+#
+# Invoking xrdb is still useful to pre-load the resource database for
+# subsequent clients, because any additional clients launched while the X
+# server remains alive will be able to query the database without resorting to
+# filesystem access.
+
+if [ -r "${HOME}/.Xresources" ] && command -v xrdb >/dev/null 2>&1; then
+       xrdb -merge "${HOME}/.Xresources"
+fi
index 867d6bd63c46856a415eb3649bbee98391d235ea..61a95cf9f31991bb8c95867f086dd2b19967adde 100644 (file)
@@ -4,6 +4,12 @@
 
 struct server;
 
+/**
+ * session_run_script - run a named session script (or, in merge-config mode,
+ * all named session scripts) from the XDG path.
+ */
+void session_run_script(const char *script);
+
 /**
  * session_environment_init - set environment variables based on <key>=<value>
  * pairs in `${XDG_CONFIG_DIRS:-/etc/xdg}/labwc/environment` with user override
index db5894343f479f68cf39ff71848691498e2bef72..b52b717aae1809966f160aaade54a7b9c8355531 100644 (file)
@@ -261,8 +261,8 @@ session_environment_init(void)
        paths_destroy(&paths);
 }
 
-static void
-run_session_script(const char *script)
+void
+session_run_script(const char *script)
 {
        struct wl_list paths;
        paths_config_create(&paths, script);
@@ -293,13 +293,13 @@ session_autostart_init(struct server *server)
 {
        /* Update dbus and systemd user environment, each may fail gracefully */
        update_activation_env(server, /* initialize */ true);
-       run_session_script("autostart");
+       session_run_script("autostart");
 }
 
 void
 session_shutdown(struct server *server)
 {
-       run_session_script("shutdown");
+       session_run_script("shutdown");
 
        /* Clear the dbus and systemd user environment, each may fail gracefully */
        update_activation_env(server, /* initialize */ false);
index 87792d0f5b8f40ab82b84722381e63aa0cc15cae..738c2b17d0df566f072fc853ae3bd48d280155e3 100644 (file)
@@ -7,6 +7,7 @@
 #include "common/macros.h"
 #include "common/mem.h"
 #include "config/rcxml.h"
+#include "config/session.h"
 #include "labwc.h"
 #include "node.h"
 #include "ssd.h"
@@ -1072,6 +1073,9 @@ sync_atoms(xcb_connection_t *xcb_conn)
 static void
 handle_server_ready(struct wl_listener *listener, void *data)
 {
+       /* Fire an Xwayland startup script if one (or many) can be found */
+       session_run_script("xinitrc");
+
        xcb_connection_t *xcb_conn = xcb_connect(NULL, NULL);
        if (xcb_connection_has_error(xcb_conn)) {
                wlr_log(WLR_ERROR, "Failed to create xcb connection");