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

initial support History for LastActiveWindow

This commit is contained in:
Michail Vourlakos 2019-06-07 18:07:19 +03:00
parent 4ae9b1b91c
commit 79ae6a6de4
6 changed files with 47 additions and 15 deletions

View File

@ -43,6 +43,9 @@ LastActiveWindow::LastActiveWindow(TrackedGeneralInfo *trackedInfo)
m_windowsTracker(trackedInfo->wm()->windowsTracker()),
m_wm(trackedInfo->wm())
{
connect(m_windowsTracker, &Windows::activeWindowChanged, this, &LastActiveWindow::windowChanged);
connect(m_windowsTracker, &Windows::windowChanged, this, &LastActiveWindow::windowChanged);
connect(m_windowsTracker, &Windows::windowRemoved, this, &LastActiveWindow::windowRemoved);
}
LastActiveWindow::~LastActiveWindow()
@ -236,6 +239,14 @@ void LastActiveWindow::setWinId(QVariant winId)
return;
}
if (!m_history.contains(winId)) {
m_history.prepend(winId);
} else {
int p = m_history.indexOf(winId);
//! move to start
m_history.move(p, 0);
}
m_winId = winId;
emit winIdChanged();
}
@ -268,9 +279,32 @@ void LastActiveWindow::setInformation(const WindowInfoWrap &info)
}
//! PRIVATE SLOTS
void LastActiveWindow::windowChanged(const WindowId &wid)
{
if (m_winId == wid && !wid.isNull()) {
setInformation(m_windowsTracker->infoFor(wid));
}
}
void LastActiveWindow::windowRemoved(const WindowId &wid)
{
bool wasFirst{false};
if (m_history.contains(wid)) {
if (m_history[0] == wid) {
wasFirst = true;
}
m_history.removeAll(wid);
}
if (wasFirst && !m_history.isEmpty()) {
setInformation(m_windowsTracker->infoFor(m_history[0]));
}
}
//! FUNCTIONALITY
void LastActiveWindow::requestActivate()
{
m_wm->requestActivate(m_winId);

View File

@ -96,6 +96,12 @@ public slots:
Q_INVOKABLE bool canBeDragged();
private slots:
void windowChanged(const WindowId &wid);
void windowRemoved(const WindowId &wid);
signals:
void draggingStarted();
@ -151,6 +157,8 @@ private:
QVariant m_winId;
QList<WindowId> m_history;
TrackedGeneralInfo *m_trackedInfo{nullptr};
AbstractWindowInterface *m_wm{nullptr};
Tracker::Windows *m_windowsTracker{nullptr};

View File

@ -37,9 +37,6 @@ TrackedGeneralInfo::TrackedGeneralInfo(Tracker::Windows *tracker, Latte::View *v
{
m_lastActiveWindow = new LastActiveWindow(this);
connect(tracker, &Windows::windowChanged, this, &TrackedGeneralInfo::windowChanged);
connect(tracker, &Windows::activeWindowChanged, this, &TrackedGeneralInfo::windowChanged);
emit lastActiveWindowChanged();
}
@ -145,13 +142,6 @@ void TrackedGeneralInfo::setActiveWindow(const WindowId &wid)
m_lastActiveWindow->setInformation(m_tracker->infoFor(wid));
}
void TrackedGeneralInfo::windowChanged(const WindowId &wid)
{
if (m_lastActiveWindow->winId() == wid && !wid.isNull()) {
m_lastActiveWindow->setInformation(m_tracker->infoFor(wid));
}
}
}
}
}

View File

@ -79,9 +79,6 @@ public:
signals:
void lastActiveWindowChanged();
private slots:
void windowChanged(const WindowId &wid);
private:
bool m_enabled;
bool m_activeWindowMaximized;

View File

@ -68,6 +68,8 @@ void Windows::init()
connect(m_wm, &AbstractWindowInterface::windowRemoved, this, [&](WindowId wid) {
m_windows.remove(wid);
updateViewsHints();
emit windowRemoved(wid);
});
connect(m_wm, &AbstractWindowInterface::windowAdded, this, [&](WindowId wid) {

View File

@ -90,6 +90,7 @@ signals:
//! inform consumers for window changes
void activeWindowChanged(const WindowId &wid);
void windowChanged(const WindowId &wid);
void windowRemoved(const WindowId &wid);
private slots:
void updateAvailableScreenGeometries();