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