1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-26 23:21:37 +03:00

proceed with implementation of LastActiveWindow

This commit is contained in:
Michail Vourlakos 2019-06-09 12:47:10 +03:00
parent 29bbba1730
commit 35752bbc2f
5 changed files with 73 additions and 19 deletions

View File

@ -36,13 +36,14 @@ namespace Latte {
namespace WindowSystem {
namespace Tracker {
const int INVALIDWID = -1;
LastActiveWindow::LastActiveWindow(TrackedGeneralInfo *trackedInfo)
: QObject(trackedInfo),
m_trackedInfo(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);
}
@ -156,6 +157,21 @@ void LastActiveWindow::setIsShaded(bool shaded)
emit isShadedChanged();
}
bool LastActiveWindow::isValid() const
{
return m_isValid;
}
void LastActiveWindow::setIsValid(bool valid)
{
if (m_isValid == valid) {
return;
}
m_isValid = valid;
emit isValidChanged();
}
bool LastActiveWindow::hasSkipTaskbar() const
{
return m_hasSkipTaskbar;
@ -234,7 +250,7 @@ QVariant LastActiveWindow::winId() const
void LastActiveWindow::setWinId(QVariant winId)
{
if (m_winId == winId) {
if (m_winId == winId && isValid()) {
return;
}
@ -254,6 +270,7 @@ void LastActiveWindow::setInformation(const WindowInfoWrap &info)
{
setWinId(info.wid());
setIsValid(true);
setActive(info.isActive());
setIsMinimized(info.isMinimized());
setIsMaximized(info.isMaxVert() || info.isMaxHoriz());
@ -275,41 +292,69 @@ void LastActiveWindow::setInformation(const WindowInfoWrap &info)
} else {
setIcon(info.icon());
}
}
//! PRIVATE SLOTS
void LastActiveWindow::windowChanged(const WindowId &wid)
{
if (!m_trackedInfo->enabled()) {
qDebug() << " Window Changed : TrackedInfo is disabled...";
return;
}
if (m_winId == wid && !wid.isNull()) {
setInformation(m_windowsTracker->infoFor(wid));
} else if (m_history.contains(wid)) {
if (m_history.contains(wid)) {
//! remove from history minimized windows or windows that changed screen
//! and update information accordingly with the first window found from
//! and update information accordingly with the first valid window found from
//! history after the removal
WindowInfoWrap winfo = m_windowsTracker->infoFor(wid);
if (winfo.isMinimized() || !m_trackedInfo->isTracking(winfo)) {
m_history.removeAll(wid);
bool firstItemRemoved{false};
if (m_history.count() > 0) {
setInformation(m_windowsTracker->infoFor(m_history[0]));
//! Remove minimized windows OR NOT-TRACKED windows from history
if (winfo.isMinimized() || !m_trackedInfo->isTracking(winfo)) {
if (m_history[0] == wid) {
firstItemRemoved = true;
}
m_history.removeAll(wid);
}
if (m_history.count() > 0) {
if (m_history[0] == wid || firstItemRemoved) {
WindowInfoWrap history1 = m_windowsTracker->infoFor(m_history[0]);
//! Check if first found History window is still valid to show its information
if (history1.isMinimized() || !m_trackedInfo->isTracking(history1)) {
windowChanged(m_history[0]);
} else {
setInformation(history1);
}
}
} else {
//! History is empty so any demonstrated information are invalid
setIsValid(false);
}
qDebug() << " HISTORY ::: " << m_history;
} else {
qDebug() << " LastActiveWindow : window is not in history";
}
}
void LastActiveWindow::windowRemoved(const WindowId &wid)
{
if (m_history.contains(wid)) {
bool firstItemRemoved{false};
if (m_history.count() > 0 && m_history[0] == wid) {
firstItemRemoved = true;
}
m_history.removeAll(wid);
if (m_history.count() > 0) {
setInformation(m_windowsTracker->infoFor(m_history[0]));
if (m_history.count() > 0 && firstItemRemoved) {
windowChanged(m_history[0]);
} else {
setIsValid(false);
}
}
}

View File

@ -52,6 +52,7 @@ class LastActiveWindow : public QObject {
Q_PROPERTY(bool isKeepAbove READ isKeepAbove NOTIFY isKeepAboveChanged)
Q_PROPERTY(bool isOnAllDesktops READ isOnAllDesktops NOTIFY isOnAllDesktopsChanged)
Q_PROPERTY(bool isShaded READ isShaded NOTIFY isShadedChanged)
Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged)
Q_PROPERTY(bool hasSkipTaskbar READ hasSkipTaskbar NOTIFY hasSkipTaskbarChanged)
Q_PROPERTY(QString appName READ appName NOTIFY appNameChanged)
@ -73,6 +74,7 @@ public:
bool isKeepAbove() const;
bool isOnAllDesktops() const;
bool isShaded() const;
bool isValid() const;
bool hasSkipTaskbar() const;
QString appName() const;
@ -113,6 +115,7 @@ signals:
void isKeepAboveChanged();
void isOnAllDesktopsChanged();
void isShadedChanged();
void isValidChanged();
void hasSkipTaskbarChanged();
void appNameChanged();
@ -129,6 +132,7 @@ private:
void setIsKeepAbove(bool above);
void setIsOnAllDesktops(bool all);
void setIsShaded(bool shaded);
void setIsValid(bool valid);
void setHasSkipTaskbar(bool skip);
void setAppName(QString appName);
@ -147,6 +151,7 @@ private:
bool m_isKeepAbove{false};
bool m_isOnAllDesktops{false};
bool m_isShaded{false};
bool m_isValid{false};
bool m_hasSkipTaskbar{false};
QString m_appName;

View File

@ -108,7 +108,7 @@ Latte::View *TrackedViewInfo::view() const
}
bool TrackedViewInfo::isTracking(const WindowInfoWrap &winfo) const
{
{
return TrackedGeneralInfo::isTracking(winfo)
&& m_availableScreenGeometry.contains(winfo.geometry().center());
}

View File

@ -170,7 +170,7 @@ void Windows::addView(Latte::View *view)
addRelevantLayout(view);
});
updateHints(view);
updateAllHints();
emit informationAnnounced(view);
}

View File

@ -763,7 +763,8 @@ Window{
}
Text{
text: latteView && latteView.windowsTracker ? latteView.windowsTracker.currentScreen.lastActiveWindow.winId : "--"
text: latteView && latteView.windowsTracker && latteView.windowsTracker.currentScreen.lastActiveWindow.isValid ?
latteView.windowsTracker.currentScreen.lastActiveWindow.winId : "--"
}
Text{
@ -771,7 +772,8 @@ Window{
}
Text{
text: latteView && latteView.windowsTracker ? latteView.windowsTracker.currentScreen.lastActiveWindow.display : "--"
text: latteView && latteView.windowsTracker && latteView.windowsTracker.currentScreen.lastActiveWindow.isValid ?
latteView.windowsTracker.currentScreen.lastActiveWindow.display : "--"
elide: Text.ElideRight
}
@ -780,7 +782,8 @@ Window{
}
Text{
text: latteView && latteView.windowsTracker ? latteView.windowsTracker.allScreens.lastActiveWindow.winId : "--"
text: latteView && latteView.windowsTracker && latteView.windowsTracker.allScreens.lastActiveWindow.isValid ?
latteView.windowsTracker.allScreens.lastActiveWindow.winId : "--"
}
Text{
@ -788,7 +791,8 @@ Window{
}
Text{
text: latteView && latteView.windowsTracker ? latteView.windowsTracker.allScreens.lastActiveWindow.display : "--"
text: latteView && latteView.windowsTracker && latteView.windowsTracker.allScreens.lastActiveWindow.isValid ?
latteView.windowsTracker.allScreens.lastActiveWindow.display : "--"
elide: Text.ElideRight
}
}