Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
WallpaperService.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 <PhosphorShell/phosphorshell_export.h>
7
8#include <QHash>
9#include <QImage>
10#include <QObject>
11#include <QString>
12#include <QVariantMap>
13
14#include <memory>
15
16namespace PhosphorShaders {
18}
19
20namespace PhosphorShell {
21
68class PHOSPHORSHELL_EXPORT WallpaperService : public QObject
69{
70 Q_OBJECT
71 Q_DISABLE_COPY_MOVE(WallpaperService)
72
73 Q_PROPERTY(QImage image READ image NOTIFY imageChanged)
76 Q_PROPERTY(QString path READ path NOTIFY pathChanged)
77 Q_PROPERTY(bool available READ isAvailable NOTIFY imageChanged)
78
79public:
82 explicit WallpaperService(const QString& storePath, QObject* parent = nullptr);
87 WallpaperService(const QString& storePath, std::unique_ptr<PhosphorShaders::IWallpaperProvider> seedProvider,
88 QObject* parent = nullptr);
90
92 [[nodiscard]] QString storePath() const;
93
94 [[nodiscard]] QImage image() const;
95 [[nodiscard]] QString path() const;
96 [[nodiscard]] bool isAvailable() const;
97
101 Q_INVOKABLE [[nodiscard]] QString configuredPath(const QString& screenName = QString()) const;
104 Q_INVOKABLE [[nodiscard]] QString previewPath(const QString& screenName = QString()) const;
107 Q_INVOKABLE [[nodiscard]] QString effectivePath(const QString& screenName = QString()) const;
108
113 Q_INVOKABLE bool setPath(const QString& path, const QString& screenName = QString());
114
117 Q_INVOKABLE bool setPreview(const QString& path, const QString& screenName = QString());
120 Q_INVOKABLE void clearPreview(const QString& screenName = QString());
121
122 // Appearance owns the complete, atomically saved look. This live layer
123 // also receives drafts, without writing the old standalone wallpaper file.
124 Q_INVOKABLE void setAppearance(const QVariantMap& wallpapers);
125 Q_INVOKABLE QVariantMap appearanceSeed() const;
126 Q_INVOKABLE QString effectiveFit(const QString& screenName = QString()) const;
127
130 Q_INVOKABLE void refresh();
131
132Q_SIGNALS:
137 void effectivePathChanged(const QString& screenName);
138
139private:
140 void load();
141 void save() const;
142 void seedFromDesktop();
143 void scheduleLoad(const QString& path);
144 void installImage(QImage image, const QString& path);
145
146 // QImageReader::setAllocationLimit unit is MiB. 512 MiB covers a
147 // ~16K × 16K RGBA8888 wallpaper while rejecting decompression
148 // bombs.
149 static constexpr int kMaxImageBytesMib = 512;
150 // Pixel-count cap: reject before decode runs, so a small-header
151 // image with huge declared dimensions can't make it to allocation.
152 static constexpr qint64 kMaxPixelCount = qint64(16384) * 16384;
153
154 const QString m_storePath;
155 std::unique_ptr<PhosphorShaders::IWallpaperProvider> m_seedProvider;
156 // Output name → absolute path. The empty key is the all-screens entry.
157 QHash<QString, QString> m_configured;
158 QHash<QString, QString> m_preview;
159 QVariantMap m_appearance;
160 // The path `m_image` was decoded from.
161 QString m_imagePath;
162 QImage m_image;
163 // Generation counter discards out-of-order async-load results: a
164 // rapid wallpaper-change sequence could queue multiple decode
165 // tasks; only the most recently scheduled one's result is
166 // installed. Incremented on every scheduleLoad.
167 quint64 m_loadGeneration = 0;
168};
169
170} // namespace PhosphorShell
Abstract wallpaper provider interface.
Definition IWallpaperProvider.h:17
QString effectiveFit(const QString &screenName=QString()) const
QVariantMap appearanceSeed() const
QString effectivePath(const QString &screenName=QString()) const
What a surface on screenName should draw: the preview when one is set, otherwise the configured path.
bool setPreview(const QString &path, const QString &screenName=QString())
Show path on screenName (every screen when empty) without persisting it.
QString configuredPath(const QString &screenName=QString()) const
The persisted wallpaper for screenName: its own entry, else the all-screens entry,...
void clearPreview(const QString &screenName=QString())
Drop the preview for screenName, or every preview when the name is empty.
QString previewPath(const QString &screenName=QString()) const
The transient preview for screenName, resolved the same way.
WallpaperService(const QString &storePath, std::unique_ptr< PhosphorShaders::IWallpaperProvider > seedProvider, QObject *parent=nullptr)
Same, with the first-run seed source injected.
QString storePath() const
Where the store lives, as the constructor was given it.
void refresh()
Re-decode path into image, for a consumer that knows the file changed on disk under the same name.
bool setPath(const QString &path, const QString &screenName=QString())
Persist path as the wallpaper for screenName, or for every screen when the name is empty (which also ...
void effectivePathChanged(const QString &screenName)
The answer to effectivePath(screenName) may have changed.
WallpaperService(const QString &storePath, QObject *parent=nullptr)
The shell-wide configured wallpaper: the all-screens entry, or when only per-screen entries exist,...
void setAppearance(const QVariantMap &wallpapers)
Definition ShaderProfile.h:21
Definition Environment.h:11