/*
    SPDX-FileCopyrightText: 2019 Martin Flöser <mgraesslin@kde.org>

    SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "windoweffects.h"
#include "core/region.h"
#include "effect/effecthandler.h"

#include <QGuiApplication>
#include <QWidget>
#include <QWindow>

Q_DECLARE_METATYPE(KWindowEffects::SlideFromLocation)

namespace KWin
{

WindowEffects::WindowEffects()
    : QObject()
    , KWindowEffectsPrivate()
{
}

WindowEffects::~WindowEffects()
{
}

bool WindowEffects::isEffectAvailable(KWindowEffects::Effect effect)
{
    if (!effects) {
        return false;
    }
    switch (effect) {
    case KWindowEffects::BackgroundContrast:
        return effects->isEffectLoaded(QStringLiteral("contrast"));
    case KWindowEffects::BlurBehind:
        return effects->isEffectLoaded(QStringLiteral("blur"));
    case KWindowEffects::Slide:
        return effects->isEffectLoaded(QStringLiteral("slidingpopups"));
    default:
        // plugin does not provide integration for other effects
        return false;
    }
}

void WindowEffects::slideWindow(QWindow *window, KWindowEffects::SlideFromLocation location, int offset)
{
    window->setProperty("kwin_slide", QVariant::fromValue(location));
    window->setProperty("kwin_slide_offset", offset);
}

void WindowEffects::enableBlurBehind(QWindow *window, bool enable, const QRegion &region)
{
    if (enable) {
        window->setProperty("kwin_blur", QVariant::fromValue(RegionF(region)));
    } else {
        window->setProperty("kwin_blur", {});
    }
}

void WindowEffects::enableBackgroundContrast(QWindow *window, bool enable, qreal contrast, qreal intensity, qreal saturation, const QRegion &region)
{
    // The background contrast effect has been merged with the blur effect and its params are global.
}

}
