diff --git a/effects/diminactive/diminactive.cpp b/effects/diminactive/diminactive.cpp index 69ba65311..a6f4f05b5 100644 --- a/effects/diminactive/diminactive.cpp +++ b/effects/diminactive/diminactive.cpp @@ -1,398 +1,403 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2007 Lubos Lunak Copyright (C) 2007 Christian Nitschkowski Copyright (C) 2018 Vlad Zagorodniy 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 . *********************************************************************/ // own #include "diminactive.h" // KConfigSkeleton #include "diminactiveconfig.h" namespace KWin { /** * Checks if two windows belong to the same window group * * One possible example of a window group is an app window and app * preferences window(e.g. Dolphin window and Dolphin Preferences window). * * @param w1 The first window * @param w2 The second window * @returns @c true if both windows belong to the same window group, @c false otherwise **/ static inline bool belongToSameGroup(const EffectWindow *w1, const EffectWindow *w2) { return w1 && w2 && w1->group() && w1->group() == w2->group(); } DimInactiveEffect::DimInactiveEffect() { initConfig(); reconfigure(ReconfigureAll); connect(effects, &EffectsHandler::windowActivated, this, &DimInactiveEffect::windowActivated); connect(effects, &EffectsHandler::windowClosed, this, &DimInactiveEffect::windowClosed); connect(effects, &EffectsHandler::windowDeleted, this, &DimInactiveEffect::windowDeleted); connect(effects, &EffectsHandler::activeFullScreenEffectChanged, this, &DimInactiveEffect::activeFullScreenEffectChanged); } DimInactiveEffect::~DimInactiveEffect() { } void DimInactiveEffect::reconfigure(ReconfigureFlags flags) { Q_UNUSED(flags) DimInactiveConfig::self()->read(); // TODO: Use normalized strength param. m_dimStrength = DimInactiveConfig::strength() / 100.0; m_dimPanels = DimInactiveConfig::dimPanels(); m_dimDesktop = DimInactiveConfig::dimDesktop(); m_dimKeepAbove = DimInactiveConfig::dimKeepAbove(); m_dimByGroup = DimInactiveConfig::dimByGroup(); + m_dimFullScreen = DimInactiveConfig::dimFullScreen(); // Need to reset m_activeWindow becase canDimWindow returns false // if m_activeWindow is equal to effects->activeWindow(). m_activeWindow = nullptr; EffectWindow *activeWindow = effects->activeWindow(); m_activeWindow = (activeWindow && canDimWindow(activeWindow)) ? activeWindow : nullptr; m_activeWindowGroup = (m_dimByGroup && m_activeWindow) ? m_activeWindow->group() : nullptr; m_fullScreenTransition.timeLine.setDuration( std::chrono::milliseconds(static_cast(animationTime(250)))); effects->addRepaintFull(); } void DimInactiveEffect::prePaintScreen(ScreenPrePaintData &data, int time) { const std::chrono::milliseconds delta(time); if (m_fullScreenTransition.active) { m_fullScreenTransition.timeLine.update(delta); } auto transitionIt = m_transitions.begin(); while (transitionIt != m_transitions.end()) { (*transitionIt).update(delta); ++transitionIt; } effects->prePaintScreen(data, time); } void DimInactiveEffect::paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) { auto transitionIt = m_transitions.constFind(w); if (transitionIt != m_transitions.constEnd()) { const qreal transitionProgress = (*transitionIt).value(); dimWindow(data, m_dimStrength * transitionProgress); effects->paintWindow(w, mask, region, data); return; } auto forceIt = m_forceDim.constFind(w); if (forceIt != m_forceDim.constEnd()) { const qreal forcedStrength = *forceIt; dimWindow(data, forcedStrength); effects->paintWindow(w, mask, region, data); return; } if (canDimWindow(w)) { dimWindow(data, m_dimStrength); } effects->paintWindow(w, mask, region, data); } void DimInactiveEffect::postPaintScreen() { if (m_fullScreenTransition.active) { if (m_fullScreenTransition.timeLine.done()) { m_fullScreenTransition.active = false; } effects->addRepaintFull(); } auto transitionIt = m_transitions.begin(); while (transitionIt != m_transitions.end()) { EffectWindow *w = transitionIt.key(); if ((*transitionIt).done()) { transitionIt = m_transitions.erase(transitionIt); } else { ++transitionIt; } w->addRepaintFull(); } effects->postPaintScreen(); } void DimInactiveEffect::dimWindow(WindowPaintData &data, qreal strength) { qreal dimFactor; if (m_fullScreenTransition.active) { dimFactor = 1.0 - m_fullScreenTransition.timeLine.value(); } else if (effects->activeFullScreenEffect()) { dimFactor = 0.0; } else { dimFactor = 1.0; } data.multiplyBrightness(1.0 - strength * dimFactor); data.multiplySaturation(1.0 - strength * dimFactor); } bool DimInactiveEffect::canDimWindow(const EffectWindow *w) const { if (m_activeWindow == w) { return false; } if (m_dimByGroup && belongToSameGroup(m_activeWindow, w)) { return false; } if (w->isDock() && !m_dimPanels) { return false; } if (w->isDesktop() && !m_dimDesktop) { return false; } if (w->keepAbove() && !m_dimKeepAbove) { return false; } + if (w->isFullScreen() && !m_dimFullScreen) { + return false; + } + if (!w->isManaged()) { return false; } return w->isNormalWindow() || w->isDialog() || w->isUtility() || w->isDock() || w->isDesktop(); } void DimInactiveEffect::scheduleInTransition(EffectWindow *w) { TimeLine &timeLine = m_transitions[w]; timeLine.setDuration( std::chrono::milliseconds(static_cast(animationTime(160)))); if (timeLine.done()) { // If the Out animation is still active, then we're trucating // duration of the timeline(from 250ms to 160ms). If the timeline // is about to be finished with the old duration, then after // changing duration it will be in the "done" state. Thus, we // have to reset the timeline, otherwise it won't update progress. timeLine.reset(); } timeLine.setDirection(TimeLine::Backward); timeLine.setEasingCurve(QEasingCurve::InOutSine); } void DimInactiveEffect::scheduleGroupInTransition(EffectWindow *w) { if (!m_dimByGroup) { scheduleInTransition(w); return; } if (!w->group()) { scheduleInTransition(w); return; } const auto members = w->group()->members(); for (EffectWindow *member : members) { scheduleInTransition(member); } } void DimInactiveEffect::scheduleOutTransition(EffectWindow *w) { TimeLine &timeLine = m_transitions[w]; timeLine.setDuration( std::chrono::milliseconds(static_cast(animationTime(250)))); if (timeLine.done()) { timeLine.reset(); } timeLine.setDirection(TimeLine::Forward); timeLine.setEasingCurve(QEasingCurve::InOutSine); } void DimInactiveEffect::scheduleGroupOutTransition(EffectWindow *w) { if (!m_dimByGroup) { scheduleOutTransition(w); return; } if (!w->group()) { scheduleOutTransition(w); return; } const auto members = w->group()->members(); for (EffectWindow *member : members) { scheduleOutTransition(member); } } void DimInactiveEffect::scheduleRepaint(EffectWindow *w) { if (!m_dimByGroup) { w->addRepaintFull(); return; } if (!w->group()) { w->addRepaintFull(); return; } const auto members = w->group()->members(); for (EffectWindow *member : members) { member->addRepaintFull(); } } void DimInactiveEffect::windowActivated(EffectWindow *w) { if (!w) { return; } if (m_activeWindow == w) { return; } if (m_dimByGroup && belongToSameGroup(m_activeWindow, w)) { m_activeWindow = w; return; } // WORKAROUND: Deleted windows do not belong to any of window groups. // So, if one of windows in a window group is closed, the In transition // will be false-triggered for the rest of the window group. In addition // to the active window, keep track of active window group so we can // tell whether "focus" moved from a closed window to some other window // in a window group. if (m_dimByGroup && w->group() && w->group() == m_activeWindowGroup) { m_activeWindow = w; return; } EffectWindow *previousActiveWindow = m_activeWindow; m_activeWindow = canDimWindow(w) ? w : nullptr; m_activeWindowGroup = (m_dimByGroup && m_activeWindow) ? m_activeWindow->group() : nullptr; if (previousActiveWindow) { scheduleGroupOutTransition(previousActiveWindow); scheduleRepaint(previousActiveWindow); } if (m_activeWindow) { scheduleGroupInTransition(m_activeWindow); scheduleRepaint(m_activeWindow); } } void DimInactiveEffect::windowClosed(EffectWindow *w) { // When a window is closed, we should force current dim strength that // is applied to it to avoid flickering when some effect animates // the disappearing of the window. If there is no such effect then // it won't be dimmed. qreal forcedStrength = 0.0; bool shouldForceDim = false; auto transitionIt = m_transitions.find(w); if (transitionIt != m_transitions.end()) { forcedStrength = m_dimStrength * (*transitionIt).value(); shouldForceDim = true; m_transitions.erase(transitionIt); } else if (m_activeWindow == w) { forcedStrength = 0.0; shouldForceDim = true; } else if (m_dimByGroup && belongToSameGroup(m_activeWindow, w)) { forcedStrength = 0.0; shouldForceDim = true; } else if (canDimWindow(w)) { forcedStrength = m_dimStrength; shouldForceDim = true; } if (shouldForceDim) { m_forceDim.insert(w, forcedStrength); } if (m_activeWindow == w) { m_activeWindow = nullptr; } } void DimInactiveEffect::windowDeleted(EffectWindow *w) { m_forceDim.remove(w); // FIXME: Sometimes we can miss the window close signal because KWin // can activate a window that is not ready for painting and the window // gets destroyed immediately. So, we have to remove active transitions // for that window here, otherwise we'll crash in postPaintScreen. m_transitions.remove(w); } void DimInactiveEffect::activeFullScreenEffectChanged() { if (m_fullScreenTransition.timeLine.done()) { m_fullScreenTransition.timeLine.reset(); } m_fullScreenTransition.timeLine.setDirection( effects->activeFullScreenEffect() ? TimeLine::Forward : TimeLine::Backward ); m_fullScreenTransition.active = true; effects->addRepaintFull(); } } // namespace KWin diff --git a/effects/diminactive/diminactive.h b/effects/diminactive/diminactive.h index 1af62f778..4aef26e26 100644 --- a/effects/diminactive/diminactive.h +++ b/effects/diminactive/diminactive.h @@ -1,130 +1,138 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2007 Lubos Lunak Copyright (C) 2007 Christian Nitschkowski Copyright (C) 2018 Vlad Zagorodniy 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 . *********************************************************************/ #ifndef KWIN_DIMINACTIVE_H #define KWIN_DIMINACTIVE_H // kwineffects #include namespace KWin { class DimInactiveEffect : public Effect { Q_OBJECT Q_PROPERTY(int dimStrength READ dimStrength) Q_PROPERTY(bool dimPanels READ dimPanels) Q_PROPERTY(bool dimDesktop READ dimDesktop) Q_PROPERTY(bool dimKeepAbove READ dimKeepAbove) Q_PROPERTY(bool dimByGroup READ dimByGroup) + Q_PROPERTY(bool dimFullScreen READ dimFullScreen) public: DimInactiveEffect(); ~DimInactiveEffect() override; void reconfigure(ReconfigureFlags flags) override; void prePaintScreen(ScreenPrePaintData &data, int time) override; void paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) override; void postPaintScreen() override; int requestedEffectChainPosition() const override; bool isActive() const override; int dimStrength() const; bool dimPanels() const; bool dimDesktop() const; bool dimKeepAbove() const; bool dimByGroup() const; + bool dimFullScreen() const; private Q_SLOTS: void windowActivated(EffectWindow *w); void windowClosed(EffectWindow *w); void windowDeleted(EffectWindow *w); void activeFullScreenEffectChanged(); private: void dimWindow(WindowPaintData &data, qreal strength); bool canDimWindow(const EffectWindow *w) const; void scheduleInTransition(EffectWindow *w); void scheduleGroupInTransition(EffectWindow *w); void scheduleOutTransition(EffectWindow *w); void scheduleGroupOutTransition(EffectWindow *w); void scheduleRepaint(EffectWindow *w); private: qreal m_dimStrength; bool m_dimPanels; bool m_dimDesktop; bool m_dimKeepAbove; bool m_dimByGroup; + bool m_dimFullScreen; EffectWindow *m_activeWindow; const EffectWindowGroup *m_activeWindowGroup; QHash m_transitions; QHash m_forceDim; struct { bool active = false; TimeLine timeLine; } m_fullScreenTransition; }; inline int DimInactiveEffect::requestedEffectChainPosition() const { return 50; } inline bool DimInactiveEffect::isActive() const { return true; } inline int DimInactiveEffect::dimStrength() const { return qRound(m_dimStrength * 100.0); } inline bool DimInactiveEffect::dimPanels() const { return m_dimPanels; } inline bool DimInactiveEffect::dimDesktop() const { return m_dimDesktop; } inline bool DimInactiveEffect::dimKeepAbove() const { return m_dimKeepAbove; } inline bool DimInactiveEffect::dimByGroup() const { return m_dimByGroup; } +inline bool DimInactiveEffect::dimFullScreen() const +{ + return m_dimFullScreen; +} + } // namespace KWin #endif diff --git a/effects/diminactive/diminactive.kcfg b/effects/diminactive/diminactive.kcfg index f1f32fe62..ebad90c9e 100644 --- a/effects/diminactive/diminactive.kcfg +++ b/effects/diminactive/diminactive.kcfg @@ -1,24 +1,27 @@ 25 false false false true + + true + diff --git a/effects/diminactive/diminactive_config.ui b/effects/diminactive/diminactive_config.ui index 19f7ff101..f81ed44f4 100644 --- a/effects/diminactive/diminactive_config.ui +++ b/effects/diminactive/diminactive_config.ui @@ -1,76 +1,83 @@ DimInactiveEffectConfig 0 0 400 160 Strength: 0 0 100 5 Dim: Docks and panels Desktop Keep above windows By window group + + + + Fullscreen windows + + +