File indexing completed on 2024-04-28 16:49:28

0001 /*
0002 *  Copyright 2019  Michail Vourlakos <mvourlakos@gmail.com>
0003 *
0004 *  This file is part of Latte-Dock
0005 *
0006 *  Latte-Dock is free software; you can redistribute it and/or
0007 *  modify it under the terms of the GNU General Public License as
0008 *  published by the Free Software Foundation; either version 2 of
0009 *  the License, or (at your option) any later version.
0010 *
0011 *  Latte-Dock is distributed in the hope that it will be useful,
0012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 *  GNU General Public License for more details.
0015 *
0016 *  You should have received a copy of the GNU General Public License
0017 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 #include "currentscreentracker.h"
0021 
0022 // local
0023 #include "../view.h"
0024 #include "../../wm/schemecolors.h"
0025 #include "../../wm/tracker/lastactivewindow.h"
0026 #include "../../wm/tracker/windowstracker.h"
0027 
0028 namespace Latte {
0029 namespace ViewPart {
0030 namespace TrackerPart {
0031 
0032 CurrentScreenTracker::CurrentScreenTracker(WindowsTracker *parent)
0033     : QObject(parent),
0034       m_latteView(parent->view()),
0035       m_wm(parent->wm())
0036 {
0037     init();
0038 }
0039 
0040 CurrentScreenTracker::~CurrentScreenTracker()
0041 {
0042     m_wm->windowsTracker()->removeView(m_latteView);
0043 }
0044 
0045 void  CurrentScreenTracker::init()
0046 {
0047     if (lastActiveWindow()) {
0048         initSignalsForInformation();
0049     }
0050 
0051     connect(m_latteView, &Latte::View::layoutChanged, this, [&]() {
0052         if (m_latteView->layout()) {
0053             initSignalsForInformation();
0054         }
0055     });
0056 
0057     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::informationAnnounced, this, [&](const Latte::View *view) {
0058         if (m_latteView == view) {
0059             initSignalsForInformation();
0060         }
0061     });
0062 
0063     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowMaximizedChanged, this, [&](const Latte::View *view) {
0064         if (m_latteView == view) {
0065             emit activeWindowMaximizedChanged();
0066         }
0067     });
0068 
0069     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowTouchingChanged, this, [&](const Latte::View *view) {
0070         if (m_latteView == view) {
0071             emit activeWindowTouchingChanged();
0072         }
0073     });
0074 
0075     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowActiveChanged, this, [&](const Latte::View *view) {
0076         if (m_latteView == view) {
0077             emit existsWindowActiveChanged();
0078         }
0079     });
0080 
0081     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowMaximizedChanged, this, [&](const Latte::View *view) {
0082         if (m_latteView == view) {
0083             emit existsWindowMaximizedChanged();
0084         }
0085     });
0086 
0087     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowTouchingChanged, this, [&](const Latte::View *view) {
0088         if (m_latteView == view) {
0089             emit existsWindowTouchingChanged();
0090         }
0091     });
0092 
0093     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::isTouchingBusyVerticalViewChanged, this, [&](const Latte::View *view) {
0094         if (m_latteView == view) {
0095             emit isTouchingBusyVerticalViewChanged();
0096         }
0097     });
0098 
0099     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowSchemeChanged, this, [&](const Latte::View *view) {
0100         if (m_latteView == view) {
0101             emit activeWindowSchemeChanged();
0102         }
0103     });
0104 
0105     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::touchingWindowSchemeChanged, this, [&](const Latte::View *view) {
0106         if (m_latteView == view) {
0107             emit touchingWindowSchemeChanged();
0108         }
0109     });
0110 }
0111 
0112 void CurrentScreenTracker::initSignalsForInformation()
0113 {
0114     emit lastActiveWindowChanged();
0115     emit activeWindowMaximizedChanged();
0116     emit activeWindowTouchingChanged();
0117     emit existsWindowActiveChanged();
0118     emit existsWindowMaximizedChanged();
0119     emit existsWindowTouchingChanged();
0120     emit activeWindowSchemeChanged();
0121     emit touchingWindowSchemeChanged();
0122 }
0123 
0124 bool CurrentScreenTracker::activeWindowMaximized() const
0125 {
0126     return m_wm->windowsTracker()->activeWindowMaximized(m_latteView);
0127 }
0128 
0129 bool CurrentScreenTracker::activeWindowTouching() const
0130 {
0131     return m_wm->windowsTracker()->activeWindowTouching(m_latteView);
0132 }
0133 
0134 bool CurrentScreenTracker::existsWindowActive() const
0135 {
0136     return m_wm->windowsTracker()->existsWindowActive(m_latteView);
0137 }
0138 
0139 bool CurrentScreenTracker::existsWindowMaximized() const
0140 {
0141     return m_wm->windowsTracker()->existsWindowMaximized(m_latteView);
0142 }
0143 
0144 bool CurrentScreenTracker::existsWindowTouching() const
0145 {
0146     return m_wm->windowsTracker()->existsWindowTouching(m_latteView);
0147 }
0148 
0149 bool CurrentScreenTracker::isTouchingBusyVerticalView() const
0150 {
0151     return m_wm->windowsTracker()->isTouchingBusyVerticalView(m_latteView);
0152 }
0153 
0154 WindowSystem::SchemeColors *CurrentScreenTracker::activeWindowScheme() const
0155 {
0156     return m_wm->windowsTracker()->activeWindowScheme(m_latteView);
0157 }
0158 
0159 WindowSystem::SchemeColors *CurrentScreenTracker::touchingWindowScheme() const
0160 {
0161     return m_wm->windowsTracker()->touchingWindowScheme(m_latteView);
0162 }
0163 
0164 WindowSystem::Tracker::LastActiveWindow *CurrentScreenTracker::lastActiveWindow()
0165 {
0166     return m_wm->windowsTracker()->lastActiveWindow(m_latteView);
0167 }
0168 
0169 
0170 //! Window Functions
0171 void CurrentScreenTracker::requestMoveLastWindow(int localX, int localY)
0172 {
0173     m_wm->windowsTracker()->lastActiveWindow(m_latteView)->requestMove(m_latteView, localX, localY);
0174 }
0175 
0176 }
0177 }
0178 }