From e14a0111651fbe460c1887572836dee78c48e87d Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Wed, 5 Aug 2020 22:33:01 +0200 Subject: [PATCH] [effects/fullscreen] Add effect that animates full screen changes Just a slightly altered copy of the maximize effect --- autotests/test_scripted_effectloader.cpp | 3 + effects/CMakeLists.txt | 1 + .../package/contents/code/fullscreen.js | 90 +++++++++++++++++++ effects/fullscreen/package/metadata.desktop | 18 ++++ 4 files changed, 112 insertions(+) create mode 100644 effects/fullscreen/package/contents/code/fullscreen.js create mode 100644 effects/fullscreen/package/metadata.desktop diff --git a/autotests/test_scripted_effectloader.cpp b/autotests/test_scripted_effectloader.cpp index d1deca4ef9..d0b72f5244 100644 --- a/autotests/test_scripted_effectloader.cpp +++ b/autotests/test_scripted_effectloader.cpp @@ -133,6 +133,7 @@ void TestScriptedEffectLoader::testHasEffect_data() QTest::newRow("FadeDesktop") << QStringLiteral("kwin4_effect_fadedesktop") << true; QTest::newRow("FadingPopups") << QStringLiteral("kwin4_effect_fadingpopups") << true; QTest::newRow("FrozenApp") << QStringLiteral("kwin4_effect_frozenapp") << true; + QTest::newRow("FullScreen") << QStringLiteral("kwin4_effect_fullscreen") << true; QTest::newRow("Login") << QStringLiteral("kwin4_effect_login") << true; QTest::newRow("Logout") << QStringLiteral("kwin4_effect_logout") << true; QTest::newRow("Maximize") << QStringLiteral("kwin4_effect_maximize") << true; @@ -205,6 +206,7 @@ void TestScriptedEffectLoader::testLoadEffect_data() QTest::newRow("FadeDesktop") << QStringLiteral("kwin4_effect_fadedesktop") << true; QTest::newRow("FadingPopups") << QStringLiteral("kwin4_effect_fadingpopups") << true; QTest::newRow("FrozenApp") << QStringLiteral("kwin4_effect_frozenapp") << true; + QTest::newRow("FullScreen") << QStringLiteral("kwin4_effect_fullscreen") << true; QTest::newRow("Login") << QStringLiteral("kwin4_effect_login") << true; QTest::newRow("Logout") << QStringLiteral("kwin4_effect_logout") << true; QTest::newRow("Maximize") << QStringLiteral("kwin4_effect_maximize") << true; @@ -364,6 +366,7 @@ void TestScriptedEffectLoader::testLoadAllEffects() plugins.writeEntry(kwin4 + QStringLiteral("fadedesktopEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("fadingpopupsEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("frozenappEnabled"), false); + plugins.writeEntry(kwin4 + QStringLiteral("fullscreenEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("loginEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("logoutEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("maximizeEnabled"), false); diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 0f2a0d48cc..ed3e06788c 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -164,6 +164,7 @@ install_scripted_effect(fade) install_scripted_effect(fadedesktop) install_scripted_effect(fadingpopups) install_scripted_effect(frozenapp) +install_scripted_effect(fullscreen) install_scripted_effect(login) install_scripted_effect(logout) install_scripted_effect(maximize) diff --git a/effects/fullscreen/package/contents/code/fullscreen.js b/effects/fullscreen/package/contents/code/fullscreen.js new file mode 100644 index 0000000000..778f0fb12e --- /dev/null +++ b/effects/fullscreen/package/contents/code/fullscreen.js @@ -0,0 +1,90 @@ +/* + This file is part of the KDE project. + + SPDX-FileCopyrightText: 2012 Martin Gräßlin + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +"use strict"; + +var fullScreenEffect = { + duration: animationTime(250), + loadConfig: function () { + fullScreenEffect.duration = animationTime(250); + }, + fullScreenChanged: function (window) { + if (!window.oldGeometry) { + return; + } + window.setData(Effect.WindowForceBlurRole, true); + var oldGeometry, newGeometry; + oldGeometry = window.oldGeometry; + newGeometry = window.geometry; + if (oldGeometry.width == newGeometry.width && oldGeometry.height == newGeometry.height) + oldGeometry = window.olderGeometry; + window.olderGeometry = window.oldGeometry; + window.oldGeometry = newGeometry; + window.fullScreenAnimation1 = animate({ + window: window, + duration: fullScreenEffect.duration, + animations: [{ + type: Effect.Size, + to: { + value1: newGeometry.width, + value2: newGeometry.height + }, + from: { + value1: oldGeometry.width, + value2: oldGeometry.height + } + }, { + type: Effect.Translation, + to: { + value1: 0, + value2: 0 + }, + from: { + value1: oldGeometry.x - newGeometry.x - (newGeometry.width / 2 - oldGeometry.width / 2), + value2: oldGeometry.y - newGeometry.y - (newGeometry.height / 2 - oldGeometry.height / 2) + } + }] + }); + if (!window.resize) { + window.fullScreenAnimation2 =animate({ + window: window, + duration: fullScreenEffect.duration, + animations: [{ + type: Effect.CrossFadePrevious, + to: 1.0, + from: 0.0 + }] + }); + } + }, + restoreForceBlurState: function(window) { + window.setData(Effect.WindowForceBlurRole, null); + }, + geometryChange: function (window, oldGeometry) { + if (window.fullScreenAnimation1) { + if (window.geometry.width != window.oldGeometry.width || + window.geometry.height != window.oldGeometry.height) { + cancel(window.fullScreenAnimation1); + delete window.fullScreenAnimation1; + if (window.fullScreenAnimation2) { + cancel(window.fullScreenAnimation2); + delete window.fullScreenAnimation2; + } + } + } + window.oldGeometry = window.geometry; + window.olderGeometry = oldGeometry; + }, + init: function () { + effect.configChanged.connect(fullScreenEffect.loadConfig); + effects.windowFrameGeometryChanged.connect(fullScreenEffect.geometryChange); + effects.windowFullScreenChanged.connect(fullScreenEffect.fullScreenChanged); + effect.animationEnded.connect(fullScreenEffect.restoreForceBlurState); + } +}; +fullScreenEffect.init(); diff --git a/effects/fullscreen/package/metadata.desktop b/effects/fullscreen/package/metadata.desktop new file mode 100644 index 0000000000..f1c5509a19 --- /dev/null +++ b/effects/fullscreen/package/metadata.desktop @@ -0,0 +1,18 @@ +[Desktop Entry] +Comment=Animation for a window going to and leaving full screen mode +Icon=preferences-system-windows-effect-fullscreen +Name=Full Screen +Type=Service +X-KDE-ParentApp= +X-KDE-PluginInfo-Author=Martin Gräßlin +X-KDE-PluginInfo-Category=Appearance +X-KDE-PluginInfo-Email=mgraesslin@kde.org +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-Name=kwin4_effect_fullscreen +X-KDE-PluginInfo-Version=1 +X-KDE-PluginInfo-Website= +X-KDE-ServiceTypes=KWin/Effect +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-Ordering=60 +X-Plasma-API=javascript +X-Plasma-MainScript=code/fullscreen.js