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 <QImage>
9#include <QObject>
10#include <QString>
11
12#include <memory>
13
14namespace PhosphorShaders {
15class IWallpaperProvider;
16}
17
18QT_BEGIN_NAMESPACE
19class QFileSystemWatcher;
20class QTimer;
21QT_END_NAMESPACE
22
23namespace PhosphorShell {
24
50class PHOSPHORSHELL_EXPORT WallpaperService : public QObject
51{
52 Q_OBJECT
53 Q_DISABLE_COPY_MOVE(WallpaperService)
54
55 Q_PROPERTY(QImage image READ image NOTIFY imageChanged)
56 Q_PROPERTY(QString path READ path NOTIFY imageChanged)
57 Q_PROPERTY(bool available READ isAvailable NOTIFY imageChanged)
58
59public:
60 explicit WallpaperService(QObject* parent = nullptr);
62
63 [[nodiscard]] QImage image() const;
64 [[nodiscard]] QString path() const;
65 [[nodiscard]] bool isAvailable() const;
66
70 Q_INVOKABLE void refresh();
71
72Q_SIGNALS:
74
75private:
76 void scheduleLoad(const QString& path);
77 void installImage(QImage image, const QString& path);
78
79 // Plasma config file is written via atomic rename, which can fire
80 // QFileSystemWatcher::fileChanged several times for one save.
81 // Debounce so a burst collapses to one refresh().
82 static constexpr int kRefreshDebounceMs = 200;
83 // QImageReader::setAllocationLimit unit is MiB. 512 MiB covers a
84 // ~16K × 16K RGBA8888 wallpaper while rejecting decompression
85 // bombs.
86 static constexpr int kMaxImageBytesMib = 512;
87 // Pixel-count cap: reject before decode runs, so a small-header
88 // image with huge declared dimensions can't make it to allocation.
89 static constexpr qint64 kMaxPixelCount = qint64(16384) * 16384;
90
91 std::unique_ptr<PhosphorShaders::IWallpaperProvider> m_provider;
92 QString m_currentPath;
93 QImage m_image;
94 QFileSystemWatcher* m_watcher = nullptr;
95 QTimer* m_refreshDebounce = nullptr;
96 // Generation counter discards out-of-order async-load results: a
97 // rapid wallpaper-change sequence could queue multiple decode
98 // tasks; only the most recently scheduled one's result is
99 // installed. Incremented on every scheduleLoad.
100 quint64 m_loadGeneration = 0;
101};
102
103} // namespace PhosphorShell
Asynchronous wallpaper-image source for shader backgrounds.
Definition WallpaperService.h:51
WallpaperService(QObject *parent=nullptr)
void refresh()
Re-query the provider and reload the wallpaper image if the path has changed.
Definition ShaderEffect.h:28
Definition Environment.h:11