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
25{
26 if (qEnvironmentVariableIsEmpty("QT_WAYLAND_SHELL_INTEGRATION")) {
27 // WAYLAND_DISPLAY proves a compositor is actually running. We do NOT fall
28 // back to XDG_SESSION_TYPE because it can be "wayland" on systemd machines
29 // even in SSH sessions or before the compositor starts, and XDG_RUNTIME_DIR
30 // is always set on systemd — so that combination is too permissive.
31 //
32 // Also check XDG_RUNTIME_DIR/wayland-0 as a fallback: some compositors
33 // (e.g. COSMIC) or systemd socket-activation setups may not set
34 // WAYLAND_DISPLAY but the socket exists at the default path.
35 //
36 // WAYLAND_SOCKET admits on its own: it is a connected fd the
37 // compositor handed this process, and libwayland's wl_display_connect,
38 // which Qt's wayland platform calls, takes it ahead of WAYLAND_DISPLAY
39 // and any socket path. A process given only WAYLAND_SOCKET has a live
40 // compositor with no display name or socket to show for it, so it
41 // passes none of the checks below.
42 if (!qEnvironmentVariableIsEmpty("WAYLAND_SOCKET") || !qEnvironmentVariableIsEmpty("WAYLAND_DISPLAY")) {
43 qputenv("QT_WAYLAND_SHELL_INTEGRATION", "phosphorwayland");
44 } else {
45 // Fallback: check for common Wayland sockets. Compositors may use any
46 // socket name (wayland-0, wayland-1 for nested sessions, or custom names).
47 // We check the two most common defaults. COSMIC and some socket-activation
48 // setups may not set WAYLAND_DISPLAY but the socket still exists.
49 const QByteArray runtimeDir = qgetenv("XDG_RUNTIME_DIR");
50 if (!runtimeDir.isEmpty()) {
51 const QString runtimePath = QString::fromUtf8(runtimeDir);
52 if (QFile::exists(runtimePath + QStringLiteral("/wayland-0"))
53 || QFile::exists(runtimePath + QStringLiteral("/wayland-1"))) {
54 qputenv("QT_WAYLAND_SHELL_INTEGRATION", "phosphorwayland");
55 }
56 }
57 }
58 }
59}
60
61} // namespace PhosphorWayland
Definition BackgroundEffect.h:15
void registerLayerShellPlugin()
Call before QGuiApplication to register the phosphorwayland QPA plugin.
Definition LayerShellPluginLoader.h:24