Improve WindowTracker CPU usage

--add a Timer in order to not sent too many
batch signals for windowChanged with no reason
and send only one at the end of the Timer::trigger
pull/6/head
Michail Vourlakos 6 years ago
parent 97332cc8cf
commit b6520b1cd8

@ -35,10 +35,25 @@ AbstractWindowInterface::AbstractWindowInterface(QObject *parent)
m_corona = qobject_cast<Latte::Corona *>(parent); m_corona = qobject_cast<Latte::Corona *>(parent);
m_windowsTracker = new WindowsTracker(this); m_windowsTracker = new WindowsTracker(this);
m_schemesTracker = new SchemesTracker(this); m_schemesTracker = new SchemesTracker(this);
m_windowWaitingTimer.setInterval(150);
m_windowWaitingTimer.setSingleShot(true);
connect(&m_windowWaitingTimer, &QTimer::timeout, this, [&]() {
WindowId wid = m_windowChangedWaiting;
m_windowChangedWaiting = QVariant();
emit windowChanged(wid);
});
connect(this, &AbstractWindowInterface::windowChanged, this, [&](WindowId wid) {
qDebug() << "WINDOW CHANGED ::: " << wid;
});
} }
AbstractWindowInterface::~AbstractWindowInterface() AbstractWindowInterface::~AbstractWindowInterface()
{ {
m_windowWaitingTimer.stop();
m_schemesTracker->deleteLater(); m_schemesTracker->deleteLater();
m_windowsTracker->deleteLater(); m_windowsTracker->deleteLater();
} }
@ -58,6 +73,33 @@ WindowsTracker *AbstractWindowInterface::windowsTracker()
return m_windowsTracker; return m_windowsTracker;
} }
void AbstractWindowInterface::considerWindowChanged(WindowId wid)
{
//! Consider if the windowChanged signal should be sent DIRECTLY or WAIT
if (m_windowChangedWaiting == wid && m_windowWaitingTimer.isActive()) {
//! window should be sent later
m_windowWaitingTimer.start();
return;
}
if (m_windowChangedWaiting != wid && !m_windowWaitingTimer.isActive()) {
//! window should be sent later
m_windowChangedWaiting = wid;
m_windowWaitingTimer.start();
}
if (m_windowChangedWaiting != wid && m_windowWaitingTimer.isActive()) {
m_windowWaitingTimer.stop();
//! sent previous waiting window
emit (m_windowChangedWaiting);
//! retrigger waiting for the upcoming window
m_windowChangedWaiting = wid;
m_windowWaitingTimer.start();
}
}
} }
} }

@ -40,6 +40,7 @@
#include <QPoint> #include <QPoint>
#include <QPointer> #include <QPointer>
#include <QScreen> #include <QScreen>
#include <QTimer>
// KDE // KDE
#include <KActivities/Consumer> #include <KActivities/Consumer>
@ -117,10 +118,19 @@ signals:
protected: protected:
QPointer<KActivities::Consumer> m_activities; QPointer<KActivities::Consumer> m_activities;
//! Sending too fast plenty of signals for the same window
//! has no reason and can create HIGH CPU usage. This Timer
//! can delay the batch sending of signals for the same window
WindowId m_windowChangedWaiting;
QTimer m_windowWaitingTimer;
void considerWindowChanged(WindowId wid);
private: private:
Latte::Corona *m_corona; Latte::Corona *m_corona;
SchemesTracker *m_schemesTracker; SchemesTracker *m_schemesTracker;
WindowsTracker *m_windowsTracker; WindowsTracker *m_windowsTracker;
}; };
} }

@ -564,7 +564,7 @@ void WaylandInterface::windowCreatedProxy(KWayland::Client::PlasmaWindow *w)
PlasmaWindow *pW = qobject_cast<PlasmaWindow*>(w); PlasmaWindow *pW = qobject_cast<PlasmaWindow*>(w);
if (pW && !isPlasmaDesktop(pW) && pW->appId() != QLatin1String("latte-dock")) { if (pW && !isPlasmaDesktop(pW) && pW->appId() != QLatin1String("latte-dock")) {
emit windowChanged(pW->internalId()); considerWindowChanged(pW->internalId());
} }
}); });

@ -453,7 +453,6 @@ void WindowsTracker::updateHints(Latte::View *view)
if (isActiveInViewScreen(view, winfo)) { if (isActiveInViewScreen(view, winfo)) {
m_views[view].lastActiveWindow = winfo.wid(); m_views[view].lastActiveWindow = winfo.wid();
qDebug() << " a w d :: " << winfo.display();
foundActiveInCurScreen = true; foundActiveInCurScreen = true;
activeWinId = winfo.wid(); activeWinId = winfo.wid();
} }

@ -464,7 +464,7 @@ void XWindowInterface::windowChangedProxy(WId wid, NET::Properties prop1, NET::P
if ((prop1 & NET::WMState) if ((prop1 & NET::WMState)
&& !(prop1 & NET::WMGeometry) && !(prop1 & NET::WMGeometry)
&& !(prop1 & NET::ActiveWindow) && !(prop1 & NET::ActiveWindow)
&& !(prop1 & NET::WMVisibleName)) { && !(prop1 & (NET::WMName | NET::WMVisibleName)) ) {
KWindowInfo info(wid, NET::WMState); KWindowInfo info(wid, NET::WMState);
if (info.valid()) { if (info.valid()) {
@ -477,7 +477,7 @@ void XWindowInterface::windowChangedProxy(WId wid, NET::Properties prop1, NET::P
} }
} }
emit windowChanged(wid); considerWindowChanged(wid);
} }
} }

Loading…
Cancel
Save