565b4ed6a3
Instead of each effect, which needs to announce support, having custom code to create a property and set it on the root window, there is now a common API in EffectsHandler to take care of this. The methods takes care of creating the atom if it has not already done and set the property on the root window. Furthermore it allows multiple effects to announce the same property without getting in conflict with each other. As a further convenience the property is automatically removed when the effect is unloaded, so less things an effect author has to care about. REVIEW: 107815
180 lines
5.3 KiB
C++
180 lines
5.3 KiB
C++
/********************************************************************
|
|
KWin - the KDE window manager
|
|
This file is part of the KDE project.
|
|
|
|
Copyright (C) 2010 Andreas Demmer <ademmer@opensuse.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/>.
|
|
*********************************************************************/
|
|
|
|
#include "dashboard.h"
|
|
// KConfigSkeleton
|
|
#include "dashboardconfig.h"
|
|
|
|
#include <KDE/KConfigGroup>
|
|
|
|
namespace KWin
|
|
{
|
|
KWIN_EFFECT(dashboard, DashboardEffect)
|
|
|
|
DashboardEffect::DashboardEffect()
|
|
: transformWindow(false)
|
|
, retransformWindow(false)
|
|
, activateAnimation(false)
|
|
, deactivateAnimation(false)
|
|
, window(NULL)
|
|
{
|
|
// TODO: better namespacing for atoms
|
|
atom = effects->announceSupportProperty("_WM_EFFECT_KDE_DASHBOARD", this);
|
|
|
|
// read settings
|
|
reconfigure(ReconfigureAll);
|
|
connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*)));
|
|
connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*)));
|
|
connect(effects, SIGNAL(windowActivated(KWin::EffectWindow*)), this, SLOT(slotWindowActivated(KWin::EffectWindow*)));
|
|
}
|
|
|
|
DashboardEffect::~DashboardEffect()
|
|
{
|
|
}
|
|
|
|
void DashboardEffect::reconfigure(ReconfigureFlags)
|
|
{
|
|
brightness = DashboardConfig::brightness()/ 100.0;
|
|
saturation = DashboardConfig::saturation()/ 100.0;
|
|
blur = DashboardConfig::blur();
|
|
|
|
timeline.setDuration(animationTime<DashboardConfig>(500));
|
|
}
|
|
|
|
void DashboardEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
{
|
|
if (transformWindow && (w != window) && w->isManaged() && !isDashboard(w)) {
|
|
// dashboard active, transform other windows
|
|
data.multiplyBrightness((1 - ((1.0 - brightness) * timeline.currentValue())));
|
|
data.multiplySaturation((1 - ((1.0 - saturation) * timeline.currentValue())));
|
|
}
|
|
|
|
else if (transformWindow && (w == window) && w->isManaged()) {
|
|
// transform dashboard
|
|
if ((timeline.currentValue() * 2) <= 1) {
|
|
data.multiplyOpacity(timeline.currentValue() * 2);
|
|
}
|
|
}
|
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
}
|
|
|
|
void DashboardEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
{
|
|
if (transformWindow) {
|
|
if (activateAnimation)
|
|
timeline.setCurrentTime(timeline.currentTime() + time);
|
|
if (deactivateAnimation)
|
|
timeline.setCurrentTime(timeline.currentTime() - time);
|
|
}
|
|
effects->prePaintScreen(data, time);
|
|
}
|
|
|
|
void DashboardEffect::postPaintScreen()
|
|
{
|
|
if (transformWindow) {
|
|
if (retransformWindow) {
|
|
retransformWindow = false;
|
|
transformWindow = false;
|
|
effects->addRepaintFull();
|
|
window = NULL;
|
|
effects->setActiveFullScreenEffect(0);
|
|
}
|
|
|
|
if (activateAnimation) {
|
|
if (timeline.currentValue() == 1.0)
|
|
activateAnimation = false;
|
|
|
|
effects->addRepaintFull();
|
|
}
|
|
|
|
if (deactivateAnimation) {
|
|
if (timeline.currentValue() == 0.0) {
|
|
deactivateAnimation = false;
|
|
transformWindow = false;
|
|
window = NULL;
|
|
effects->setActiveFullScreenEffect(0);
|
|
}
|
|
|
|
effects->addRepaintFull();
|
|
}
|
|
}
|
|
|
|
effects->postPaintScreen();
|
|
}
|
|
|
|
bool DashboardEffect::isDashboard(EffectWindow *w)
|
|
{
|
|
return w->windowRole() == "plasma-dashboard";
|
|
}
|
|
|
|
void DashboardEffect::slotWindowActivated(EffectWindow *w)
|
|
{
|
|
if (!w)
|
|
return;
|
|
|
|
// apply effect on dashboard activation
|
|
if (isDashboard(w)) {
|
|
effects->setActiveFullScreenEffect(this);
|
|
transformWindow = true;
|
|
window = w;
|
|
|
|
effects->addRepaintFull();
|
|
} else {
|
|
if (transformWindow) {
|
|
retransformWindow = true;
|
|
effects->addRepaintFull();
|
|
}
|
|
}
|
|
}
|
|
|
|
void DashboardEffect::slotWindowAdded(EffectWindow* w)
|
|
{
|
|
if (isDashboard(w)) {
|
|
// Tell other windowAdded() effects to ignore this window
|
|
w->setData(WindowAddedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
|
|
if (blur) {
|
|
w->setData(WindowBlurBehindRole, w->geometry());
|
|
w->setData(WindowForceBlurRole, QVariant(true));
|
|
}
|
|
|
|
activateAnimation = true;
|
|
deactivateAnimation = false;
|
|
timeline.setCurrentTime(0);
|
|
|
|
w->addRepaintFull();
|
|
}
|
|
}
|
|
|
|
void DashboardEffect::slotWindowClosed(EffectWindow* w)
|
|
{
|
|
if (isDashboard(w)) {
|
|
// Tell other windowClosed() effects to ignore this window
|
|
w->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
|
|
w->addRepaintFull();
|
|
}
|
|
}
|
|
|
|
bool DashboardEffect::isActive() const
|
|
{
|
|
return transformWindow;
|
|
}
|
|
|
|
} // namespace
|