Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
DBusScreenAdaptor.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 "phosphorscreens_export.h"
7
8#include <QDBusAbstractAdaptor>
9#include <QHash>
10#include <QObject>
11#include <QPointer>
12#include <QRect>
13#include <QStringList>
14
15#include <functional>
16
17class QScreen;
18
19namespace PhosphorScreens {
20
21class IConfigStore;
22class ScreenManager;
23
42class PHOSPHORSCREENS_EXPORT DBusScreenAdaptor : public QDBusAbstractAdaptor
43{
44 Q_OBJECT
45 Q_CLASSINFO("D-Bus Interface", "org.phosphor_works.Placement.Screen")
46
47public:
52 explicit DBusScreenAdaptor(ScreenManager* manager, IConfigStore* store, QObject* parent = nullptr);
54
62 using CompositorReportGate = std::function<bool(QLatin1StringView member)>;
64
65public Q_SLOTS:
66 // Screen queries
67 QStringList getScreens();
83 QString getScreenInfo(const QString& screenId);
85 QString getScreenId(const QString& connectorName);
86 void setPrimaryScreenFromKWin(const QString& connectorName);
93 void setAvailableGeometryFromKWin(const QString& screenName, int x, int y, int width, int height);
97 QRect getAvailableGeometry(const QString& screenId);
98 QRect getScreenGeometry(const QString& screenId);
99
100 // Virtual screen management
101 QString getVirtualScreenConfig(const QString& physicalScreenId);
108 QString setVirtualScreenConfig(const QString& physicalScreenId, const QString& configJson);
109 QStringList getPhysicalScreens();
110 QString getEffectiveScreenAt(int x, int y);
111
120 QString swapVirtualScreenInDirection(const QString& currentVirtualScreenId, const QString& direction);
121
126 QString rotateVirtualScreens(const QString& physicalScreenId, bool clockwise);
127
138 void setPixelSizeFromKWin(const QString& screenName, int width, int height);
139
140Q_SIGNALS:
141 void screenAdded(const QString& screenId);
142 void screenRemoved(const QString& screenId);
147 void screenGeometryChanged(const QString& screenId);
148 void virtualScreensChanged(const QString& physicalScreenId);
153 void availableGeometryChanged(const QString& screenId);
154
155protected:
163
164private:
165 void handleScreenGeometryChanged(QScreen* screen, const QString& physId);
166 void handleScreenRemoved(QScreen* removedScreen, QScreen* targetScreen, const QString& cachedId);
175 void handleScreenIdentifierChanged(const QString& oldId, const QString& newId);
176 bool emitForEffectiveScreens(const QString& physId, const std::function<void(const QString&)>& emitFn);
177 void invalidateScreenInfoCache();
178 void connectScreenManagerSignals(ScreenManager* mgr);
179 void wireQGuiApplicationSignals();
184 void wirePerScreenSignals(QScreen* screen);
185
186 QString m_primaryScreenOverride;
187 // QPointer-guarded so a ScreenManager / IConfigStore destroyed before
188 // this adaptor (e.g. daemon tears down data members before QObject
189 // children) safely reads as null rather than dangling, for every slot and
190 // accessor that reads them after that point. The destructor deliberately
191 // does not disconnect (Qt breaks the connections when either peer dies),
192 // so there is no destructor path for it to guard.
193 QPointer<ScreenManager> m_screenManager;
194 QPointer<IConfigStore> m_configStore;
195
196 QStringList m_lastEmittedEffectiveIds;
197 QHash<QString, QStringList> m_cachedEffectiveIdsPerScreen;
198 QHash<QString, QString> m_cachedScreenInfoJson;
199
200 bool m_qGuiAppSignalsWired = false;
202 CompositorReportGate m_compositorReportGate;
203};
204
205} // namespace PhosphorScreens
QString swapVirtualScreenInDirection(const QString &currentVirtualScreenId, const QString &direction)
Swap the region of currentVirtualScreenId with the adjacent sibling VS in the given direction (left/r...
void screenGeometryChanged(const QString &screenId)
The screen's resolution, position or logical scale changed (the scale through ScreenManager::logicalS...
void availableGeometryChanged(const QString &screenId)
The screen's available geometry (the work area left by panels) moved while its full rect may not have...
QString getScreenId(const QString &connectorName)
QString rotateVirtualScreens(const QString &physicalScreenId, bool clockwise)
Rotate every VS region on physicalScreenId through a spatial clockwise ring order.
QString getVirtualScreenConfig(const QString &physicalScreenId)
QString setVirtualScreenConfig(const QString &physicalScreenId, const QString &configJson)
Set the virtual screen subdivision configuration for a physical screen.
QRect getAvailableGeometry(const QString &screenId)
The geometry queries answer the primary screen for an EMPTY id only.
void virtualScreensChanged(const QString &physicalScreenId)
IConfigStore * configStore() const
QString getEffectiveScreenAt(int x, int y)
void setAvailableGeometryFromKWin(const QString &screenName, int x, int y, int width, int height)
Record the authoritative per-screen available geometry as reported by the compositor (the KWin effect...
void setCompositorReportGate(CompositorReportGate gate)
QString getScreenInfo(const QString &screenId)
JSON object describing screenId.
void setPrimaryScreenFromKWin(const QString &connectorName)
void screenAdded(const QString &screenId)
void screenRemoved(const QString &screenId)
void setPixelSizeFromKWin(const QString &screenName, int width, int height)
Record an output's exact size in device pixels as reported by the compositor (the KWin effect reads t...
DBusScreenAdaptor(ScreenManager *manager, IConfigStore *store, QObject *parent=nullptr)
Primary constructor: wires the screen-topology service and the VS config store at construction time.
QRect getScreenGeometry(const QString &screenId)
std::function< bool(QLatin1StringView member)> CompositorReportGate
The admission check for the methods only the compositor may call (setPrimaryScreenFromKWin,...
Definition DBusScreenAdaptor.h:62
ScreenManager * screenManager() const
Pluggable persistence for virtual-screen configurations.
Definition IConfigStore.h:37
Centralized screen-topology service.
Definition Manager.h:86
Definition IWindowTrackingService.h:28