1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-24 17:33:50 +03:00

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
This commit is contained in:
Michail Vourlakos 2019-05-27 20:09:48 +03:00
parent 97332cc8cf
commit b6520b1cd8
5 changed files with 55 additions and 4 deletions

View File

@ -35,10 +35,25 @@ AbstractWindowInterface::AbstractWindowInterface(QObject *parent)
m_corona = qobject_cast<Latte::Corona *>(parent);
m_windowsTracker = new WindowsTracker(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()
{
m_windowWaitingTimer.stop();
m_schemesTracker->deleteLater();
m_windowsTracker->deleteLater();
}
@ -58,6 +73,33 @@ WindowsTracker *AbstractWindowInterface::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();
}
}
}
}

View File

@ -40,6 +40,7 @@
#include <QPoint>
#include <QPointer>
#include <QScreen>
#include <QTimer>
// KDE
#include <KActivities/Consumer>
@ -117,10 +118,19 @@ signals:
protected:
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:
Latte::Corona *m_corona;
SchemesTracker *m_schemesTracker;
WindowsTracker *m_windowsTracker;
};
}

View File

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

View File

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

View File

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