diff --git a/scanslicer/entry.py b/scanslicer/entry.py index c720416..997ecd7 100644 --- a/scanslicer/entry.py +++ b/scanslicer/entry.py @@ -36,3 +36,30 @@ def _detect_backend_from_qpa_env(): if token in ("xcb", "x11"): return "x11" return None + + +# resolve_runtime_backend: function definition for ScanSlicer behavior. +def resolve_runtime_backend(backend): + if backend in ("wayland", "x11"): + return backend + + env_backend = _detect_backend_from_qpa_env() + if env_backend is not None: + return env_backend + + session_type = os.environ.get("XDG_SESSION_TYPE", "").strip().lower() + if session_type == "wayland": + return "wayland" + if session_type == "x11": + return "x11" + + runtime_dir = os.environ.get("XDG_RUNTIME_DIR", "").strip() + wayland_display = os.environ.get("WAYLAND_DISPLAY", "").strip() + if runtime_dir and wayland_display and os.path.exists(os.path.join(runtime_dir, wayland_display)): + return "wayland" + + if os.environ.get("DISPLAY", "").strip(): + return "x11" + + # Fall back to Wayland when auto-detection has no clear signal. + return "wayland"