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"
|
2012-09-02 06:46:32 +00:00
|
|
|
// KConfigSkeleton
|
|
|
|
#include "translucencyconfig.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()
|
2012-09-05 19:35:36 +00:00
|
|
|
: m_activeDecorations(false)
|
2012-09-04 19:02:41 +00:00
|
|
|
, m_activeMoveResize(false)
|
|
|
|
, m_activeDialogs(false)
|
|
|
|
, m_activeInactive(false)
|
|
|
|
, m_activeCombobox(false)
|
|
|
|
, m_activeMenus(false)
|
|
|
|
, m_active(false)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
reconfigure(ReconfigureAll);
|
2008-10-02 09:27:32 +00:00
|
|
|
active = effects->activeWindow();
|
2012-01-29 11:29:24 +00:00
|
|
|
connect(effects, SIGNAL(windowActivated(KWin::EffectWindow*)), this, SLOT(slotWindowActivated(KWin::EffectWindow*)));
|
2012-09-04 19:02:41 +00:00
|
|
|
connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(checkIsActive()));
|
|
|
|
connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(checkIsActive()));
|
2012-01-29 11:29:24 +00:00
|
|
|
connect(effects, SIGNAL(windowStartUserMovedResized(KWin::EffectWindow*)), this, SLOT(slotWindowStartStopUserMovedResized(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowFinishUserMovedResized(KWin::EffectWindow*)), this, SLOT(slotWindowStartStopUserMovedResized(KWin::EffectWindow*)));
|
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)
|
|
|
|
{
|
2012-09-02 06:46:32 +00:00
|
|
|
TranslucencyConfig::self()->readConfig();
|
|
|
|
decoration = TranslucencyConfig::decoration()/100.0;
|
|
|
|
moveresize = TranslucencyConfig::moveResize()/100.0;
|
|
|
|
dialogs = TranslucencyConfig::dialogs()/100.0;
|
|
|
|
inactive = TranslucencyConfig::inactive()/100.0;
|
|
|
|
comboboxpopups = TranslucencyConfig::comboboxPopups()/100.0;
|
|
|
|
menus = TranslucencyConfig::menus()/100.0;
|
|
|
|
individualmenuconfig = TranslucencyConfig::individualMenuConfig();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (individualmenuconfig) {
|
2012-09-02 06:46:32 +00:00
|
|
|
dropdownmenus = TranslucencyConfig::dropdownMenus()/100.0;
|
|
|
|
popupmenus = TranslucencyConfig::popupMenus()/100.0;
|
|
|
|
tornoffmenus = TranslucencyConfig::tornOffMenus()/100.0;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-06 10:19:26 +00:00
|
|
|
dropdownmenus = menus;
|
|
|
|
popupmenus = menus;
|
|
|
|
tornoffmenus = menus;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-12-15 07:02:07 +00:00
|
|
|
|
2012-09-04 19:02:41 +00:00
|
|
|
m_activeDecorations = !qFuzzyCompare(decoration, 1.0);
|
|
|
|
m_activeMoveResize = !qFuzzyCompare(moveresize, 1.0);
|
|
|
|
m_activeDialogs = !qFuzzyCompare(dialogs, 1.0);
|
|
|
|
m_activeInactive = !qFuzzyCompare(inactive, 1.0);
|
|
|
|
m_activeCombobox = !qFuzzyCompare(comboboxpopups, 1.0);
|
|
|
|
m_activeMenus = !qFuzzyCompare(menus, 1.0);
|
|
|
|
if (!m_activeMenus && individualmenuconfig) {
|
|
|
|
m_activeMenus = !qFuzzyCompare(dropdownmenus, 1.0) ||
|
|
|
|
!qFuzzyCompare(popupmenus, 1.0) ||
|
|
|
|
!qFuzzyCompare(tornoffmenus, 1.0);
|
|
|
|
}
|
|
|
|
checkIsActive();
|
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
|
|
|
|
2012-09-04 19:02:41 +00:00
|
|
|
void TranslucencyEffect::checkIsActive()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-09-04 19:02:41 +00:00
|
|
|
m_active = m_activeDecorations ||
|
|
|
|
m_activeMoveResize ||
|
|
|
|
m_activeDialogs ||
|
|
|
|
m_activeInactive ||
|
|
|
|
m_activeCombobox ||
|
|
|
|
m_activeMenus;
|
|
|
|
if (!m_active) {
|
|
|
|
// all individual options are disabled, no window state can activate it
|
|
|
|
return;
|
2012-02-26 16:59:21 +00:00
|
|
|
}
|
2012-09-04 19:02:41 +00:00
|
|
|
if (m_activeDecorations) {
|
|
|
|
// we can assume that there is at least one decorated window, so the effect is active
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_activeInactive) {
|
|
|
|
// we can assume that there is at least one inactive window, so the effect is active
|
|
|
|
// TODO: maybe only if inactive window is not obscured?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// for all other options we go through the list of window and search for a Window being affected
|
|
|
|
bool activeDropdown, activePopup, activeTornoff;
|
|
|
|
activeDropdown = activePopup = activeTornoff = false;
|
|
|
|
if (individualmenuconfig) {
|
|
|
|
activeDropdown = !qFuzzyCompare(dropdownmenus, 1.0);
|
|
|
|
activePopup = !qFuzzyCompare(popupmenus, 1.0);
|
|
|
|
activeTornoff = !qFuzzyCompare(activeTornoff, 1.0);
|
|
|
|
}
|
|
|
|
foreach (EffectWindow *w, effects->stackingOrder()) {
|
|
|
|
if (w->isDeleted()) {
|
|
|
|
// ignore deleted windows
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (m_activeMoveResize && (w->isUserMove() || w->isUserResize())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_activeDialogs && w->isDialog()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_activeCombobox && w->isComboBox()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_activeMenus) {
|
|
|
|
if (individualmenuconfig) {
|
|
|
|
if (activeDropdown && w->isDropdownMenu()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (activePopup && w->isPopupMenu()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (activeTornoff && w->isMenu()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (w->isMenu() || w->isDropdownMenu() || w->isPopupMenu()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// no matching window, disable effect
|
|
|
|
m_active = false;
|
|
|
|
}
|
2012-02-26 16:59:21 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TranslucencyEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
2012-09-05 19:13:33 +00:00
|
|
|
if (m_activeDecorations && 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
|
|
|
|
}
|
2012-09-05 19:35:36 +00:00
|
|
|
if (m_activeInactive && isInactive(w))
|
2012-02-26 16:59:21 +00:00
|
|
|
data.setTranslucent();
|
2012-09-05 19:35:36 +00:00
|
|
|
else if (m_activeMoveResize && (w->isUserMove() || w->isUserResize())) {
|
2008-12-15 07:02:07 +00:00
|
|
|
data.setTranslucent();
|
2012-02-26 16:59:21 +00:00
|
|
|
}
|
2012-09-05 19:13:33 +00:00
|
|
|
else if (m_activeDialogs && w->isDialog()) {
|
2007-07-19 13:32:46 +00:00
|
|
|
data.setTranslucent();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2012-12-20 15:41:23 +00:00
|
|
|
else if (m_activeMenus && ((dropdownmenus != 1.0 && w->isDropdownMenu())
|
2011-01-30 14:34:42 +00:00
|
|
|
|| (popupmenus != 1.0 && w->isPopupMenu())
|
|
|
|
|| (tornoffmenus != 1.0 && w->isMenu())
|
2012-12-20 15:41:23 +00:00
|
|
|
|| (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)
|
|
|
|
{
|
|
|
|
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
|
2012-09-05 19:13:33 +00:00
|
|
|
if (m_activeInactive && isInactive(w)) {
|
2012-07-12 15:20:17 +00:00
|
|
|
data.multiplyOpacity(inactive);
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-28 16:10:10 +00:00
|
|
|
// decoration and dialogs
|
2012-09-05 19:13:33 +00:00
|
|
|
if (m_activeDecorations && w->hasDecoration())
|
2012-07-12 15:20:17 +00:00
|
|
|
data.multiplyDecorationOpacity(decoration);
|
2012-09-05 19:13:33 +00:00
|
|
|
if (m_activeDialogs && w->isDialog())
|
2012-07-12 15:20:17 +00:00
|
|
|
data.multiplyOpacity(dialogs);
|
2008-04-28 16:10:10 +00:00
|
|
|
|
|
|
|
// Handling moving and resizing
|
2012-09-05 19:35:36 +00:00
|
|
|
if (m_activeMoveResize && (w->isUserMove() || w->isUserResize())) {
|
2012-09-07 05:59:10 +00:00
|
|
|
data.multiplyOpacity(moveresize);
|
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
|
2012-09-05 19:13:33 +00:00
|
|
|
if (m_activeMenus) {
|
|
|
|
if (dropdownmenus != 1.0 && w->isDropdownMenu())
|
2012-09-07 05:59:10 +00:00
|
|
|
data.multiplyOpacity(dropdownmenus);
|
2012-09-05 19:13:33 +00:00
|
|
|
if (popupmenus != 1.0 && w->isPopupMenu())
|
2012-09-07 05:59:10 +00:00
|
|
|
data.multiplyOpacity(popupmenus);
|
2012-09-05 19:13:33 +00:00
|
|
|
if (tornoffmenus != 1.0 && w->isMenu())
|
2012-09-07 05:59:10 +00:00
|
|
|
data.multiplyOpacity(tornoffmenus);
|
2012-09-05 19:13:33 +00:00
|
|
|
if (comboboxpopups != 1.0 && w->isComboBox())
|
2012-09-07 05:59:10 +00:00
|
|
|
data.multiplyOpacity(comboboxpopups);
|
2012-09-05 19:13:33 +00:00
|
|
|
}
|
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-03-13 11:41:30 +00:00
|
|
|
void TranslucencyEffect::slotWindowStartStopUserMovedResized(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-09-04 19:02:41 +00:00
|
|
|
if (m_activeMoveResize) {
|
|
|
|
checkIsActive();
|
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
|
|
|
{
|
2012-09-05 19:13:33 +00:00
|
|
|
if (m_activeInactive) {
|
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;
|
2012-09-04 19:02:41 +00:00
|
|
|
checkIsActive();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TranslucencyEffect::isActive() const
|
|
|
|
{
|
|
|
|
return m_active;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-14 15:34:39 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|