File indexing completed on 2024-11-10 04:57:12

0001 /*
0002     SPDX-FileCopyrightText: 2019 Martin Flöser <mgraesslin@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 #include "windoweffects.h"
0007 #include "effect/effecthandler.h"
0008 
0009 #include <QGuiApplication>
0010 #include <QWidget>
0011 #include <QWindow>
0012 
0013 Q_DECLARE_METATYPE(KWindowEffects::SlideFromLocation)
0014 
0015 namespace KWin
0016 {
0017 
0018 WindowEffects::WindowEffects()
0019     : QObject()
0020     , KWindowEffectsPrivate()
0021 {
0022 }
0023 
0024 WindowEffects::~WindowEffects()
0025 {
0026 }
0027 
0028 bool WindowEffects::isEffectAvailable(KWindowEffects::Effect effect)
0029 {
0030     if (!effects) {
0031         return false;
0032     }
0033     switch (effect) {
0034     case KWindowEffects::BackgroundContrast:
0035         return effects->isEffectLoaded(QStringLiteral("contrast"));
0036     case KWindowEffects::BlurBehind:
0037         return effects->isEffectLoaded(QStringLiteral("blur"));
0038     case KWindowEffects::Slide:
0039         return effects->isEffectLoaded(QStringLiteral("slidingpopups"));
0040     default:
0041         // plugin does not provide integration for other effects
0042         return false;
0043     }
0044 }
0045 
0046 void WindowEffects::slideWindow(QWindow *window, KWindowEffects::SlideFromLocation location, int offset)
0047 {
0048     window->setProperty("kwin_slide", QVariant::fromValue(location));
0049     window->setProperty("kwin_slide_offset", offset);
0050 }
0051 
0052 void WindowEffects::enableBlurBehind(QWindow *window, bool enable, const QRegion &region)
0053 {
0054     if (enable) {
0055         window->setProperty("kwin_blur", region);
0056     } else {
0057         window->setProperty("kwin_blur", {});
0058     }
0059 }
0060 
0061 void WindowEffects::enableBackgroundContrast(QWindow *window, bool enable, qreal contrast, qreal intensity, qreal saturation, const QRegion &region)
0062 {
0063     if (enable) {
0064         window->setProperty("kwin_background_region", region);
0065         window->setProperty("kwin_background_contrast", contrast);
0066         window->setProperty("kwin_background_intensity", intensity);
0067         window->setProperty("kwin_background_saturation", saturation);
0068     } else {
0069         window->setProperty("kwin_background_region", {});
0070         window->setProperty("kwin_background_contrast", {});
0071         window->setProperty("kwin_background_intensity", {});
0072         window->setProperty("kwin_background_saturation", {});
0073     }
0074 }
0075 }