File indexing completed on 2024-05-12 17:00:19

0001 /*
0002     SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003     SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 #ifndef WINDOWEFFECTS_H
0008 #define WINDOWEFFECTS_H
0009 #include <kwindowsystem_version.h>
0010 #include <private/kwindoweffects_p.h>
0011 
0012 #include <QHash>
0013 #include <QObject>
0014 #include <QPointer>
0015 
0016 namespace KWayland
0017 {
0018 namespace Client
0019 {
0020 class BlurManager;
0021 class ContrastManager;
0022 class Compositor;
0023 class ConnectionThread;
0024 class Blur;
0025 class Contrast;
0026 }
0027 }
0028 
0029 class WindowEffects : public QObject, public KWindowEffectsPrivateV2
0030 {
0031     Q_OBJECT
0032 public:
0033     WindowEffects();
0034     ~WindowEffects() override;
0035 
0036     static QWindow *windowForId(WId);
0037 
0038     bool eventFilter(QObject *watched, QEvent *event) override;
0039     void trackWindow(QWindow *window);
0040     void releaseWindow(QWindow *window);
0041 
0042     bool isEffectAvailable(KWindowEffects::Effect effect) override;
0043     void slideWindow(WId id, KWindowEffects::SlideFromLocation location, int offset) override;
0044 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 81)
0045     QList<QSize> windowSizes(const QList<WId> &ids) override;
0046 #endif
0047 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 82)
0048     void presentWindows(WId controller, const QList<WId> &ids) override;
0049     void presentWindows(WId controller, int desktop = NET::OnAllDesktops) override;
0050     void highlightWindows(WId controller, const QList<WId> &ids) override;
0051 #endif
0052     void enableBlurBehind(WId winId, bool enable = true, const QRegion &region = QRegion()) override;
0053     void enableBackgroundContrast(WId winId,
0054                                   bool enable = true,
0055                                   qreal contrast = 1,
0056                                   qreal intensity = 1,
0057                                   qreal saturation = 1,
0058                                   const QRegion &region = QRegion()) override;
0059     void setBackgroundFrost(QWindow *window, QColor color, const QRegion &region = QRegion()) override;
0060 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 67)
0061     void markAsDashboard(WId window) override;
0062 #endif
0063 private:
0064     void installContrast(QWindow *window, bool enable = true, qreal contrast = 1, qreal intensity = 1, qreal saturation = 1, const QRegion &region = QRegion());
0065     void installBlur(QWindow *window, bool enable, const QRegion &region);
0066     void installSlide(QWindow *window, KWindowEffects::SlideFromLocation location, int offset);
0067 
0068     void resetBlur(QWindow *window, KWayland::Client::Blur *blur = nullptr);
0069     void resetContrast(QWindow *window, KWayland::Client::Contrast *contrast = nullptr);
0070 
0071     QHash<QWindow *, QList<QMetaObject::Connection>> m_windowWatchers;
0072     QHash<QWindow *, QRegion> m_blurRegions;
0073     struct BackgroundContrastData {
0074         qreal contrast = 1;
0075         qreal intensity = 1;
0076         qreal saturation = 1;
0077         QRegion region;
0078     };
0079     QHash<QWindow *, BackgroundContrastData> m_backgroundConstrastRegions;
0080     QHash<QWindow *, QPointer<KWayland::Client::Blur>> m_blurs;
0081     QHash<QWindow *, QPointer<KWayland::Client::Contrast>> m_contrasts;
0082     struct SlideData {
0083         KWindowEffects::SlideFromLocation location;
0084         int offset;
0085     };
0086     QHash<QWindow *, SlideData> m_slideMap;
0087 };
0088 
0089 #endif