Match more application names

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

@ -39,7 +39,7 @@ Activity::Activity(QObject *parent)
onActiveWindowChanged(); onActiveWindowChanged();
connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &Activity::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); this, &Activity::onActiveWindowChanged);
} }
@ -119,7 +119,7 @@ void Activity::onActiveWindowChanged()
m_pid = info.pid(); m_pid = info.pid();
m_windowClass = info.windowClassClass().toLower(); m_windowClass = info.windowClassClass().toLower();
CAppItem *item = m_cApps->matchItem(m_pid); CAppItem *item = m_cApps->matchItem(m_pid, m_windowClass);
if (item) { if (item) {
m_title = item->localName; m_title = item->localName;

@ -71,13 +71,13 @@ CAppItem *CApplications::find(const QString &fileName)
return nullptr; return nullptr;
} }
CAppItem *CApplications::matchItem(quint32 pid) CAppItem *CApplications::matchItem(quint32 pid, const QString &windowClass)
{ {
QStringList commands = commandFromPid(pid); QStringList commands = commandFromPid(pid);
// The value returned from the commandFromPid() may be empty. // The value returned from the commandFromPid() may be empty.
// Calling first() and last() below will cause the statusbar to crash. // Calling first() and last() below will cause the statusbar to crash.
if (commands.isEmpty()) if (commands.isEmpty() || windowClass.isEmpty())
return nullptr; return nullptr;
QString command = commands.first(); QString command = commands.first();
@ -87,15 +87,35 @@ CAppItem *CApplications::matchItem(quint32 pid)
return nullptr; return nullptr;
for (CAppItem *item : m_items) { for (CAppItem *item : m_items) {
bool founded = false;
// Command name
if (item->fullExec == command || if (item->fullExec == command ||
item->exec == command || item->exec == command ||
item->fullExec == commandName || item->fullExec == commandName ||
item->exec == commandName || item->exec == commandName)
// FileName founded = true;
item->fileName == command ||
item->fileName == commandName) { // 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; return item;
} else
continue;
} }
return nullptr; return nullptr;

@ -46,7 +46,7 @@ public:
~CApplications(); ~CApplications();
CAppItem *find(const QString &fileName); CAppItem *find(const QString &fileName);
CAppItem *matchItem(quint32 pid); CAppItem *matchItem(quint32 pid, const QString &windowClass);
private: private:
void refresh(); void refresh();

Loading…
Cancel
Save