kwin/effects/dashboard/dashboard.cpp

201 lines
5.9 KiB
C++
Raw Normal View History

/********************************************************************
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"
#include <KDE/KConfigGroup>
namespace KWin
{
KWIN_EFFECT(dashboard, DashboardEffect)
DashboardEffect::DashboardEffect()
2011-01-30 14:34:42 +00:00
: transformWindow(false)
2011-05-01 12:57:01 +00:00
, retransformWindow(false)
2011-01-30 14:34:42 +00:00
, activateAnimation(false)
, deactivateAnimation(false)
, window(NULL)
2011-01-30 14:34:42 +00:00
{
// propagate that the effect is loaded
propagate();
// 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*)));
2011-01-30 14:34:42 +00:00
}
DashboardEffect::~DashboardEffect()
2011-01-30 14:34:42 +00:00
{
unpropagate();
2011-01-30 14:34:42 +00:00
}
void DashboardEffect::propagate()
2011-01-30 14:34:42 +00:00
{
// TODO: better namespacing for atoms
2011-01-30 14:34:42 +00:00
atom = XInternAtom(display(), "_WM_EFFECT_KDE_DASHBOARD", false);
effects->registerPropertyType(atom, true);
// TODO: maybe not the best way to propagate the loaded effect
unsigned char dummy = 0;
2011-01-30 14:34:42 +00:00
XChangeProperty(display(), rootWindow(), atom, atom, 8, PropModeReplace, &dummy, 1);
}
void DashboardEffect::unpropagate()
2011-01-30 14:34:42 +00:00
{
effects->registerPropertyType(atom, false);
XDeleteProperty(display(), rootWindow(), atom);
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void DashboardEffect::reconfigure(ReconfigureFlags)
{
// read settings again
KConfigGroup config = EffectsHandler::effectConfig("Dashboard");
brightness = qreal(config.readEntry<int>("Brightness", 50)) / 100.0;
saturation = qreal(config.readEntry<int>("Saturation", 50)) / 100.0;
duration = config.readEntry<int>("Duration", 500);
blur = config.readEntry("Blur", false);
timeline.setDuration(animationTime(duration));
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
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())));
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
else if (transformWindow && (w == window) && w->isManaged()) {
// transform dashboard
if ((timeline.currentValue() * 2) <= 1) {
data.multiplyOpacity(timeline.currentValue() * 2);
}
}
2011-01-30 14:34:42 +00:00
effects->paintWindow(w, mask, region, data);
}
void DashboardEffect::prePaintScreen(ScreenPrePaintData& data, int time)
{
if (transformWindow) {
if (activateAnimation)
timeline.setCurrentTime(timeline.currentTime() + time);
2011-01-30 14:34:42 +00:00
if (deactivateAnimation)
timeline.setCurrentTime(timeline.currentTime() - time);
}
2011-01-30 14:34:42 +00:00
effects->prePaintScreen(data, time);
}
void DashboardEffect::postPaintScreen()
2011-01-30 14:34:42 +00:00
{
if (transformWindow) {
if (retransformWindow) {
retransformWindow = false;
transformWindow = false;
effects->addRepaintFull();
window = NULL;
2011-01-30 14:34:42 +00:00
effects->setActiveFullScreenEffect(0);
}
2011-01-30 14:34:42 +00:00
if (activateAnimation) {
if (timeline.currentValue() == 1.0)
activateAnimation = false;
effects->addRepaintFull();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
if (deactivateAnimation) {
if (timeline.currentValue() == 0.0) {
deactivateAnimation = false;
transformWindow = false;
window = NULL;
2011-01-30 14:34:42 +00:00
effects->setActiveFullScreenEffect(0);
}
effects->addRepaintFull();
}
2011-01-30 14:34:42 +00:00
}
effects->postPaintScreen();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
bool DashboardEffect::isDashboard(EffectWindow *w)
{
return w->windowRole() == "plasma-dashboard";
2011-01-30 14:34:42 +00:00
}
void DashboardEffect::slotWindowActivated(EffectWindow *w)
2011-01-30 14:34:42 +00:00
{
if (!w)
return;
// apply effect on dashboard activation
2011-01-30 14:34:42 +00:00
if (isDashboard(w)) {
effects->setActiveFullScreenEffect(this);
transformWindow = true;
window = w;
effects->addRepaintFull();
2011-01-30 14:34:42 +00:00
} else {
if (transformWindow) {
retransformWindow = true;
effects->addRepaintFull();
}
2011-01-30 14:34:42 +00:00
}
}
void DashboardEffect::slotWindowAdded(EffectWindow* w)
2011-01-30 14:34:42 +00:00
{
if (isDashboard(w)) {
// Tell other windowAdded() effects to ignore this window
2011-01-30 14:34:42 +00:00
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();
}
2011-01-30 14:34:42 +00:00
}
void DashboardEffect::slotWindowClosed(EffectWindow* w)
2011-01-30 14:34:42 +00:00
{
if (isDashboard(w)) {
// Tell other windowClosed() effects to ignore this window
2011-01-30 14:34:42 +00:00
w->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
w->addRepaintFull();
}
2011-01-30 14:34:42 +00:00
}
bool DashboardEffect::isActive() const
{
return transformWindow;
}
} // namespace