File indexing completed on 2024-04-21 05:31:06

0001 /*
0002     SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "currentscreentracker.h"
0007 
0008 // local
0009 #include "../view.h"
0010 #include "../../wm/schemecolors.h"
0011 #include "../../wm/tracker/lastactivewindow.h"
0012 #include "../../wm/tracker/windowstracker.h"
0013 
0014 namespace Latte {
0015 namespace ViewPart {
0016 namespace TrackerPart {
0017 
0018 CurrentScreenTracker::CurrentScreenTracker(WindowsTracker *parent)
0019     : QObject(parent),
0020       m_latteView(parent->view()),
0021       m_wm(parent->wm())
0022 {
0023     init();
0024 }
0025 
0026 CurrentScreenTracker::~CurrentScreenTracker()
0027 {
0028     m_wm->windowsTracker()->removeView(m_latteView);
0029 }
0030 
0031 void  CurrentScreenTracker::init()
0032 {
0033     if (lastActiveWindow()) {
0034         initSignalsForInformation();
0035     }
0036 
0037     connect(m_latteView, &Latte::View::layoutChanged, this, [&]() {
0038         if (m_latteView->layout()) {
0039             initSignalsForInformation();
0040         }
0041     });
0042 
0043     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::informationAnnounced, this, [&](const Latte::View *view) {
0044         if (m_latteView == view) {
0045             initSignalsForInformation();
0046         }
0047     });
0048 
0049     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowMaximizedChanged, this, [&](const Latte::View *view) {
0050         if (m_latteView == view) {
0051             emit activeWindowMaximizedChanged();
0052         }
0053     });
0054 
0055     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowTouchingChanged, this, [&](const Latte::View *view) {
0056         if (m_latteView == view) {
0057             emit activeWindowTouchingChanged();
0058         }
0059     });
0060 
0061     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowTouchingEdgeChanged, this, [&](const Latte::View *view) {
0062         if (m_latteView == view) {
0063             emit activeWindowTouchingEdgeChanged();
0064         }
0065     });
0066 
0067     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowActiveChanged, this, [&](const Latte::View *view) {
0068         if (m_latteView == view) {
0069             emit existsWindowActiveChanged();
0070         }
0071     });
0072 
0073     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowMaximizedChanged, this, [&](const Latte::View *view) {
0074         if (m_latteView == view) {
0075             emit existsWindowMaximizedChanged();
0076         }
0077     });
0078 
0079     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowTouchingChanged, this, [&](const Latte::View *view) {
0080         if (m_latteView == view) {
0081             emit existsWindowTouchingChanged();
0082         }
0083     });
0084 
0085     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowTouchingEdgeChanged, this, [&](const Latte::View *view) {
0086         if (m_latteView == view) {
0087             emit existsWindowTouchingEdgeChanged();
0088         }
0089     });
0090 
0091     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::isTouchingBusyVerticalViewChanged, this, [&](const Latte::View *view) {
0092         if (m_latteView == view) {
0093             emit isTouchingBusyVerticalViewChanged();
0094         }
0095     });
0096 
0097     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowSchemeChanged, this, [&](const Latte::View *view) {
0098         if (m_latteView == view) {
0099             emit activeWindowSchemeChanged();
0100         }
0101     });
0102 
0103     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::touchingWindowSchemeChanged, this, [&](const Latte::View *view) {
0104         if (m_latteView == view) {
0105             emit touchingWindowSchemeChanged();
0106         }
0107     });
0108 }
0109 
0110 void CurrentScreenTracker::initSignalsForInformation()
0111 {
0112     emit lastActiveWindowChanged();
0113     emit activeWindowMaximizedChanged();
0114     emit activeWindowTouchingChanged();
0115     emit activeWindowTouchingEdgeChanged();
0116     emit existsWindowActiveChanged();
0117     emit existsWindowMaximizedChanged();
0118     emit existsWindowTouchingChanged();
0119     emit existsWindowTouchingEdgeChanged();
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::activeWindowTouchingEdge() const
0135 {
0136     return m_wm->windowsTracker()->activeWindowTouchingEdge(m_latteView);
0137 }
0138 
0139 bool CurrentScreenTracker::existsWindowActive() const
0140 {
0141     return m_wm->windowsTracker()->existsWindowActive(m_latteView);
0142 }
0143 
0144 bool CurrentScreenTracker::existsWindowMaximized() const
0145 {
0146     return m_wm->windowsTracker()->existsWindowMaximized(m_latteView);
0147 }
0148 
0149 bool CurrentScreenTracker::existsWindowTouching() const
0150 {
0151     return m_wm->windowsTracker()->existsWindowTouching(m_latteView);
0152 }
0153 
0154 bool CurrentScreenTracker::existsWindowTouchingEdge() const
0155 {
0156     return m_wm->windowsTracker()->existsWindowTouchingEdge(m_latteView);
0157 }
0158 
0159 bool CurrentScreenTracker::isTouchingBusyVerticalView() const
0160 {
0161     return m_wm->windowsTracker()->isTouchingBusyVerticalView(m_latteView);
0162 }
0163 
0164 WindowSystem::SchemeColors *CurrentScreenTracker::activeWindowScheme() const
0165 {
0166     return m_wm->windowsTracker()->activeWindowScheme(m_latteView);
0167 }
0168 
0169 WindowSystem::SchemeColors *CurrentScreenTracker::touchingWindowScheme() const
0170 {
0171     return m_wm->windowsTracker()->touchingWindowScheme(m_latteView);
0172 }
0173 
0174 WindowSystem::Tracker::LastActiveWindow *CurrentScreenTracker::lastActiveWindow()
0175 {
0176     return m_wm->windowsTracker()->lastActiveWindow(m_latteView);
0177 }
0178 
0179 
0180 //! Window Functions
0181 void CurrentScreenTracker::requestMoveLastWindow(int localX, int localY)
0182 {
0183     m_wm->windowsTracker()->lastActiveWindow(m_latteView)->requestMove(m_latteView, localX, localY);
0184 }
0185 
0186 }
0187 }
0188 }