KWin
Loading...
Searching...
No Matches
effectloader.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#pragma once
10#include <kwin_export.h>
11// KDE
12#include <KPluginMetaData>
13#include <KSharedConfig>
14// Qt
15#include <QFlags>
16#include <QMap>
17#include <QObject>
18#include <QPair>
19#include <QQueue>
20#include <QStaticPlugin>
21
22namespace KWin
23{
24class Effect;
25class EffectPluginFactory;
26
35enum class LoadEffectFlag {
36 Load = 1 << 0,
37 CheckDefaultFunction = 1 << 2
38};
39Q_DECLARE_FLAGS(LoadEffectFlags, LoadEffectFlag)
40
41
57class KWIN_EXPORT AbstractEffectLoader : public QObject
58{
59 Q_OBJECT
60public:
61 ~AbstractEffectLoader() override;
62
71 virtual void setConfig(KSharedConfig::Ptr config);
72
82 virtual bool hasEffect(const QString &name) const = 0;
83
92 virtual QStringList listOfKnownEffects() const = 0;
93
116 virtual bool loadEffect(const QString &name) = 0;
117
144 virtual void queryAndLoadAll() = 0;
145
152 virtual bool isEffectSupported(const QString &name) const = 0;
153
157 virtual void clear() = 0;
158
159Q_SIGNALS:
167 void effectLoaded(KWin::Effect *effect, const QString &name);
168
169protected:
170 explicit AbstractEffectLoader(QObject *parent = nullptr);
183 LoadEffectFlags readConfig(const QString &effectName, bool defaultValue) const;
184
185private:
186 KSharedConfig::Ptr m_config;
187};
188
189template<typename Loader, typename QueueType>
190class EffectLoadQueue;
208class AbstractEffectLoadQueue : public QObject
209{
210 Q_OBJECT
211public:
212 explicit AbstractEffectLoadQueue(QObject *parent = nullptr)
213 : QObject(parent)
214 {
215 }
216protected Q_SLOTS:
217 virtual void dequeue() = 0;
218
219private:
220 template<typename Loader, typename QueueType>
221 friend class EffectLoadQueue;
222};
223
224template<typename Loader, typename QueueType>
226{
227public:
228 explicit EffectLoadQueue(Loader *parent)
230 , m_effectLoader(parent)
231 , m_dequeueScheduled(false)
232 {
233 }
234 void enqueue(const QPair<QueueType, LoadEffectFlags> value)
235 {
236 m_queue.enqueue(value);
237 scheduleDequeue();
238 }
239 void clear()
240 {
241 m_queue.clear();
242 m_dequeueScheduled = false;
243 }
244
245protected:
246 void dequeue() override
247 {
248 if (m_queue.isEmpty()) {
249 return;
250 }
251 m_dequeueScheduled = false;
252 const auto pair = m_queue.dequeue();
253 m_effectLoader->loadEffect(pair.first, pair.second);
254 scheduleDequeue();
255 }
256
257private:
258 void scheduleDequeue()
259 {
260 if (m_queue.isEmpty() || m_dequeueScheduled) {
261 return;
262 }
263 m_dequeueScheduled = true;
264 QMetaObject::invokeMethod(this, &AbstractEffectLoadQueue::dequeue, Qt::QueuedConnection);
265 }
266 Loader *m_effectLoader;
267 bool m_dequeueScheduled;
268 QQueue<QPair<QueueType, LoadEffectFlags>> m_queue;
269};
270
275{
276 Q_OBJECT
277public:
278 explicit ScriptedEffectLoader(QObject *parent = nullptr);
279 ~ScriptedEffectLoader() override;
280
281 bool hasEffect(const QString &name) const override;
282 bool isEffectSupported(const QString &name) const override;
283 QStringList listOfKnownEffects() const override;
284
285 void clear() override;
286 void queryAndLoadAll() override;
287 bool loadEffect(const QString &name) override;
288 bool loadEffect(const KPluginMetaData &effect, LoadEffectFlags flags);
289
290private:
291 QList<KPluginMetaData> findAllEffects() const;
292 KPluginMetaData findEffect(const QString &name) const;
293 bool loadJavascriptEffect(const KPluginMetaData &effect);
294 bool loadDeclarativeEffect(const KPluginMetaData &effect);
295
296 QStringList m_loadedEffects;
298 QMetaObject::Connection m_queryConnection;
299};
300
302{
303 Q_OBJECT
304public:
305 explicit PluginEffectLoader(QObject *parent = nullptr);
306 ~PluginEffectLoader() override;
307
308 bool hasEffect(const QString &name) const override;
309 bool isEffectSupported(const QString &name) const override;
310 QStringList listOfKnownEffects() const override;
311
312 void clear() override;
313 void queryAndLoadAll() override;
314 bool loadEffect(const QString &name) override;
315 bool loadEffect(const KPluginMetaData &info, LoadEffectFlags flags);
316
317 void setPluginSubDirectory(const QString &directory);
318
319private:
320 QList<KPluginMetaData> findAllEffects() const;
321 KPluginMetaData findEffect(const QString &name) const;
322 EffectPluginFactory *factory(const KPluginMetaData &info) const;
323 QStringList m_loadedEffects;
324 QString m_pluginSubDirectory;
325};
326
327class KWIN_EXPORT EffectLoader : public AbstractEffectLoader
328{
329 Q_OBJECT
330public:
331 explicit EffectLoader(QObject *parent = nullptr);
332 ~EffectLoader() override;
333 bool hasEffect(const QString &name) const override;
334 bool isEffectSupported(const QString &name) const override;
335 QStringList listOfKnownEffects() const override;
336 bool loadEffect(const QString &name) override;
337 void queryAndLoadAll() override;
338 void setConfig(KSharedConfig::Ptr config) override;
339 void clear() override;
340
341private:
342 QList<AbstractEffectLoader *> m_loaders;
343};
344
345}
346Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::LoadEffectFlags)
Helper class to queue the loading of Effects.
AbstractEffectLoadQueue(QObject *parent=nullptr)
Interface to describe how an effect loader has to function.
virtual QStringList listOfKnownEffects() const =0
All the Effects this loader knows of.
void effectLoaded(KWin::Effect *effect, const QString &name)
The loader emits this signal when it successfully loaded an effect.
virtual void queryAndLoadAll()=0
The Effect Loader should query its store for all available effects and try to load them.
virtual bool hasEffect(const QString &name) const =0
Whether this Effect Loader can load the Effect with the given name.
virtual void clear()=0
Clears the load queue, that is all scheduled Effects are discarded from loading.
virtual bool loadEffect(const QString &name)=0
Synchronous loading of the Effect with the given name.
virtual bool isEffectSupported(const QString &name) const =0
Whether the Effect with the given name is supported by the compositing backend.
Base class for all KWin effects.
Definition effect.h:535
void dequeue() override
void enqueue(const QPair< QueueType, LoadEffectFlags > value)
EffectLoadQueue(Loader *parent)
void setPluginSubDirectory(const QString &directory)
bool isEffectSupported(const QString &name) const override
Whether the Effect with the given name is supported by the compositing backend.
bool loadEffect(const QString &name) override
Synchronous loading of the Effect with the given name.
void clear() override
Clears the load queue, that is all scheduled Effects are discarded from loading.
bool hasEffect(const QString &name) const override
Whether this Effect Loader can load the Effect with the given name.
void queryAndLoadAll() override
The Effect Loader should query its store for all available effects and try to load them.
QStringList listOfKnownEffects() const override
All the Effects this loader knows of.
PluginEffectLoader(QObject *parent=nullptr)
Can load scripted Effects.
LoadEffectFlag
Flags defining how a Loader should load an Effect.
@ CheckDefaultFunction
The Check Default Function needs to be invoked if the Effect provides it.
@ Load
Effect should be loaded.