feat: auto-reexec with LD_PRELOAD for gtk4-layer-shell

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.
This commit is contained in:
nevaforget 2026-03-27 13:54:32 +01:00
parent 4cad984263
commit 1251fe8ef4

View File

@ -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")