Rewrite of dialog parent effect in JavaScript

REVIEW: 110802
This commit is contained in:
Martin Gräßlin 2013-06-03 15:05:22 +02:00
parent a4ec610d23
commit 1fd779695f
7 changed files with 139 additions and 188 deletions

View file

@ -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 )

View file

@ -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)

View file

@ -1,103 +0,0 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Rivo Laks <rivolaks@hot.ee>
Copyright (C) 2011 Thomas Lübking <thomas.luebking@web.de>
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 "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<EffectWindow*, float>::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

View file

@ -1,69 +0,0 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Rivo Laks <rivolaks@hot.ee>
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_DIALOGPARENT_H
#define KWIN_DIALOGPARENT_H
// Include with base class for effects.
#include <kwineffects.h>
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<EffectWindow*, float> effectStrength;
float changeTime;
};
} // namespace
#endif

View file

@ -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)

View file

@ -0,0 +1,126 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
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/>.
*********************************************************************/
/*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();

View file

@ -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