File indexing completed on 2024-07-07 05:13:56

0001 /*
0002     SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "trackedgeneralinfo.h"
0007 
0008 #include <QLatin1String>
0009 
0010 //local
0011 #include "windowstracker.h"
0012 #include "../abstractwindowinterface.h"
0013 #include "../schemecolors.h"
0014 
0015 namespace Latte {
0016 namespace WindowSystem {
0017 namespace Tracker {
0018 
0019 
0020 TrackedGeneralInfo::TrackedGeneralInfo(Tracker::Windows *tracker)
0021     : QObject(tracker) ,
0022       m_wm(tracker->wm()),
0023       m_tracker(tracker)
0024 {
0025     m_lastActiveWindow = new LastActiveWindow(this);
0026 
0027     connect(m_wm, &AbstractWindowInterface::currentActivityChanged, this, [&]() {
0028         updateTrackingCurrentActivity();
0029     });
0030 
0031     emit lastActiveWindowChanged();
0032 }
0033 
0034 TrackedGeneralInfo::~TrackedGeneralInfo()
0035 {
0036     if (m_lastActiveWindow) {
0037         auto law = m_lastActiveWindow;
0038         m_lastActiveWindow = nullptr;
0039         emit lastActiveWindowChanged();
0040 
0041         law->deleteLater();
0042     }
0043 }
0044 
0045 bool TrackedGeneralInfo::enabled() const
0046 {
0047     return m_enabled;
0048 }
0049 
0050 void TrackedGeneralInfo::setEnabled(bool enabled)
0051 {
0052     if (m_enabled == enabled) {
0053         return;
0054     }
0055 
0056     m_enabled = enabled;
0057 }
0058 
0059 bool TrackedGeneralInfo::activeWindowMaximized() const
0060 {
0061     return m_activeWindowMaximized;
0062 }
0063 
0064 void TrackedGeneralInfo::setActiveWindowMaximized(bool activeMaximized)
0065 {
0066     if (m_activeWindowMaximized == activeMaximized) {
0067         return;
0068     }
0069 
0070     m_activeWindowMaximized = activeMaximized;
0071 }
0072 
0073 bool TrackedGeneralInfo::existsWindowActive() const
0074 {
0075     return m_existsWindowActive;
0076 }
0077 
0078 void TrackedGeneralInfo::setExistsWindowActive(bool exists)
0079 {
0080     if (m_existsWindowActive == exists) {
0081         return;
0082     }
0083 
0084     m_existsWindowActive = exists;
0085 }
0086 
0087 bool TrackedGeneralInfo::existsWindowMaximized() const
0088 {
0089     return m_existsWindowMaximized;
0090 }
0091 
0092 void TrackedGeneralInfo::setExistsWindowMaximized(bool maximized)
0093 {
0094     if (m_existsWindowMaximized == maximized) {
0095         return;
0096     }
0097 
0098     m_existsWindowMaximized = maximized;
0099 }
0100 
0101 bool TrackedGeneralInfo::isTrackingCurrentActivity() const
0102 {
0103     return m_isTrackingCurrentActivity;
0104 }
0105 
0106 void TrackedGeneralInfo::updateTrackingCurrentActivity()
0107 {
0108     m_isTrackingCurrentActivity = ( m_activities.isEmpty() || m_activities[0] == QLatin1String("{0}") || m_activities.contains(m_wm->currentActivity()));
0109 }
0110 
0111 bool TrackedGeneralInfo::isTrackingActivity(const QString &activity)
0112 {
0113     return (m_activities.isEmpty() || m_activities[0] == QLatin1String("{0}") || m_activities.contains(activity));
0114 }
0115 
0116 LastActiveWindow *TrackedGeneralInfo::lastActiveWindow() const
0117 {
0118     return m_lastActiveWindow;
0119 }
0120 
0121 SchemeColors *TrackedGeneralInfo::activeWindowScheme() const
0122 {
0123     return m_activeWindowScheme;
0124 }
0125 
0126 void TrackedGeneralInfo::setActiveWindowScheme(SchemeColors *scheme)
0127 {
0128     if (m_activeWindowScheme == scheme) {
0129         return;
0130     }
0131 
0132     m_activeWindowScheme = scheme;
0133 }
0134 
0135 AbstractWindowInterface *TrackedGeneralInfo::wm()
0136 {
0137     return m_wm;
0138 }
0139 
0140 void TrackedGeneralInfo::setActiveWindow(const WindowId &wid)
0141 {
0142     m_lastActiveWindow->setInformation(m_tracker->infoFor(wid));
0143 }
0144 
0145 bool TrackedGeneralInfo::isTracking(const WindowInfoWrap &winfo) const
0146 {
0147     bool isignored = winfo.isMinimized() || (winfo.hasSkipTaskbar() && (winfo.hasSkipPager() || winfo.hasSkipSwitcher()));
0148 
0149     return (winfo.isValid() && !isignored);
0150 }
0151 
0152 bool TrackedGeneralInfo::isShown(const WindowInfoWrap &winfo) const
0153 {
0154     return (winfo.isValid()
0155             && !m_wm->isShowingDesktop()
0156             && isTrackingCurrentActivity()
0157             && winfo.isOnDesktop(m_wm->currentDesktop())
0158             && winfo.isOnActivity(m_wm->currentActivity()));
0159 }
0160 
0161 }
0162 }
0163 }