Match more application names

pull/7/head
reionwong 5 years ago
parent 705ff11465
commit c8f552a868

@ -39,7 +39,7 @@ Activity::Activity(QObject *parent)
onActiveWindowChanged();
connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &Activity::onActiveWindowChanged);
connect(KWindowSystem::self(), static_cast<void (KWindowSystem::*)(WId)>(&KWindowSystem::windowChanged),
connect(KWindowSystem::self(), static_cast<void (KWindowSystem::*)(WId id, NET::Properties properties, NET::Properties2 properties2)>(&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;

@ -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;

@ -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();

Loading…
Cancel
Save