File indexing completed on 2024-06-09 05:25:56
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2007 Lubos Lunak <l.lunak@kde.org> 0006 SPDX-FileCopyrightText: 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net> 0007 SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0008 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 0012 #pragma once 0013 0014 // kwineffects 0015 #include "effect/effect.h" 0016 #include "effect/timeline.h" 0017 0018 namespace KWin 0019 { 0020 0021 class EffectWindowGroup; 0022 0023 class DimInactiveEffect : public Effect 0024 { 0025 Q_OBJECT 0026 Q_PROPERTY(int dimStrength READ dimStrength) 0027 Q_PROPERTY(bool dimPanels READ dimPanels) 0028 Q_PROPERTY(bool dimDesktop READ dimDesktop) 0029 Q_PROPERTY(bool dimKeepAbove READ dimKeepAbove) 0030 Q_PROPERTY(bool dimByGroup READ dimByGroup) 0031 Q_PROPERTY(bool dimFullScreen READ dimFullScreen) 0032 0033 public: 0034 DimInactiveEffect(); 0035 ~DimInactiveEffect() override; 0036 0037 void reconfigure(ReconfigureFlags flags) override; 0038 0039 void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) override; 0040 void paintWindow(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, int mask, QRegion region, WindowPaintData &data) override; 0041 void postPaintScreen() override; 0042 0043 int requestedEffectChainPosition() const override; 0044 bool isActive() const override; 0045 0046 int dimStrength() const; 0047 bool dimPanels() const; 0048 bool dimDesktop() const; 0049 bool dimKeepAbove() const; 0050 bool dimByGroup() const; 0051 bool dimFullScreen() const; 0052 0053 private Q_SLOTS: 0054 void windowActivated(EffectWindow *w); 0055 void windowAdded(EffectWindow *w); 0056 void windowClosed(EffectWindow *w); 0057 void windowDeleted(EffectWindow *w); 0058 void activeFullScreenEffectChanged(); 0059 0060 void updateActiveWindow(EffectWindow *w); 0061 0062 private: 0063 void dimWindow(WindowPaintData &data, qreal strength); 0064 bool canDimWindow(const EffectWindow *w) const; 0065 void scheduleInTransition(EffectWindow *w); 0066 void scheduleGroupInTransition(EffectWindow *w); 0067 void scheduleOutTransition(EffectWindow *w); 0068 void scheduleGroupOutTransition(EffectWindow *w); 0069 void scheduleRepaint(EffectWindow *w); 0070 0071 private: 0072 qreal m_dimStrength; 0073 bool m_dimPanels; 0074 bool m_dimDesktop; 0075 bool m_dimKeepAbove; 0076 bool m_dimByGroup; 0077 bool m_dimFullScreen; 0078 0079 EffectWindow *m_activeWindow = nullptr; 0080 const EffectWindowGroup *m_activeWindowGroup; 0081 QHash<EffectWindow *, TimeLine> m_transitions; 0082 QHash<EffectWindow *, qreal> m_forceDim; 0083 0084 struct 0085 { 0086 bool active = false; 0087 TimeLine timeLine; 0088 } m_fullScreenTransition; 0089 }; 0090 0091 inline int DimInactiveEffect::requestedEffectChainPosition() const 0092 { 0093 return 50; 0094 } 0095 0096 inline bool DimInactiveEffect::isActive() const 0097 { 0098 return true; 0099 } 0100 0101 inline int DimInactiveEffect::dimStrength() const 0102 { 0103 return qRound(m_dimStrength * 100.0); 0104 } 0105 0106 inline bool DimInactiveEffect::dimPanels() const 0107 { 0108 return m_dimPanels; 0109 } 0110 0111 inline bool DimInactiveEffect::dimDesktop() const 0112 { 0113 return m_dimDesktop; 0114 } 0115 0116 inline bool DimInactiveEffect::dimKeepAbove() const 0117 { 0118 return m_dimKeepAbove; 0119 } 0120 0121 inline bool DimInactiveEffect::dimByGroup() const 0122 { 0123 return m_dimByGroup; 0124 } 0125 0126 inline bool DimInactiveEffect::dimFullScreen() const 0127 { 0128 return m_dimFullScreen; 0129 } 0130 0131 } // namespace KWin