From 1fd779695f59a967aa4b09f30d87a88503a79fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 3 Jun 2013 15:05:22 +0200 Subject: [PATCH] Rewrite of dialog parent effect in JavaScript REVIEW: 110802 --- effects/CMakeLists.txt | 2 +- effects/dialogparent/CMakeLists.txt | 13 +- effects/dialogparent/dialogparent.cpp | 103 -------------- effects/dialogparent/dialogparent.h | 69 ---------- effects/dialogparent/package/CMakeLists.txt | 6 + .../package/contents/code/main.js | 126 ++++++++++++++++++ .../metadata.desktop} | 8 +- 7 files changed, 139 insertions(+), 188 deletions(-) delete mode 100644 effects/dialogparent/dialogparent.cpp delete mode 100644 effects/dialogparent/dialogparent.h create mode 100644 effects/dialogparent/package/CMakeLists.txt create mode 100644 effects/dialogparent/package/contents/code/main.js rename effects/dialogparent/{dialogparent.desktop => package/metadata.desktop} (97%) diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index cdd26577b3..b81c349f04 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -97,6 +97,7 @@ endif() set( kwin4_effect_include_directories ) # scripted effects +add_subdirectory( dialogparent ) add_subdirectory( fade ) add_subdirectory( login ) @@ -111,7 +112,6 @@ endif() # Built-in effects go here # Common effects -include( dialogparent/CMakeLists.txt ) include( kscreen/CMakeLists.txt ) include( presentwindows/CMakeLists.txt ) include( screenedge/CMakeLists.txt ) diff --git a/effects/dialogparent/CMakeLists.txt b/effects/dialogparent/CMakeLists.txt index ab626750de..1242620d48 100644 --- a/effects/dialogparent/CMakeLists.txt +++ b/effects/dialogparent/CMakeLists.txt @@ -1,12 +1 @@ -####################################### -# Effect - -# Source files -set( kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources} - dialogparent/dialogparent.cpp - ) - -# .desktop files -install( FILES - dialogparent/dialogparent.desktop - DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) +add_subdirectory(package) diff --git a/effects/dialogparent/dialogparent.cpp b/effects/dialogparent/dialogparent.cpp deleted file mode 100644 index de9ab52f3e..0000000000 --- a/effects/dialogparent/dialogparent.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************** - KWin - the KDE window manager - This file is part of the KDE project. - -Copyright (C) 2006 Rivo Laks -Copyright (C) 2011 Thomas Lübking - -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 . -*********************************************************************/ - -#include "dialogparent.h" - -namespace KWin -{ - -KWIN_EFFECT(dialogparent, DialogParentEffect) - -DialogParentEffect::DialogParentEffect() -{ - reconfigure(ReconfigureAll); - connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*))); - connect(effects, SIGNAL(windowActivated(KWin::EffectWindow*)), this, SLOT(slotWindowActivated(KWin::EffectWindow*))); -} - -void DialogParentEffect::reconfigure(ReconfigureFlags) -{ - // How long does it take for the effect to get it's full strength (in ms) - changeTime = animationTime(300); -} - -void DialogParentEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time) -{ - QMap::iterator it = effectStrength.find(w); - if (it != effectStrength.end()) { - if (!w->findModal()) { - *it -= time/changeTime; - if (*it <= 0.0f) - effectStrength.erase(it); - } - else if (*it < 1.0f) - *it = qMin(1.0f, *it + time/changeTime); - } - effects->prePaintWindow(w, data, time); -} - -void DialogParentEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) -{ - const float s = effectStrength.value(w, 0.0); - if (s > 0.0f) { - data.multiplyBrightness((1.0f - 0.4*s)); // [1.0; 0.6] - data.multiplySaturation((1.0f - 0.6*s)); // [1.0; 0.4] - } - effects->paintWindow(w, mask, region, data); -} - -void DialogParentEffect::postPaintWindow(EffectWindow* w) -{ - const float s = effectStrength.value(w, 0.0); - if (s > 0.0f && s < 1.0f) // not done yet - w->addRepaintFull(); - - effects->postPaintWindow( w ); -} - -void DialogParentEffect::slotWindowActivated(EffectWindow* w) -{ - if (w && w->isModal()) { - EffectWindowList mainwindows = w->mainWindows(); - foreach (EffectWindow* parent, mainwindows) { - if (!effectStrength.contains(parent)) - effectStrength[parent] = 0.0; - parent->addRepaintFull(); - } - } -} - -void DialogParentEffect::slotWindowClosed(EffectWindow* w) -{ - if (w && w->isModal()) { - EffectWindowList mainwindows = w->mainWindows(); - foreach(EffectWindow* parent, mainwindows) - parent->addRepaintFull(); // brighten up - } - effectStrength.remove(w); -} - -bool DialogParentEffect::isActive() const -{ - return !effectStrength.isEmpty(); -} - -} // namespace diff --git a/effects/dialogparent/dialogparent.h b/effects/dialogparent/dialogparent.h deleted file mode 100644 index d439cc63c9..0000000000 --- a/effects/dialogparent/dialogparent.h +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************** - KWin - the KDE window manager - This file is part of the KDE project. - -Copyright (C) 2006 Rivo Laks - -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 . -*********************************************************************/ - -#ifndef KWIN_DIALOGPARENT_H -#define KWIN_DIALOGPARENT_H - -// Include with base class for effects. -#include - - -namespace KWin -{ - -/** - * An effect which changes saturation and brighness of windows which have - * active modal dialogs. - * This should make the dialog seem more important and emphasize that the - * window is inactive until the dialog is closed. - **/ -class DialogParentEffect - : public Effect -{ - Q_OBJECT - Q_PROPERTY(int changeTime READ configuredChangeTime) -public: - DialogParentEffect(); - virtual void reconfigure(ReconfigureFlags); - - virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time); - virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data); - virtual void postPaintWindow(EffectWindow* w); - - virtual bool isActive() const; - - // for properties - int configuredChangeTime() const { - return changeTime; - } -public Q_SLOTS: - void slotWindowClosed(KWin::EffectWindow *c); - void slotWindowActivated(KWin::EffectWindow *c); -protected: - bool hasModalWindow(EffectWindow* t); -private: - // The progress of the fading. - QMap effectStrength; - float changeTime; -}; - -} // namespace - -#endif diff --git a/effects/dialogparent/package/CMakeLists.txt b/effects/dialogparent/package/CMakeLists.txt new file mode 100644 index 0000000000..44c284a9c8 --- /dev/null +++ b/effects/dialogparent/package/CMakeLists.txt @@ -0,0 +1,6 @@ +install(DIRECTORY contents DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/effects/kwin4_effect_dialogparent) +install(FILES metadata.desktop DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/effects/kwin4_effect_dialogparent) + +install(FILES metadata.desktop + DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} + RENAME kwin4_effect_dialogparent.desktop) diff --git a/effects/dialogparent/package/contents/code/main.js b/effects/dialogparent/package/contents/code/main.js new file mode 100644 index 0000000000..e4c2f70a77 --- /dev/null +++ b/effects/dialogparent/package/contents/code/main.js @@ -0,0 +1,126 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + + Copyright (C) 2013 Martin Gräßlin + +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 . +*********************************************************************/ +/*global effect, effects, animate, cancel, set, animationTime, Effect, QEasingCurve */ +/*jslint continue: true */ +var dialogParentEffect = { + duration: animationTime(300), + windowAdded: function (window) { + "use strict"; + var mainWindows, i, w; + if (window === null || window.modal === false) { + return; + } + mainWindows = window.mainWindows(); + for (i = 0; i < mainWindows.length; i += 1) { + w = mainWindows[i]; + if (w.dialogParentAnimation !== undefined) { + continue; + } + dialogParentEffect.startAnimation(w, dialogParentEffect.duration); + } + }, + startAnimation: function (window, duration) { + "use strict"; + if (window.visible === false) { + return; + } + window.dialogParentAnimation = set({ + window: window, + duration: duration, + animations: [{ + type: Effect.Saturation, + to: 0.4 + }, { + type: Effect.Brightness, + to: 0.6 + }] + }); + }, + windowClosed: function (window) { + "use strict"; + var mainWindows, i, w; + dialogParentEffect.cancelAnimation(window); + if (window.modal === false) { + return; + } + mainWindows = window.mainWindows(); + for (i = 0; i < mainWindows.length; i += 1) { + w = mainWindows[i]; + if (w.dialogParentAnimation === undefined) { + continue; + } + cancel(w.dialogParentAnimation); + w.dialogParentAnimation = undefined; + animate({ + window: w, + duration: dialogParentEffect.duration, + animations: [{ + type: Effect.Saturation, + from: 0.4, + to: 1.0 + }, { + type: Effect.Brightness, + from: 0.6, + to: 1.0 + }] + }); + } + }, + cancelAnimation: function (window) { + "use strict"; + if (window.dialogParentAnimation !== undefined) { + cancel(window.dialogParentAnimation); + window.dialogParentAnimation = undefined; + } + }, + desktopChanged: function () { + "use strict"; + var i, windows, window; + windows = effects.stackingOrder; + for (i = 0; i < windows.length; i += 1) { + window = windows[i]; + dialogParentEffect.cancelAnimation(window); + dialogParentEffect.restartAnimation(window); + } + }, + restartAnimation: function (window) { + "use strict"; + if (window === null || window.findModal() === null) { + return; + } + dialogParentEffect.startAnimation(window, 1); + }, + init: function () { + "use strict"; + var i, windows; + effects.windowActivated.connect(dialogParentEffect.windowAdded); + effects.windowClosed.connect(dialogParentEffect.windowClosed); + effects.windowMinimized.connect(dialogParentEffect.cancelAnimation); + effects.windowUnminimized.connect(dialogParentEffect.restartAnimation); + effects['desktopChanged(int,int)'].connect(dialogParentEffect.desktopChanged); + + // start animation + windows = effects.stackingOrder; + for (i = 0; i < windows.length; i += 1) { + dialogParentEffect.restartAnimation(windows[i]); + } + } +}; +dialogParentEffect.init(); diff --git a/effects/dialogparent/dialogparent.desktop b/effects/dialogparent/package/metadata.desktop similarity index 97% rename from effects/dialogparent/dialogparent.desktop rename to effects/dialogparent/package/metadata.desktop index 7cf67e8f91..c0beeef36f 100644 --- a/effects/dialogparent/dialogparent.desktop +++ b/effects/dialogparent/package/metadata.desktop @@ -146,14 +146,16 @@ Comment[zh_CN]=将当前激活对话框的父窗口变暗 Comment[zh_TW]=將目前對話框的父視窗變暗 Type=Service +X-Plasma-API=javascript +X-Plasma-MainScript=code/main.js X-KDE-ServiceTypes=KWin/Effect -X-KDE-PluginInfo-Author=Rivo Laks -X-KDE-PluginInfo-Email=rivolaks@hot.ee +X-KDE-PluginInfo-Author=Rivo Laks, Martin Gräßlin +X-KDE-PluginInfo-Email=rivolaks@hot.ee, mgraesslin@kde.org X-KDE-PluginInfo-Name=kwin4_effect_dialogparent X-KDE-PluginInfo-Version=0.1.0 X-KDE-PluginInfo-Category=Focus X-KDE-PluginInfo-Depends= X-KDE-PluginInfo-License=GPL X-KDE-PluginInfo-EnabledByDefault=true -X-KDE-Library=kwin4_effect_builtins +X-KDE-Library=kwin4_effect_dialogparent X-KDE-Ordering=70