diff --git a/src/activity.cpp b/src/activity.cpp index b1fb2aa..4c18640 100644 --- a/src/activity.cpp +++ b/src/activity.cpp @@ -39,7 +39,7 @@ Activity::Activity(QObject *parent) onActiveWindowChanged(); connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &Activity::onActiveWindowChanged); - connect(KWindowSystem::self(), static_cast(&KWindowSystem::windowChanged), + connect(KWindowSystem::self(), static_cast(&KWindowSystem::windowChanged), this, &Activity::onActiveWindowChanged); } @@ -119,7 +119,7 @@ void Activity::onActiveWindowChanged() m_pid = info.pid(); m_windowClass = info.windowClassClass().toLower(); - CAppItem *item = m_cApps->matchItem(m_pid); + CAppItem *item = m_cApps->matchItem(m_pid, m_windowClass); if (item) { m_title = item->localName; diff --git a/src/capplications.cpp b/src/capplications.cpp index 2fea3b7..616991c 100644 --- a/src/capplications.cpp +++ b/src/capplications.cpp @@ -71,13 +71,13 @@ CAppItem *CApplications::find(const QString &fileName) return nullptr; } -CAppItem *CApplications::matchItem(quint32 pid) +CAppItem *CApplications::matchItem(quint32 pid, const QString &windowClass) { QStringList commands = commandFromPid(pid); // The value returned from the commandFromPid() may be empty. // Calling first() and last() below will cause the statusbar to crash. - if (commands.isEmpty()) + if (commands.isEmpty() || windowClass.isEmpty()) return nullptr; QString command = commands.first(); @@ -87,15 +87,35 @@ CAppItem *CApplications::matchItem(quint32 pid) return nullptr; for (CAppItem *item : m_items) { + bool founded = false; + + // Command name if (item->fullExec == command || - item->exec == command || - item->fullExec == commandName || - item->exec == commandName || - // FileName - item->fileName == command || - item->fileName == commandName) { + item->exec == command || + item->fullExec == commandName || + item->exec == commandName) + founded = true; + + // Desktop name + if (!founded && (item->fileName == command + || item->fileName == commandName)) + founded = true; + + if (!founded && item->fileName.startsWith(windowClass, Qt::CaseInsensitive)) + founded = true; + + // Try matching mapped name against 'Name'. + if (!founded && item->name.startsWith(windowClass, Qt::CaseInsensitive)) + founded = true; + + // Icon Name + if (!founded && item->icon == command) + founded = true; + + if (founded) return item; - } + else + continue; } return nullptr; diff --git a/src/capplications.h b/src/capplications.h index 88ba9c1..0ef2e55 100644 --- a/src/capplications.h +++ b/src/capplications.h @@ -46,7 +46,7 @@ public: ~CApplications(); CAppItem *find(const QString &fileName); - CAppItem *matchItem(quint32 pid); + CAppItem *matchItem(quint32 pid, const QString &windowClass); private: void refresh();