2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2009-02-05 15:35:38 +00:00
|
|
|
#include "translucency.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-10-22 13:34:26 +00:00
|
|
|
#include <kconfiggroup.h>
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(translucency, TranslucencyEffect)
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2009-02-05 15:35:38 +00:00
|
|
|
TranslucencyEffect::TranslucencyEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
: fadeout(NULL)
|
|
|
|
, current(NULL)
|
|
|
|
, previous(NULL)
|
|
|
|
{
|
|
|
|
reconfigure(ReconfigureAll);
|
2008-10-02 09:27:32 +00:00
|
|
|
active = effects->activeWindow();
|
2011-02-27 09:05:04 +00:00
|
|
|
connect(effects, SIGNAL(windowActivated(EffectWindow*)), this, SLOT(slotWindowActivated(EffectWindow*)));
|
2011-02-28 20:03:13 +00:00
|
|
|
connect(effects, SIGNAL(windowUserMovedResized(EffectWindow*,bool,bool)), this, SLOT(slotWindowUserMovedResized(EffectWindow*,bool,bool)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-10-02 09:27:32 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TranslucencyEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2009-02-05 15:35:38 +00:00
|
|
|
KConfigGroup conf = effects->effectConfig("Translucency");
|
2011-01-30 14:34:42 +00:00
|
|
|
decoration = conf.readEntry("Decoration", 1.0);
|
|
|
|
moveresize = conf.readEntry("MoveResize", 0.8);
|
|
|
|
dialogs = conf.readEntry("Dialogs", 1.0);
|
|
|
|
inactive = conf.readEntry("Inactive", 1.0);
|
|
|
|
comboboxpopups = conf.readEntry("ComboboxPopups", 1.0);
|
|
|
|
menus = conf.readEntry("Menus", 1.0);
|
|
|
|
individualmenuconfig = conf.readEntry("IndividualMenuConfig", false);
|
|
|
|
if (individualmenuconfig) {
|
|
|
|
dropdownmenus = conf.readEntry("DropdownMenus", 1.0);
|
|
|
|
popupmenus = conf.readEntry("PopupMenus", 1.0);
|
|
|
|
tornoffmenus = conf.readEntry("TornOffMenus", 1.0);
|
|
|
|
} else {
|
2008-04-06 10:19:26 +00:00
|
|
|
dropdownmenus = menus;
|
|
|
|
popupmenus = menus;
|
|
|
|
tornoffmenus = menus;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
moveresize_timeline.setCurveShape(TimeLine::EaseOutCurve);
|
|
|
|
moveresize_timeline.setDuration(animationTime(conf, "Duration", 800));
|
|
|
|
activeinactive_timeline.setCurveShape(TimeLine::EaseInOutCurve);
|
|
|
|
activeinactive_timeline.setDuration(animationTime(conf, "Duration", 800));
|
2008-12-15 07:02:07 +00:00
|
|
|
|
|
|
|
// Repaint the screen just in case the user changed the inactive opacity
|
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-07-19 10:07:49 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TranslucencyEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
2008-04-28 16:10:10 +00:00
|
|
|
moveresize_timeline.addTime(time);
|
|
|
|
activeinactive_timeline.addTime(time);
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (decoration != 1.0 && w->hasDecoration()) {
|
2007-07-19 10:07:49 +00:00
|
|
|
data.mask |= PAINT_WINDOW_TRANSLUCENT;
|
2007-07-19 13:32:46 +00:00
|
|
|
// don't clear PAINT_WINDOW_OPAQUE, contents are not affected
|
2011-01-30 14:34:42 +00:00
|
|
|
data.clip &= w->contentsRect().translated(w->pos()); // decoration cannot clip
|
|
|
|
}
|
|
|
|
if (inactive != 1.0 && isInactive(w))
|
2008-12-15 07:02:07 +00:00
|
|
|
data.setTranslucent();
|
2011-01-30 14:34:42 +00:00
|
|
|
if ((moveresize != 1.0 && (w->isUserMove() || w->isUserResize()))
|
|
|
|
|| (dialogs != 1.0 && w->isDialog())) {
|
2007-07-19 13:32:46 +00:00
|
|
|
data.setTranslucent();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if ((dropdownmenus != 1.0 && w->isDropdownMenu())
|
|
|
|
|| (popupmenus != 1.0 && w->isPopupMenu())
|
|
|
|
|| (tornoffmenus != 1.0 && w->isMenu())
|
|
|
|
|| (comboboxpopups != 1.0 && w->isComboBox())) {
|
2008-04-06 10:19:26 +00:00
|
|
|
data.setTranslucent();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TranslucencyEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
2008-04-28 16:10:10 +00:00
|
|
|
// We keep track of the windows that was last active so we know
|
|
|
|
// which one to fade out and which ones to paint as fully inactive
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w == active && w != current) {
|
2008-04-28 16:10:10 +00:00
|
|
|
previous = current;
|
|
|
|
current = w;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-04-28 16:10:10 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isDesktop() || w->isDock()) {
|
|
|
|
effects->paintWindow(w, mask, region, data);
|
2008-04-28 16:10:10 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-04-28 16:10:10 +00:00
|
|
|
// Handling active and inactive windows
|
2011-01-30 14:34:42 +00:00
|
|
|
if (inactive != 1.0 && isInactive(w)) {
|
2008-01-14 15:34:39 +00:00
|
|
|
data.opacity *= inactive;
|
2008-04-28 16:10:10 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w == previous) {
|
2008-04-28 16:10:10 +00:00
|
|
|
data.opacity *= (inactive + ((1.0 - inactive) * (1.0 - activeinactive_timeline.value())));
|
2011-01-30 14:34:42 +00:00
|
|
|
if (activeinactive_timeline.value() < 1.0)
|
2008-04-28 16:10:10 +00:00
|
|
|
w->addRepaintFull();
|
2008-01-14 15:34:39 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-28 16:10:10 +00:00
|
|
|
// Fading in
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!isInactive(w) && !w->isDesktop()) {
|
2008-04-28 16:10:10 +00:00
|
|
|
data.opacity *= (inactive + ((1.0 - inactive) * activeinactive_timeline.value()));
|
2011-01-30 14:34:42 +00:00
|
|
|
if (activeinactive_timeline.value() < 1.0)
|
2008-04-28 16:10:10 +00:00
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-04-28 16:10:10 +00:00
|
|
|
// decoration and dialogs
|
2011-01-30 14:34:42 +00:00
|
|
|
if (decoration != 1.0 && w->hasDecoration())
|
2008-01-14 15:34:39 +00:00
|
|
|
data.decoration_opacity *= decoration;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (dialogs != 1.0 && w->isDialog())
|
2008-01-14 15:34:39 +00:00
|
|
|
data.opacity *= dialogs;
|
2008-04-28 16:10:10 +00:00
|
|
|
|
|
|
|
// Handling moving and resizing
|
2011-01-30 14:34:42 +00:00
|
|
|
if (moveresize != 1.0 && !w->isDesktop() && !w->isDock()) {
|
2008-04-28 16:10:10 +00:00
|
|
|
double progress = moveresize_timeline.value();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isUserMove() || w->isUserResize()) {
|
|
|
|
// Fading to translucent
|
|
|
|
data.opacity *= (moveresize + ((1.0 - moveresize) * (1.0 - progress)));
|
|
|
|
if (progress < 1.0 && progress > 0.0) {
|
2008-06-13 09:35:57 +00:00
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (fadeout != w)
|
2008-06-13 09:35:57 +00:00
|
|
|
fadeout = w;
|
2008-04-28 16:10:10 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
// Fading back to more opaque
|
|
|
|
if (w == fadeout && !w->isUserMove() && !w->isUserResize()) {
|
2008-04-28 16:10:10 +00:00
|
|
|
data.opacity *= (moveresize + ((1.0 - moveresize) * (progress)));
|
2011-01-30 14:34:42 +00:00
|
|
|
if (progress == 1.0 || progress == 0.0)
|
2008-04-28 16:10:10 +00:00
|
|
|
fadeout = NULL;
|
|
|
|
else
|
|
|
|
w->addRepaintFull();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-04-28 16:10:10 +00:00
|
|
|
|
2008-10-23 09:31:44 +00:00
|
|
|
// Menus and combos
|
2011-01-30 14:34:42 +00:00
|
|
|
if (dropdownmenus != 1.0 && w->isDropdownMenu())
|
2008-04-06 10:19:26 +00:00
|
|
|
data.opacity *= dropdownmenus;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (popupmenus != 1.0 && w->isPopupMenu())
|
2008-04-06 10:19:26 +00:00
|
|
|
data.opacity *= popupmenus;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (tornoffmenus != 1.0 && w->isMenu())
|
2008-04-06 10:19:26 +00:00
|
|
|
data.opacity *= tornoffmenus;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (comboboxpopups != 1.0 && w->isComboBox())
|
2008-04-06 10:19:26 +00:00
|
|
|
data.opacity *= comboboxpopups;
|
2008-04-28 16:10:10 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool TranslucencyEffect::isInactive(const EffectWindow* w) const
|
|
|
|
{
|
|
|
|
if (active == w || w->isDock() || !w->isManaged())
|
2008-01-14 15:34:39 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (NULL != active && NULL != active->group())
|
|
|
|
if (active->group() == w->group())
|
2008-01-14 15:34:39 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!w->isNormalWindow() && !w->isDialog() && !w->isDock())
|
2008-01-14 15:34:39 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-14 15:34:39 +00:00
|
|
|
|
2011-02-28 20:03:13 +00:00
|
|
|
void TranslucencyEffect::slotWindowUserMovedResized(EffectWindow* w, bool first, bool last)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (moveresize != 1.0 && (first || last)) {
|
2008-04-28 16:10:10 +00:00
|
|
|
moveresize_timeline.setProgress(0.0);
|
2007-04-29 17:35:43 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-02-27 09:05:04 +00:00
|
|
|
void TranslucencyEffect::slotWindowActivated(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (inactive != 1.0) {
|
2008-04-28 16:10:10 +00:00
|
|
|
activeinactive_timeline.setProgress(0.0);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (NULL != active && active != w) {
|
|
|
|
if ((NULL == w || w->group() != active->group()) &&
|
|
|
|
NULL != active->group()) {
|
2008-01-14 15:34:39 +00:00
|
|
|
// Active group has changed. so repaint old group
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (EffectWindow * tmp, active->group()->members())
|
|
|
|
tmp->addRepaintFull();
|
|
|
|
} else
|
2008-01-14 15:34:39 +00:00
|
|
|
active->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-14 15:34:39 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (NULL != w) {
|
|
|
|
if (NULL != w->group()) {
|
2008-01-14 15:34:39 +00:00
|
|
|
// Repaint windows in new group
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (EffectWindow * tmp, w->group()->members())
|
|
|
|
tmp->addRepaintFull();
|
|
|
|
} else
|
2008-01-14 15:34:39 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
active = w;
|
|
|
|
}
|
2008-01-14 15:34:39 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|