From 1251fe8ef468c396310787cc04114834bab941c1 Mon Sep 17 00:00:00 2001 From: nevaforget Date: Fri, 27 Mar 2026 13:54:32 +0100 Subject: [PATCH] feat: auto-reexec with LD_PRELOAD for gtk4-layer-shell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same pattern as moonlock — re-exec the process with LD_PRELOAD set so gtk4-layer-shell is loaded before libwayland-client. Skipped during tests via pytest/unittest module detection. --- src/moonset/main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/moonset/main.py b/src/moonset/main.py index cbd643d..8eeb764 100644 --- a/src/moonset/main.py +++ b/src/moonset/main.py @@ -2,9 +2,23 @@ # ABOUTME: Handles multi-monitor setup: power menu on primary, wallpaper on secondary monitors. import logging +import os import sys from importlib.resources import files +# gtk4-layer-shell must be loaded before libwayland-client. +# Only allow our own library in LD_PRELOAD — discard anything inherited from the environment. +_LAYER_SHELL_LIB = "/usr/lib/libgtk4-layer-shell.so" +_existing_preload = os.environ.get("LD_PRELOAD", "") +_is_testing = "pytest" in sys.modules or "unittest" in sys.modules +if ( + not _is_testing + and _LAYER_SHELL_LIB not in _existing_preload + and os.path.exists(_LAYER_SHELL_LIB) +): + os.environ["LD_PRELOAD"] = _LAYER_SHELL_LIB + os.execvp(sys.executable, [sys.executable, "-m", "moonset.main"] + sys.argv[1:]) + import gi gi.require_version("Gtk", "4.0") gi.require_version("Gdk", "4.0")