Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
LayerShellPluginLoader.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <QByteArray>
7#include <QFile>
8#include <QString>
9
10namespace PhosphorWayland {
11
23{
24 if (qEnvironmentVariableIsEmpty("QT_WAYLAND_SHELL_INTEGRATION")) {
25 // WAYLAND_DISPLAY proves a compositor is actually running. We do NOT fall
26 // back to XDG_SESSION_TYPE because it can be "wayland" on systemd machines
27 // even in SSH sessions or before the compositor starts, and XDG_RUNTIME_DIR
28 // is always set on systemd — so that combination is too permissive.
29 //
30 // Also check XDG_RUNTIME_DIR/wayland-0 as a fallback: some compositors
31 // (e.g. COSMIC) or systemd socket-activation setups may not set
32 // WAYLAND_DISPLAY but the socket exists at the default path.
33 if (!qEnvironmentVariableIsEmpty("WAYLAND_DISPLAY")) {
34 qputenv("QT_WAYLAND_SHELL_INTEGRATION", "phosphorwayland");
35 } else {
36 // Fallback: check for common Wayland sockets. Compositors may use any
37 // socket name (wayland-0, wayland-1 for nested sessions, or custom names).
38 // We check the two most common defaults. COSMIC and some socket-activation
39 // setups may not set WAYLAND_DISPLAY but the socket still exists.
40 const QByteArray runtimeDir = qgetenv("XDG_RUNTIME_DIR");
41 if (!runtimeDir.isEmpty()) {
42 const QString runtimePath = QString::fromUtf8(runtimeDir);
43 if (QFile::exists(runtimePath + QStringLiteral("/wayland-0"))
44 || QFile::exists(runtimePath + QStringLiteral("/wayland-1"))) {
45 qputenv("QT_WAYLAND_SHELL_INTEGRATION", "phosphorwayland");
46 }
47 }
48 }
49 }
50}
51
52} // namespace PhosphorWayland
Definition CompositorLost.h:11
void registerLayerShellPlugin()
Call before QGuiApplication to register the phosphorwayland QPA plugin.
Definition LayerShellPluginLoader.h:22