File indexing completed on 2024-04-21 09:21:44

0001 /*
0002     SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "allscreenstracker.h"
0007 
0008 // local
0009 #include "../view.h"
0010 #include "../../layout/genericlayout.h"
0011 #include "../../wm/schemecolors.h"
0012 #include "../../wm/tracker/lastactivewindow.h"
0013 #include "../../wm/tracker/windowstracker.h"
0014 
0015 namespace Latte {
0016 namespace ViewPart {
0017 namespace TrackerPart {
0018 
0019 AllScreensTracker::AllScreensTracker(WindowsTracker *parent)
0020     : QObject(parent),
0021       m_latteView(parent->view()),
0022       m_wm(parent->wm())
0023 {
0024     init();
0025 }
0026 
0027 AllScreensTracker::~AllScreensTracker()
0028 {
0029 }
0030 
0031 void  AllScreensTracker::init()
0032 {
0033     if (!m_currentLastActiveWindow && 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::informationAnnouncedForLayout, this, [&](const Latte::Layout::GenericLayout *layout) {
0044         if (m_latteView->layout() == layout) {
0045             initSignalsForInformation();
0046         }
0047     });
0048 
0049     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowMaximizedChangedForLayout, this, [&](const Latte::Layout::GenericLayout *layout) {
0050         if (m_latteView->layout() == layout) {
0051             emit activeWindowMaximizedChanged();
0052         }
0053     });
0054 
0055     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowActiveChangedForLayout, this, [&](const Latte::Layout::GenericLayout *layout) {
0056         if (m_latteView->layout() == layout) {
0057             emit existsWindowActiveChanged();
0058         }
0059     });
0060 
0061     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowMaximizedChangedForLayout, this, [&](const Latte::Layout::GenericLayout *layout) {
0062         if (m_latteView->layout() == layout) {
0063             emit existsWindowMaximizedChanged();
0064         }
0065     });
0066 
0067     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowSchemeChangedForLayout, this, [&](const Latte::Layout::GenericLayout *layout) {
0068         if (m_latteView->layout() == layout) {
0069             emit activeWindowSchemeChanged();
0070         }
0071     });
0072 }
0073 
0074 void AllScreensTracker::initSignalsForInformation()
0075 {
0076     m_currentLastActiveWindow = lastActiveWindow();
0077 
0078     emit lastActiveWindowChanged();
0079     emit activeWindowMaximizedChanged();
0080     emit existsWindowActiveChanged();
0081     emit existsWindowMaximizedChanged();
0082     emit activeWindowSchemeChanged();
0083 }
0084 
0085 bool AllScreensTracker::activeWindowMaximized() const
0086 {
0087     return m_wm->windowsTracker()->activeWindowMaximized(m_latteView->layout());
0088 }
0089 
0090 bool AllScreensTracker::existsWindowActive() const
0091 {
0092     return m_wm->windowsTracker()->existsWindowActive(m_latteView->layout());
0093 }
0094 
0095 bool AllScreensTracker::existsWindowMaximized() const
0096 {
0097     return m_wm->windowsTracker()->existsWindowMaximized(m_latteView->layout());
0098 }
0099 
0100 WindowSystem::SchemeColors *AllScreensTracker::activeWindowScheme() const
0101 {
0102     return m_wm->windowsTracker()->activeWindowScheme(m_latteView->layout());
0103 }
0104 
0105 WindowSystem::Tracker::LastActiveWindow *AllScreensTracker::lastActiveWindow()
0106 {
0107     return m_wm->windowsTracker()->lastActiveWindow(m_latteView->layout());
0108 }
0109 
0110 
0111 //! Window Functions
0112 void AllScreensTracker::requestMoveLastWindow(int localX, int localY)
0113 {
0114     m_wm->windowsTracker()->lastActiveWindow(m_latteView->layout())->requestMove(m_latteView, localX, localY);
0115 }
0116 
0117 }
0118 }
0119 }