// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include "RemoteDisplayMode.h" #include static bool DetectRemoteDisplay() { const QByteArray env = qgetenv("JFJOCH_VIEWER_REMOTE"); if (!env.isEmpty()) return env != "0" && env.compare("false", Qt::CaseInsensitive) != 0; // Wayland, Windows and macOS sessions are local by construction. if (QGuiApplication::platformName() != QLatin1String("xcb")) return false; // A DISPLAY with a host part goes over a socket that carries every pixel: // "localhost:10.0" is SSH forwarding, "host:0" is raw remote X. A local display // is ":0"-style ("unix:0" is a legacy spelling of the same thing). const QByteArray display = qgetenv("DISPLAY"); const auto colon = display.indexOf(':'); if (colon <= 0) return false; return display.left(colon) != "unix"; } static bool &ActiveFlag() { static bool active = DetectRemoteDisplay(); return active; } bool RemoteDisplayMode() { return ActiveFlag(); } void SetRemoteDisplayMode(bool active) { ActiveFlag() = active; }