1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-15 15:24:24 +03:00

add buffer size for LastActiveWindow

This commit is contained in:
Michail Vourlakos 2019-06-09 13:06:06 +03:00
parent 35752bbc2f
commit c16251f743
2 changed files with 24 additions and 3 deletions

View File

@ -37,6 +37,8 @@ namespace WindowSystem {
namespace Tracker { namespace Tracker {
const int INVALIDWID = -1; const int INVALIDWID = -1;
const int PREFHISTORY = 8;
const int MAXHISTORY = 15;
LastActiveWindow::LastActiveWindow(TrackedGeneralInfo *trackedInfo) LastActiveWindow::LastActiveWindow(TrackedGeneralInfo *trackedInfo)
: QObject(trackedInfo), : QObject(trackedInfo),
@ -256,6 +258,7 @@ void LastActiveWindow::setWinId(QVariant winId)
if (!m_history.contains(winId)) { if (!m_history.contains(winId)) {
m_history.prepend(winId); m_history.prepend(winId);
clearHistory();
} else { } else {
int p = m_history.indexOf(winId); int p = m_history.indexOf(winId);
//! move to start //! move to start
@ -298,7 +301,7 @@ void LastActiveWindow::setInformation(const WindowInfoWrap &info)
void LastActiveWindow::windowChanged(const WindowId &wid) void LastActiveWindow::windowChanged(const WindowId &wid)
{ {
if (!m_trackedInfo->enabled()) { if (!m_trackedInfo->enabled()) {
qDebug() << " Window Changed : TrackedInfo is disabled..."; qDebug() << " Last Active Window, Window Changed : TrackedInfo is disabled...";
return; return;
} }
@ -315,7 +318,9 @@ void LastActiveWindow::windowChanged(const WindowId &wid)
if (m_history[0] == wid) { if (m_history[0] == wid) {
firstItemRemoved = true; firstItemRemoved = true;
} }
m_history.removeAll(wid); m_history.removeAll(wid);
clearHistory();
} }
if (m_history.count() > 0) { if (m_history.count() > 0) {
@ -334,9 +339,9 @@ void LastActiveWindow::windowChanged(const WindowId &wid)
setIsValid(false); setIsValid(false);
} }
qDebug() << " HISTORY ::: " << m_history; //qDebug() << " HISTORY ::: " << m_history;
} else { } else {
qDebug() << " LastActiveWindow : window is not in history"; //qDebug() << " LastActiveWindow : window is not in history";
} }
} }
@ -349,6 +354,7 @@ void LastActiveWindow::windowRemoved(const WindowId &wid)
firstItemRemoved = true; firstItemRemoved = true;
} }
m_history.removeAll(wid);
m_history.removeAll(wid); m_history.removeAll(wid);
if (m_history.count() > 0 && firstItemRemoved) { if (m_history.count() > 0 && firstItemRemoved) {
@ -359,6 +365,19 @@ void LastActiveWindow::windowRemoved(const WindowId &wid)
} }
} }
void LastActiveWindow::clearHistory()
{
if (m_history.count() > MAXHISTORY) {
int size = m_history.count();
for(int i=0; i<(size-PREFHISTORY); ++i) {
if (!m_history.isEmpty()) {
m_history.removeLast();
}
}
}
}
//! FUNCTIONALITY //! FUNCTIONALITY
void LastActiveWindow::requestActivate() void LastActiveWindow::requestActivate()
{ {

View File

@ -143,6 +143,8 @@ private:
void setWinId(QVariant winId); void setWinId(QVariant winId);
void clearHistory();
private: private:
bool m_isActive{false}; bool m_isActive{false};
bool m_isMinimized{false}; bool m_isMinimized{false};