Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 9d197e8c authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

[effects] Add Scale effect

Summary:
The new effect scales windows as they appear and disappear.

As the the most of window animation effects, it is a monolithic effect,
i.e., if you enable scale effect, it will animate *both* the appearing and
disappearing.

The main difference between the Scale effect and the Scale in effect is
that the Scale in effect only animates windows as they appear. There is
no corresponding "the Scale out" effect, which is odd. Other points that
differentiate the Scale effect from the Scale in effect:

* it is more subtle;
* it doesn't animate the log out screen;
* it doesn't conflict with the Fade effect, etc.

... and overall, the Scale effect supersedes the Scale in effect.

{F5904947}

//Window open animation.//

{F5904948}

//Window close animation.//

{F5905283, layout=center, size=full}

//KCM.//

Test Plan:
* Enabled this effect
* Opened/closed System Settings

Reviewers: #kwin, #plasma, #vdg, davidedmundson

Reviewed By: #kwin, #plasma, #vdg, davidedmundson

Subscribers: ngraham, davidedmundson, fvogt, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D13461
parent a8563304
......@@ -103,6 +103,7 @@ void TestBuiltInEffectLoader::testHasEffect_data()
QTest::newRow("MouseMark") << QStringLiteral("mousemark") << true;
QTest::newRow("PresentWindows") << QStringLiteral("presentwindows") << true;
QTest::newRow("Resize") << QStringLiteral("resize") << true;
QTest::newRow("Scale") << QStringLiteral("scale") << true;
QTest::newRow("ScreenEdge") << QStringLiteral("screenedge") << true;
QTest::newRow("ScreenShot") << QStringLiteral("screenshot") << true;
QTest::newRow("Sheet") << QStringLiteral("sheet") << true;
......@@ -159,6 +160,7 @@ void TestBuiltInEffectLoader::testKnownEffects()
<< QStringLiteral("mousemark")
<< QStringLiteral("presentwindows")
<< QStringLiteral("resize")
<< QStringLiteral("scale")
<< QStringLiteral("screenedge")
<< QStringLiteral("screenshot")
<< QStringLiteral("sheet")
......@@ -237,6 +239,7 @@ void TestBuiltInEffectLoader::testSupported_data()
QTest::newRow("MouseMark") << QStringLiteral("mousemark") << true << xc << true;
QTest::newRow("PresentWindows") << QStringLiteral("presentwindows") << true << xc << true;
QTest::newRow("Resize") << QStringLiteral("resize") << true << xc << true;
QTest::newRow("Scale") << QStringLiteral("scale") << true << xc << true;
QTest::newRow("ScreenEdge") << QStringLiteral("screenedge") << true << xc << true;
QTest::newRow("ScreenShot") << QStringLiteral("screenshot") << true << xc << true;
QTest::newRow("Sheet") << QStringLiteral("sheet") << false << xc << true;
......@@ -325,6 +328,7 @@ void TestBuiltInEffectLoader::testLoadEffect_data()
QTest::newRow("MouseMark") << QStringLiteral("mousemark") << true << xc;
QTest::newRow("PresentWindows") << QStringLiteral("presentwindows") << true << xc;
QTest::newRow("Resize") << QStringLiteral("resize") << true << xc;
QTest::newRow("Scale") << QStringLiteral("scale") << true << xc;
QTest::newRow("ScreenEdge") << QStringLiteral("screenedge") << true << xc;
QTest::newRow("ScreenShot") << QStringLiteral("screenshot") << true << xc;
QTest::newRow("Sheet") << QStringLiteral("sheet") << false << xc;
......
......@@ -95,6 +95,7 @@ void TestPluginEffectLoader::testHasEffect_data()
QTest::newRow("MouseMark") << QStringLiteral("mousemark") << false;
QTest::newRow("PresentWindows") << QStringLiteral("presentwindows") << false;
QTest::newRow("Resize") << QStringLiteral("resize") << false;
QTest::newRow("Scale") << QStringLiteral("scale") << false;
QTest::newRow("ScreenEdge") << QStringLiteral("screenedge") << false;
QTest::newRow("ScreenShot") << QStringLiteral("screenshot") << false;
QTest::newRow("Sheet") << QStringLiteral("sheet") << false;
......
......@@ -125,6 +125,7 @@ void TestScriptedEffectLoader::testHasEffect_data()
QTest::newRow("MouseMark") << QStringLiteral("mousemark") << false;
QTest::newRow("PresentWindows") << QStringLiteral("presentwindows") << false;
QTest::newRow("Resize") << QStringLiteral("resize") << false;
QTest::newRow("Scale") << QStringLiteral("scale") << false;
QTest::newRow("ScreenEdge") << QStringLiteral("screenedge") << false;
QTest::newRow("ScreenShot") << QStringLiteral("screenshot") << false;
QTest::newRow("Sheet") << QStringLiteral("sheet") << false;
......
......@@ -90,6 +90,7 @@ set( kwin4_effect_builtins_sources
presentwindows/presentwindows.cpp
presentwindows/presentwindows_proxy.cpp
resize/resize.cpp
scale/scale.cpp
showfps/showfps.cpp
slide/slide.cpp
thumbnailaside/thumbnailaside.cpp
......@@ -119,6 +120,7 @@ kconfig_add_kcfg_files(kwin4_effect_builtins_sources
mousemark/mousemarkconfig.kcfgc
presentwindows/presentwindowsconfig.kcfgc
resize/resizeconfig.kcfgc
scale/scaleconfig.kcfgc
showfps/showfpsconfig.kcfgc
slide/slideconfig.kcfgc
slidingpopups/slidingpopupsconfig.kcfgc
......@@ -179,6 +181,7 @@ add_subdirectory( lookingglass )
add_subdirectory( magnifier )
add_subdirectory( mouseclick )
add_subdirectory( mousemark )
add_subdirectory( scale )
include( screenshot/CMakeLists.txt )
include( sheet/CMakeLists.txt )
include( snaphelper/CMakeLists.txt )
......
......@@ -37,6 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "magiclamp/magiclamp.h"
#include "minimizeanimation/minimizeanimation.h"
#include "resize/resize.h"
#include "scale/scale.h"
#include "showfps/showfps.h"
#include "showpaint/showpaint.h"
#include "slide/slide.h"
......@@ -441,6 +442,21 @@ EFFECT_FALLBACK
nullptr,
nullptr
#endif
EFFECT_FALLBACK
}, {
QStringLiteral("scale"),
i18ndc("kwin_effects", "Name of a KWin Effect", "Scale"),
i18ndc("kwin_effects", "Comment describing the KWin Effect", "Make windows smoothly scale in and out when they are shown or hidden"),
QStringLiteral("Appearance"),
QString(),
QUrl(),
false,
false,
#ifdef EFFECT_BUILTINS
&createHelper<ScaleEffect>,
&ScaleEffect::supported,
nullptr
#endif
EFFECT_FALLBACK
}, {
QStringLiteral("screenedge"),
......
......@@ -57,6 +57,7 @@ enum class BuiltInEffect
MouseMark,
PresentWindows,
Resize,
Scale,
ScreenEdge,
ScreenShot,
Sheet,
......
#######################################
# Config
set(kwin_scale_config_SRCS scale_config.cpp)
ki18n_wrap_ui(kwin_scale_config_SRCS scale_config.ui)
qt5_add_dbus_interface(kwin_scale_config_SRCS ${kwin_effects_dbus_xml} kwineffects_interface)
kconfig_add_kcfg_files(kwin_scale_config_SRCS scaleconfig.kcfgc)
add_library(kwin_scale_config MODULE ${kwin_scale_config_SRCS})
target_link_libraries(kwin_scale_config
Qt5::DBus
KF5::ConfigWidgets
KF5::I18n
KF5::Service
)
kcoreaddons_desktop_to_json(kwin_scale_config scale_config.desktop SERVICE_TYPES kcmodule.desktop)
install(
TARGETS
kwin_scale_config
DESTINATION
${PLUGIN_INSTALL_DIR}/kwin/effects/configs
)
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
// own
#include "scale.h"
// KConfigSkeleton
#include "scaleconfig.h"
// Qt
#include <QSet>
namespace KWin
{
static const QSet<QString> s_blacklist {
// The logout screen has to be animated only by the logout effect.
QStringLiteral("ksmserver ksmserver"),
// KDE Plasma splash screen has to be animated only by the login effect.
QStringLiteral("ksplashqml ksplashqml"),
QStringLiteral("ksplashsimple ksplashsimple"),
QStringLiteral("ksplashx ksplashx")
};
ScaleEffect::ScaleEffect()
{
initConfig<ScaleConfig>();
reconfigure(ReconfigureAll);
connect(effects, &EffectsHandler::windowAdded, this, &ScaleEffect::windowAdded);
connect(effects, &EffectsHandler::windowClosed, this, &ScaleEffect::windowClosed);
connect(effects, &EffectsHandler::windowDeleted, this, &ScaleEffect::windowDeleted);
connect(effects, &EffectsHandler::windowDataChanged, this, &ScaleEffect::windowDataChanged);
}
ScaleEffect::~ScaleEffect()
{
}
void ScaleEffect::reconfigure(ReconfigureFlags flags)
{
Q_UNUSED(flags)
ScaleConfig::self()->read();
m_duration = std::chrono::milliseconds(animationTime<ScaleConfig>(160));
m_inParams.scale.from = ScaleConfig::inScale();
m_inParams.scale.to = 1.0;
m_inParams.opacity.from = ScaleConfig::inOpacity();
m_inParams.opacity.to = 1.0;
m_outParams.scale.from = 1.0;
m_outParams.scale.to = ScaleConfig::outScale();
m_outParams.opacity.from = 1.0;
m_outParams.opacity.to = ScaleConfig::outOpacity();
}
void ScaleEffect::prePaintScreen(ScreenPrePaintData &data, int time)
{
const std::chrono::milliseconds delta(time);
auto animationIt = m_animations.begin();
while (animationIt != m_animations.end()) {
(*animationIt).update(delta);
++animationIt;
}
effects->prePaintScreen(data, time);
}
void ScaleEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time)
{
if (m_animations.contains(w)) {
data.setTransformed();
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE);
}
effects->prePaintWindow(w, data, time);
}
void ScaleEffect::paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data)
{
auto animationIt = m_animations.constFind(w);
if (animationIt == m_animations.constEnd()) {
effects->paintWindow(w, mask, region, data);
return;
}
const ScaleParams params = w->isDeleted() ? m_outParams : m_inParams;
const qreal t = (*animationIt).value();
const qreal scale = interpolate(params.scale.from, params.scale.to, t);
data.setXScale(scale);
data.setYScale(scale);
data.setXTranslation(0.5 * (1.0 - scale) * w->width());
data.setYTranslation(0.5 * (1.0 - scale) * w->height());
data.multiplyOpacity(interpolate(params.opacity.from, params.opacity.to, t));
effects->paintWindow(w, mask, region, data);
}
void ScaleEffect::postPaintScreen()
{
auto animationIt = m_animations.begin();
while (animationIt != m_animations.end()) {
EffectWindow *w = animationIt.key();
const QRect geo = w->expandedGeometry();
const ScaleParams params = w->isDeleted() ? m_outParams : m_inParams;
const qreal scale = qMax(params.scale.from, params.scale.to);
const QRect repaintRect(
geo.topLeft() + 0.5 * (1.0 - scale) * QPoint(geo.width(), geo.height()),
geo.size() * scale);
effects->addRepaint(repaintRect);
if ((*animationIt).done()) {
if (w->isDeleted()) {
w->unrefWindow();
} else {
w->setData(WindowForceBackgroundContrastRole, QVariant());
w->setData(WindowForceBlurRole, QVariant());
}
animationIt = m_animations.erase(animationIt);
} else {
++animationIt;
}
}
effects->postPaintScreen();
}
bool ScaleEffect::isActive() const
{
return !m_animations.isEmpty();
}
bool ScaleEffect::supported()
{
return effects->animationsSupported();
}
void ScaleEffect::windowAdded(EffectWindow *w)
{
if (effects->activeFullScreenEffect()) {
return;
}
if (!isScaleWindow(w)) {
return;
}
if (!w->isVisible()) {
return;
}
const void *addGrab = w->data(WindowAddedGrabRole).value<void*>();
if (addGrab && addGrab != this) {
return;
}
TimeLine &timeLine = m_animations[w];
timeLine.reset();
timeLine.setDirection(TimeLine::Forward);
timeLine.setDuration(m_duration);
timeLine.setEasingCurve(QEasingCurve::InCurve);
w->setData(WindowAddedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
w->setData(WindowForceBackgroundContrastRole, QVariant(true));
w->setData(WindowForceBlurRole, QVariant(true));
w->addRepaintFull();
}
void ScaleEffect::windowClosed(EffectWindow *w)
{
if (effects->activeFullScreenEffect()) {
return;
}
if (!isScaleWindow(w)) {
return;
}
if (!w->isVisible()) {
return;
}
const void *closeGrab = w->data(WindowClosedGrabRole).value<void*>();
if (closeGrab && closeGrab != this) {
return;
}
w->refWindow();
TimeLine &timeLine = m_animations[w];
timeLine.reset();
timeLine.setDirection(TimeLine::Forward);
timeLine.setDuration(m_duration);
timeLine.setEasingCurve(QEasingCurve::OutCurve);
w->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
w->setData(WindowForceBackgroundContrastRole, QVariant(true));
w->setData(WindowForceBlurRole, QVariant(true));
w->addRepaintFull();
}
void ScaleEffect::windowDeleted(EffectWindow *w)
{
m_animations.remove(w);
}
void ScaleEffect::windowDataChanged(EffectWindow *w, int role)
{
if (role != WindowAddedGrabRole && role != WindowClosedGrabRole) {
return;
}
if (w->data(role).value<void*>() == this) {
return;
}
auto animationIt = m_animations.find(w);
if (animationIt == m_animations.end()) {
return;
}
if (w->isDeleted() && role == WindowClosedGrabRole) {
w->unrefWindow();
}
m_animations.erase(animationIt);
w->setData(WindowForceBackgroundContrastRole, QVariant());
w->setData(WindowForceBlurRole, QVariant());
}
bool ScaleEffect::isScaleWindow(EffectWindow *w) const
{
// We don't want to animate most of plasmashell's windows, yet, some
// of them we want to, for example, Task Manager Settings window.
// The problem is that all those window share single window class.
// So, the only way to decide whether a window should be animated is
// to use a heuristic: if a window has decoration, then it's most
// likely a dialog or a settings window so we have to animate it.
if (w->windowClass() == QLatin1String("plasmashell plasmashell")) {
return w->hasDecoration();
}
if (s_blacklist.contains(w->windowClass())) {
return false;
}
if (w->hasDecoration()) {
return true;
}
if (!w->isManaged()) {
return false;
}
return w->isNormalWindow()
|| w->isDialog();
}
} // namespace KWin
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_SCALE_H
#define KWIN_SCALE_H
// kwineffects
#include <kwineffects.h>
namespace KWin
{
class ScaleEffect : public Effect
{
Q_OBJECT
Q_PROPERTY(int duration READ duration)
Q_PROPERTY(qreal inScale READ inScale)
Q_PROPERTY(qreal inOpacity READ inOpacity)
Q_PROPERTY(qreal outScale READ outScale)
Q_PROPERTY(qreal outOpacity READ outOpacity)
public:
ScaleEffect();
~ScaleEffect() override;
void reconfigure(ReconfigureFlags flags) override;
void prePaintScreen(ScreenPrePaintData &data, int time) override;
void prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time) override;
void paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) override;
void postPaintScreen() override;
bool isActive() const override;
int requestedEffectChainPosition() const override;
static bool supported();
int duration() const;
qreal inScale() const;
qreal inOpacity() const;
qreal outScale() const;
qreal outOpacity() const;
private Q_SLOTS:
void windowAdded(EffectWindow *w);
void windowClosed(EffectWindow *w);
void windowDeleted(EffectWindow *w);
void windowDataChanged(EffectWindow *w, int role);
private:
bool isScaleWindow(EffectWindow *w) const;
std::chrono::milliseconds m_duration;
QHash<EffectWindow*, TimeLine> m_animations;
struct ScaleParams {
struct {
qreal from;
qreal to;
} scale, opacity;
};
ScaleParams m_inParams;
ScaleParams m_outParams;
};
inline int ScaleEffect::requestedEffectChainPosition() const
{
return 50;
}
inline int ScaleEffect::duration() const
{
return m_duration.count();
}
inline qreal ScaleEffect::inScale() const
{
return m_inParams.scale.from;
}
inline qreal ScaleEffect::inOpacity() const
{
return m_inParams.opacity.from;
}
inline qreal ScaleEffect::outScale() const
{
return m_outParams.scale.to;
}
inline qreal ScaleEffect::outOpacity() const
{
return m_outParams.opacity.to;
}
} // namespace KWin
#endif
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile arg="true"/>
<group name="Effect-Scale">
<entry name="Duration" type="UInt">
<default>0</default>
</entry>
<entry name="InScale" type="Double">
<default>0.96</default>
</entry>
<entry name="InOpacity" type="Double">
<default>0.4</default>
<min>0.0</min>
<max>1.0</max>
</entry>
<entry name="OutScale" type="Double">
<default>0.96</default>
</entry>
<entry name="OutOpacity" type="Double">
<default>0.0</default>
<min>0.0</min>
<max>1.0</max>
</entry>
</group>
</kcfg>
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "scale_config.h"
// KConfigSkeleton
#include "scaleconfig.h"
#include <config-kwin.h>
#include <kwineffects_interface.h>
#include <KAboutData>
#include <KPluginFactory>
K_PLUGIN_FACTORY_WITH_JSON(ScaleEffectConfigFactory,
"scale_config.json",
registerPlugin<KWin::ScaleEffectConfig>();)
namespace KWin
{
ScaleEffectConfig::ScaleEffectConfig(QWidget *parent, const QVariantList &args)
: KCModule(KAboutData::pluginData(QStringLiteral("scale")), parent, args)
{
ui.setupUi(this);
ScaleConfig::instance(KWIN_CONFIG);
addConfig(ScaleConfig::self(), this);
load();
}
ScaleEffectConfig::~ScaleEffectConfig()
{
}
void ScaleEffectConfig::save()
{
KCModule::save();
OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
QStringLiteral("/Effects"),
QDBusConnection::sessionBus());
interface.reconfigureEffect(QStringLiteral("scale"));
}
} // namespace KWin
#include "scale_config.moc"
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KCModule
X-KDE-Library=kwin_scale_config
X-KDE-ParentComponents=scale
Name=Scale
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef SCALE_CONFIG_H
#define SCALE_CONFIG_H
#include "ui_scale_config.h"
#include <KCModule>
namespace KWin
{
class ScaleEffectConfig : public KCModule
{
Q_OBJECT
public:
explicit ScaleEffectConfig(QWidget *parent = nullptr, const QVariantList &args = QVariantList());
~ScaleEffectConfig() override;
void save() override;
private:
::Ui::ScaleEffectConfig ui;
};