2010-07-23 19:52:20 +00:00
|
|
|
/********************************************************************
|
|
|
|
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"
|
2011-02-17 18:35:08 +00:00
|
|
|
#include <KDE/KConfigGroup>
|
2010-07-23 19:52:20 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
KWIN_EFFECT(dashboard, DashboardEffect)
|
|
|
|
|
|
|
|
DashboardEffect::DashboardEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
: transformWindow(false)
|
|
|
|
, activateAnimation(false)
|
|
|
|
, deactivateAnimation(false)
|
|
|
|
{
|
2010-07-23 19:52:20 +00:00
|
|
|
// propagate that the effect is loaded
|
|
|
|
propagate();
|
|
|
|
|
|
|
|
// read settings
|
|
|
|
reconfigure(ReconfigureAll);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-07-23 19:52:20 +00:00
|
|
|
|
|
|
|
DashboardEffect::~DashboardEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-07-23 19:52:20 +00:00
|
|
|
unpropagate();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-07-23 19:52:20 +00:00
|
|
|
|
|
|
|
void DashboardEffect::propagate()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-07-23 19:52:20 +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);
|
2010-07-23 19:52:20 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
2010-07-23 19:52:20 +00:00
|
|
|
|
|
|
|
void DashboardEffect::unpropagate()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-07-23 19:52:20 +00:00
|
|
|
effects->registerPropertyType(atom, false);
|
|
|
|
XDeleteProperty(display(), rootWindow(), atom);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-07-23 19:52:20 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DashboardEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2010-07-23 19:52:20 +00:00
|
|
|
// read settings again
|
|
|
|
KConfigGroup config = EffectsHandler::effectConfig("Dashboard");
|
|
|
|
|
|
|
|
brightness = config.readEntry("Brightness", "50");
|
|
|
|
saturation = config.readEntry("Saturation", "50");
|
2010-10-20 06:33:55 +00:00
|
|
|
duration = config.readEntry("Duration", "500");
|
|
|
|
|
2010-07-23 19:52:20 +00:00
|
|
|
blur = config.readEntry("Blur", false);
|
2010-10-20 06:33:55 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
timeline.setDuration(animationTime(duration.toInt()));
|
|
|
|
}
|
2010-07-23 19:52:20 +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)) {
|
2010-10-20 06:33:55 +00:00
|
|
|
brightnessDelta = (1 - (brightness.toDouble() / 100));
|
|
|
|
saturationDelta = (1 - (saturation.toDouble() / 100));
|
|
|
|
|
2010-07-23 19:52:20 +00:00
|
|
|
// dashboard active, transform other windows
|
2010-10-20 06:33:55 +00:00
|
|
|
data.brightness *= (1 - (brightnessDelta * timeline.value()));
|
|
|
|
data.saturation *= (1 - (saturationDelta * timeline.value()));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-07-23 19:52:20 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
else if (transformWindow && (w == window) && w->isManaged()) {
|
2010-11-07 12:32:08 +00:00
|
|
|
// transform dashboard
|
2011-01-30 14:34:42 +00:00
|
|
|
if ((timeline.value() * 2) <= 1) {
|
2010-10-21 15:07:34 +00:00
|
|
|
data.opacity *= timeline.value() * 2;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2010-10-21 15:07:34 +00:00
|
|
|
data.opacity *= 1;
|
|
|
|
}
|
2010-07-23 19:52:20 +00:00
|
|
|
}
|
|
|
|
|
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.addTime(time);
|
|
|
|
if (deactivateAnimation)
|
|
|
|
timeline.removeTime(time);
|
2010-10-20 06:33:55 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
2010-10-20 06:33:55 +00:00
|
|
|
|
2010-07-23 19:52:20 +00:00
|
|
|
void DashboardEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (transformWindow) {
|
|
|
|
if (retransformWindow) {
|
2010-07-23 19:52:20 +00:00
|
|
|
retransformWindow = false;
|
|
|
|
transformWindow = false;
|
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->setActiveFullScreenEffect(0);
|
|
|
|
}
|
2010-10-20 06:33:55 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (activateAnimation) {
|
|
|
|
if (timeline.value() == 1.0)
|
2010-10-20 06:33:55 +00:00
|
|
|
activateAnimation = false;
|
|
|
|
|
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-20 06:33:55 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (deactivateAnimation) {
|
|
|
|
if (timeline.value() == 0.0) {
|
2010-10-20 06:33:55 +00:00
|
|
|
deactivateAnimation = false;
|
|
|
|
transformWindow = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->setActiveFullScreenEffect(0);
|
|
|
|
}
|
2010-10-20 06:33:55 +00:00
|
|
|
|
|
|
|
effects->addRepaintFull();
|
2010-07-23 19:52:20 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-07-23 19:52:20 +00:00
|
|
|
|
|
|
|
effects->postPaintScreen();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-07-23 19:52:20 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool DashboardEffect::isDashboard(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (w->windowClass() == "dashboard dashboard") {
|
2010-07-23 19:52:20 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2010-07-23 19:52:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-07-23 19:52:20 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DashboardEffect::windowActivated(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (!w)
|
2010-07-23 19:52:20 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// apply effect on dashboard activation
|
2011-01-30 14:34:42 +00:00
|
|
|
if (isDashboard(w)) {
|
|
|
|
effects->setActiveFullScreenEffect(this);
|
2010-07-23 19:52:20 +00:00
|
|
|
transformWindow = true;
|
|
|
|
window = w;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (blur) {
|
|
|
|
w->setData(WindowBlurBehindRole, w->geometry());
|
|
|
|
}
|
2010-07-23 19:52:20 +00:00
|
|
|
|
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
if (transformWindow) {
|
2010-07-23 19:52:20 +00:00
|
|
|
retransformWindow = true;
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-23 19:52:20 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DashboardEffect::windowAdded(EffectWindow* w)
|
|
|
|
{
|
|
|
|
propertyNotify(w, atom);
|
2010-08-11 09:25:25 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (isDashboard(w)) {
|
2010-11-07 12:32:08 +00:00
|
|
|
// 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)));
|
2010-10-20 06:33:55 +00:00
|
|
|
|
|
|
|
activateAnimation = true;
|
|
|
|
deactivateAnimation = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
timeline.setProgress(0.0);
|
2010-10-20 06:33:55 +00:00
|
|
|
|
2010-11-07 12:32:08 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-07 12:32:08 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DashboardEffect::windowClosed(EffectWindow* w)
|
|
|
|
{
|
|
|
|
propertyNotify(w, atom);
|
2010-11-07 12:32:08 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (isDashboard(w)) {
|
2010-11-07 12:32:08 +00:00
|
|
|
// 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)));
|
2010-11-07 12:32:08 +00:00
|
|
|
w->addRepaintFull();
|
2010-08-11 09:25:25 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-11 09:25:25 +00:00
|
|
|
|
2010-07-23 19:52:20 +00:00
|
|
|
} // namespace
|