1 /*
2     SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
3     SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "currentscreentracker.h"
7 
8 // local
9 #include "../view.h"
10 #include "../../wm/schemecolors.h"
11 #include "../../wm/tracker/lastactivewindow.h"
12 #include "../../wm/tracker/windowstracker.h"
13 
14 namespace Latte {
15 namespace ViewPart {
16 namespace TrackerPart {
17 
CurrentScreenTracker(WindowsTracker * parent)18 CurrentScreenTracker::CurrentScreenTracker(WindowsTracker *parent)
19     : QObject(parent),
20       m_latteView(parent->view()),
21       m_wm(parent->wm())
22 {
23     init();
24 }
25 
~CurrentScreenTracker()26 CurrentScreenTracker::~CurrentScreenTracker()
27 {
28     m_wm->windowsTracker()->removeView(m_latteView);
29 }
30 
init()31 void  CurrentScreenTracker::init()
32 {
33     if (lastActiveWindow()) {
34         initSignalsForInformation();
35     }
36 
37     connect(m_latteView, &Latte::View::layoutChanged, this, [&]() {
38         if (m_latteView->layout()) {
39             initSignalsForInformation();
40         }
41     });
42 
43     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::informationAnnounced, this, [&](const Latte::View *view) {
44         if (m_latteView == view) {
45             initSignalsForInformation();
46         }
47     });
48 
49     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowMaximizedChanged, this, [&](const Latte::View *view) {
50         if (m_latteView == view) {
51             emit activeWindowMaximizedChanged();
52         }
53     });
54 
55     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowTouchingChanged, this, [&](const Latte::View *view) {
56         if (m_latteView == view) {
57             emit activeWindowTouchingChanged();
58         }
59     });
60 
61     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowTouchingEdgeChanged, this, [&](const Latte::View *view) {
62         if (m_latteView == view) {
63             emit activeWindowTouchingEdgeChanged();
64         }
65     });
66 
67     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowActiveChanged, this, [&](const Latte::View *view) {
68         if (m_latteView == view) {
69             emit existsWindowActiveChanged();
70         }
71     });
72 
73     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowMaximizedChanged, this, [&](const Latte::View *view) {
74         if (m_latteView == view) {
75             emit existsWindowMaximizedChanged();
76         }
77     });
78 
79     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowTouchingChanged, this, [&](const Latte::View *view) {
80         if (m_latteView == view) {
81             emit existsWindowTouchingChanged();
82         }
83     });
84 
85     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::existsWindowTouchingEdgeChanged, this, [&](const Latte::View *view) {
86         if (m_latteView == view) {
87             emit existsWindowTouchingEdgeChanged();
88         }
89     });
90 
91     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::isTouchingBusyVerticalViewChanged, this, [&](const Latte::View *view) {
92         if (m_latteView == view) {
93             emit isTouchingBusyVerticalViewChanged();
94         }
95     });
96 
97     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::activeWindowSchemeChanged, this, [&](const Latte::View *view) {
98         if (m_latteView == view) {
99             emit activeWindowSchemeChanged();
100         }
101     });
102 
103     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::touchingWindowSchemeChanged, this, [&](const Latte::View *view) {
104         if (m_latteView == view) {
105             emit touchingWindowSchemeChanged();
106         }
107     });
108 }
109 
initSignalsForInformation()110 void CurrentScreenTracker::initSignalsForInformation()
111 {
112     emit lastActiveWindowChanged();
113     emit activeWindowMaximizedChanged();
114     emit activeWindowTouchingChanged();
115     emit activeWindowTouchingEdgeChanged();
116     emit existsWindowActiveChanged();
117     emit existsWindowMaximizedChanged();
118     emit existsWindowTouchingChanged();
119     emit existsWindowTouchingEdgeChanged();
120     emit activeWindowSchemeChanged();
121     emit touchingWindowSchemeChanged();
122 }
123 
activeWindowMaximized() const124 bool CurrentScreenTracker::activeWindowMaximized() const
125 {
126     return m_wm->windowsTracker()->activeWindowMaximized(m_latteView);
127 }
128 
activeWindowTouching() const129 bool CurrentScreenTracker::activeWindowTouching() const
130 {
131     return m_wm->windowsTracker()->activeWindowTouching(m_latteView);
132 }
133 
activeWindowTouchingEdge() const134 bool CurrentScreenTracker::activeWindowTouchingEdge() const
135 {
136     return m_wm->windowsTracker()->activeWindowTouchingEdge(m_latteView);
137 }
138 
existsWindowActive() const139 bool CurrentScreenTracker::existsWindowActive() const
140 {
141     return m_wm->windowsTracker()->existsWindowActive(m_latteView);
142 }
143 
existsWindowMaximized() const144 bool CurrentScreenTracker::existsWindowMaximized() const
145 {
146     return m_wm->windowsTracker()->existsWindowMaximized(m_latteView);
147 }
148 
existsWindowTouching() const149 bool CurrentScreenTracker::existsWindowTouching() const
150 {
151     return m_wm->windowsTracker()->existsWindowTouching(m_latteView);
152 }
153 
existsWindowTouchingEdge() const154 bool CurrentScreenTracker::existsWindowTouchingEdge() const
155 {
156     return m_wm->windowsTracker()->existsWindowTouchingEdge(m_latteView);
157 }
158 
isTouchingBusyVerticalView() const159 bool CurrentScreenTracker::isTouchingBusyVerticalView() const
160 {
161     return m_wm->windowsTracker()->isTouchingBusyVerticalView(m_latteView);
162 }
163 
activeWindowScheme() const164 WindowSystem::SchemeColors *CurrentScreenTracker::activeWindowScheme() const
165 {
166     return m_wm->windowsTracker()->activeWindowScheme(m_latteView);
167 }
168 
touchingWindowScheme() const169 WindowSystem::SchemeColors *CurrentScreenTracker::touchingWindowScheme() const
170 {
171     return m_wm->windowsTracker()->touchingWindowScheme(m_latteView);
172 }
173 
lastActiveWindow()174 WindowSystem::Tracker::LastActiveWindow *CurrentScreenTracker::lastActiveWindow()
175 {
176     return m_wm->windowsTracker()->lastActiveWindow(m_latteView);
177 }
178 
179 
180 //! Window Functions
requestMoveLastWindow(int localX,int localY)181 void CurrentScreenTracker::requestMoveLastWindow(int localX, int localY)
182 {
183     m_wm->windowsTracker()->lastActiveWindow(m_latteView)->requestMove(m_latteView, localX, localY);
184 }
185 
186 }
187 }
188 }
189