feat(entry): implement def resolve_runtime_backend

This commit is contained in:
dev 2026-02-23 10:00:12 +00:00
parent 052d3efefa
commit fff9178f8a

View file

@ -36,3 +36,30 @@ def _detect_backend_from_qpa_env():
if token in ("xcb", "x11"): if token in ("xcb", "x11"):
return "x11" return "x11"
return None 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"