From d5b7694d4d105998e92703d7530ffc74ffa9a1cf Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Thu, 31 Oct 2019 17:04:54 +0200 Subject: [PATCH] update application data after 1500ms from startup --when an application is tracked from the lastactivewindow infrastructure it is updating the application name/icon 1500 ms after its first startup in order to fix apps cases where they update their StartupWMClass a bit delayed BUG:413671 --- app/wm/tracker/lastactivewindow.cpp | 23 +++++++++++++++++++++++ app/wm/tracker/lastactivewindow.h | 8 ++++++++ app/wm/tracker/windowstracker.cpp | 4 ++-- app/wm/tracker/windowstracker.h | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/wm/tracker/lastactivewindow.cpp b/app/wm/tracker/lastactivewindow.cpp index 3edac02d3..4f10e64f9 100644 --- a/app/wm/tracker/lastactivewindow.cpp +++ b/app/wm/tracker/lastactivewindow.cpp @@ -56,6 +56,17 @@ LastActiveWindow::LastActiveWindow(TrackedGeneralInfo *trackedInfo) connect(m_windowsTracker, &Windows::windowChanged, this, &LastActiveWindow::windowChanged); connect(m_windowsTracker, &Windows::windowRemoved, this, &LastActiveWindow::windowRemoved); + + //! delayed application data + m_updateApplicationDataTimer.setInterval(1500); + m_updateApplicationDataTimer.setSingleShot(true); + connect(&m_updateApplicationDataTimer, &QTimer::timeout, this, [&]() { + if (m_delayedApplicationDataWid>=0 && m_delayedApplicationDataWid == m_winId && !m_initializedApplicationData.contains(m_winId)) { + setAppName(m_windowsTracker->appNameFor(m_winId, true)); + m_delayedApplicationDataWid = -1; + m_initializedApplicationData.append(m_winId); + } + }); } LastActiveWindow::~LastActiveWindow() @@ -315,6 +326,14 @@ void LastActiveWindow::setInformation(const WindowInfoWrap &info) if (firstActiveness) { updateColorScheme(); + + //delayed application data + m_updateApplicationDataTimer.stop(); + + if (!m_initializedApplicationData.contains(info.wid())) { + m_delayedApplicationDataWid = info.wid(); + m_updateApplicationDataTimer.start(); + } } if (info.appName().isEmpty()) { @@ -380,6 +399,10 @@ void LastActiveWindow::windowChanged(const WindowId &wid) void LastActiveWindow::windowRemoved(const WindowId &wid) { + if (m_initializedApplicationData.contains(wid)) { + m_initializedApplicationData.removeAll(wid); + } + if (m_history.contains(wid)) { bool firstItemRemoved{false}; diff --git a/app/wm/tracker/lastactivewindow.h b/app/wm/tracker/lastactivewindow.h index 0e914abf6..6721a9b29 100644 --- a/app/wm/tracker/lastactivewindow.h +++ b/app/wm/tracker/lastactivewindow.h @@ -27,6 +27,7 @@ // Qt #include #include +#include namespace Latte { class View; @@ -174,6 +175,13 @@ private: QList m_history; + //! Some applications delay their application name/icon identification + //! such as Libreoffice that updates its StartupWMClass after + //! its startup + QTimer m_updateApplicationDataTimer; + QList m_initializedApplicationData; + WindowId m_delayedApplicationDataWid{-1}; + TrackedGeneralInfo *m_trackedInfo{nullptr}; AbstractWindowInterface *m_wm{nullptr}; Tracker::Windows *m_windowsTracker{nullptr}; diff --git a/app/wm/tracker/windowstracker.cpp b/app/wm/tracker/windowstracker.cpp index 9e13670a4..08c346be9 100644 --- a/app/wm/tracker/windowstracker.cpp +++ b/app/wm/tracker/windowstracker.cpp @@ -583,13 +583,13 @@ QIcon Windows::iconFor(const WindowId &wid) return m_windows[wid].icon(); } -QString Windows::appNameFor(const WindowId &wid) +QString Windows::appNameFor(const WindowId &wid, bool forceUpdate) { if (!m_windows.contains(wid)) { return QString(); } - if (m_windows[wid].appName().isEmpty()) { + if (m_windows[wid].appName().isEmpty() || forceUpdate) { AppData data = m_wm->appDataFor(wid); m_windows[wid].setAppName(data.name); diff --git a/app/wm/tracker/windowstracker.h b/app/wm/tracker/windowstracker.h index 7b32478cd..d78cdc224 100644 --- a/app/wm/tracker/windowstracker.h +++ b/app/wm/tracker/windowstracker.h @@ -85,7 +85,7 @@ public: //! Windows management bool isValidFor(const WindowId &wid) const; QIcon iconFor(const WindowId &wid); - QString appNameFor(const WindowId &wid); + QString appNameFor(const WindowId &wid, bool forceUpdate = false); WindowInfoWrap infoFor(const WindowId &wid) const; void setPlasmaDesktop(WindowId wid);