File indexing completed on 2025-03-16 13:58:23
0001 /* 0002 * Copyright 2019 Michail Vourlakos <mvourlakos@gmail.com> 0003 * 0004 * This file is part of Latte-Dock 0005 * 0006 * Latte-Dock is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * Latte-Dock is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include "trackedgeneralinfo.h" 0021 0022 //local 0023 #include "windowstracker.h" 0024 #include "../abstractwindowinterface.h" 0025 #include "../schemecolors.h" 0026 0027 namespace Latte { 0028 namespace WindowSystem { 0029 namespace Tracker { 0030 0031 0032 TrackedGeneralInfo::TrackedGeneralInfo(Tracker::Windows *tracker) 0033 : QObject(tracker) , 0034 m_wm(tracker->wm()), 0035 m_tracker(tracker) 0036 { 0037 m_lastActiveWindow = new LastActiveWindow(this); 0038 0039 connect(m_wm, &AbstractWindowInterface::currentActivityChanged, this, [&]() { 0040 updateTrackingCurrentActivity(); 0041 }); 0042 0043 emit lastActiveWindowChanged(); 0044 } 0045 0046 TrackedGeneralInfo::~TrackedGeneralInfo() 0047 { 0048 if (m_lastActiveWindow) { 0049 auto law = m_lastActiveWindow; 0050 m_lastActiveWindow = nullptr; 0051 emit lastActiveWindowChanged(); 0052 0053 law->deleteLater(); 0054 } 0055 } 0056 0057 bool TrackedGeneralInfo::enabled() const 0058 { 0059 return m_enabled; 0060 } 0061 0062 void TrackedGeneralInfo::setEnabled(bool enabled) 0063 { 0064 if (m_enabled == enabled) { 0065 return; 0066 } 0067 0068 m_enabled = enabled; 0069 } 0070 0071 bool TrackedGeneralInfo::activeWindowMaximized() const 0072 { 0073 return m_activeWindowMaximized; 0074 } 0075 0076 void TrackedGeneralInfo::setActiveWindowMaximized(bool activeMaximized) 0077 { 0078 if (m_activeWindowMaximized == activeMaximized) { 0079 return; 0080 } 0081 0082 m_activeWindowMaximized = activeMaximized; 0083 } 0084 0085 bool TrackedGeneralInfo::existsWindowActive() const 0086 { 0087 return m_existsWindowActive; 0088 } 0089 0090 void TrackedGeneralInfo::setExistsWindowActive(bool exists) 0091 { 0092 if (m_existsWindowActive == exists) { 0093 return; 0094 } 0095 0096 m_existsWindowActive = exists; 0097 } 0098 0099 bool TrackedGeneralInfo::existsWindowMaximized() const 0100 { 0101 return m_existsWindowMaximized; 0102 } 0103 0104 void TrackedGeneralInfo::setExistsWindowMaximized(bool maximized) 0105 { 0106 if (m_existsWindowMaximized == maximized) { 0107 return; 0108 } 0109 0110 m_existsWindowMaximized = maximized; 0111 } 0112 0113 bool TrackedGeneralInfo::isTrackingCurrentActivity() const 0114 { 0115 return m_isTrackingCurrentActivity; 0116 } 0117 0118 void TrackedGeneralInfo::updateTrackingCurrentActivity() 0119 { 0120 m_isTrackingCurrentActivity = ( m_activities.isEmpty() 0121 || m_activities[0] == "0" 0122 || m_activities.contains(m_wm->currentActivity())); 0123 } 0124 0125 0126 LastActiveWindow *TrackedGeneralInfo::lastActiveWindow() const 0127 { 0128 return m_lastActiveWindow; 0129 } 0130 0131 SchemeColors *TrackedGeneralInfo::activeWindowScheme() const 0132 { 0133 return m_activeWindowScheme; 0134 } 0135 0136 void TrackedGeneralInfo::setActiveWindowScheme(SchemeColors *scheme) 0137 { 0138 if (m_activeWindowScheme == scheme) { 0139 return; 0140 } 0141 0142 m_activeWindowScheme = scheme; 0143 } 0144 0145 AbstractWindowInterface *TrackedGeneralInfo::wm() 0146 { 0147 return m_wm; 0148 } 0149 0150 void TrackedGeneralInfo::setActiveWindow(const WindowId &wid) 0151 { 0152 m_lastActiveWindow->setInformation(m_tracker->infoFor(wid)); 0153 } 0154 0155 bool TrackedGeneralInfo::isTracking(const WindowInfoWrap &winfo) const 0156 { 0157 return (winfo.isValid() 0158 && isTrackingCurrentActivity() 0159 && !winfo.isPlasmaDesktop() 0160 && !winfo.isMinimized() 0161 && winfo.isOnDesktop(m_wm->currentDesktop()) 0162 && winfo.isOnActivity(m_wm->currentActivity())); 0163 } 0164 0165 } 0166 } 0167 }