1 /*
2     SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
3     SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "windowstracker.h"
7 
8 // local
9 #include "currentscreentracker.h"
10 #include "allscreenstracker.h"
11 #include "../positioner.h"
12 #include "../view.h"
13 #include "../../lattecorona.h"
14 #include "../../wm/tracker/windowstracker.h"
15 
16 
17 namespace Latte {
18 namespace ViewPart {
19 
WindowsTracker(Latte::View * parent)20 WindowsTracker::WindowsTracker(Latte::View *parent)
21     : QObject(parent),
22       m_latteView(parent)
23 {
24     qDebug() << "WindowsTracker creating...";
25 
26     auto corona = qobject_cast<Latte::Corona *>(m_latteView->corona());
27     m_wm = corona->wm();
28 
29     m_allScreensTracker = new TrackerPart::AllScreensTracker(this);
30     m_currentScreenTracker = new TrackerPart::CurrentScreenTracker(this);
31 
32     connect(m_wm->windowsTracker(), &WindowSystem::Tracker::Windows::enabledChanged, this, [&](const Latte::View *view) {
33         if (m_latteView == view) {
34             emit enabledChanged();
35         }
36     });
37 
38     m_wm->windowsTracker()->addView(m_latteView);
39     emit allScreensChanged();
40     emit currentScreenChanged();
41 }
42 
~WindowsTracker()43 WindowsTracker::~WindowsTracker()
44 {
45     qDebug() << "WindowsTracker removing...";
46 
47     if (m_allScreensTracker) {
48         m_allScreensTracker->deleteLater();
49     }
50 
51     if (m_currentScreenTracker) {
52         m_currentScreenTracker->deleteLater();
53     }
54 }
55 
view() const56 Latte::View *WindowsTracker::view() const
57 {
58     return m_latteView;
59 }
60 
wm() const61 WindowSystem::AbstractWindowInterface *WindowsTracker::wm() const
62 {
63     return m_wm;
64 }
65 
enabled() const66 bool WindowsTracker::enabled() const
67 {
68     return m_wm->windowsTracker()->enabled(m_latteView);
69 }
70 
setEnabled(bool active)71 void WindowsTracker::setEnabled(bool active)
72 {
73     m_wm->windowsTracker()->setEnabled(m_latteView, active);
74 }
75 
76 
allScreens() const77 TrackerPart::AllScreensTracker *WindowsTracker::allScreens() const
78 {
79     return m_allScreensTracker;
80 }
81 
currentScreen() const82 TrackerPart::CurrentScreenTracker *WindowsTracker::currentScreen() const
83 {
84     return m_currentScreenTracker;
85 }
86 
87 //! Environment Functions
switchToNextActivity()88 void WindowsTracker::switchToNextActivity()
89 {
90     m_wm->switchToNextActivity();
91 }
92 
switchToPreviousActivity()93 void WindowsTracker::switchToPreviousActivity()
94 {
95     m_wm->switchToPreviousActivity();
96 }
97 
switchToNextVirtualDesktop()98 void WindowsTracker::switchToNextVirtualDesktop()
99 {
100     m_wm->switchToNextVirtualDesktop();
101 }
102 
switchToPreviousVirtualDesktop()103 void WindowsTracker::switchToPreviousVirtualDesktop()
104 {
105     m_wm->switchToPreviousVirtualDesktop();
106 }
107 
108 }
109 }
110