diff --git a/panels/dock/taskmanager/taskmanager.cpp b/panels/dock/taskmanager/taskmanager.cpp index 70116b7b6..bdcd746a9 100644 --- a/panels/dock/taskmanager/taskmanager.cpp +++ b/panels/dock/taskmanager/taskmanager.cpp @@ -27,6 +27,7 @@ #include #include +#include #ifdef BUILD_WITH_X11 #include "x11windowmonitor.h" @@ -44,6 +45,25 @@ Q_LOGGING_CATEGORY(taskManagerLog, "dde.shell.dock.taskmanager", QtDebugMsg) namespace dock { +// 通过AM(Application Manager)匹配应用程序的辅助函数 +static QString getDesktopIdByPid(const QStringList &identifies) +{ + if (identifies.isEmpty()) + return {}; + + pid_t windowPid = identifies.last().toInt(); + if (windowPid <= 0) + return {}; + + auto appId = DSGApplication::getId(windowPid); + if (appId.isEmpty()) { + qCDebug(taskManagerLog) << "appId is empty, AM failed to identify window with pid:" << windowPid; + return {}; + } + + return QString::fromUtf8(appId); +} + class BoolFilterModel : public QSortFilterProxyModel, public AbstractTaskManagerInterface { Q_OBJECT @@ -128,6 +148,16 @@ bool TaskManager::init() } } } + + // 尝试通过AM(Application Manager)匹配应用程序 + auto desktopId = getDesktopIdByPid(identifies); + if (!desktopId.isEmpty()) { + auto res = model->match(model->index(0, 0), roleNames.key(MODEL_DESKTOPID), desktopId, 1, Qt::MatchFixedString | Qt::MatchWrap).value(0); + if (res.isValid()) { + qCDebug(taskManagerLog) << "matched by AM desktop ID:" << desktopId << res; + return res; + } + } auto res = model->match(model->index(0, 0), roleNames.key(MODEL_DESKTOPID), identifies.value(0), 1, Qt::MatchEndsWith); qCDebug(taskManagerLog) << "matched" << res.value(0); diff --git a/panels/dock/taskmanager/x11window.cpp b/panels/dock/taskmanager/x11window.cpp index adddaf363..cbfb5452c 100644 --- a/panels/dock/taskmanager/x11window.cpp +++ b/panels/dock/taskmanager/x11window.cpp @@ -49,11 +49,6 @@ QStringList X11Window::identity() { if (m_identity.isEmpty()) { m_identity = X11->getWindowWMClass(m_windowID); - if (auto appItem = getAppItem()) { - m_identity.append(appItem->desktopfileID()); - } else { - qCWarning(x11windowLog) << "identify not found appitem." << id(); - } m_identity.append(QString::number(pid())); } diff --git a/panels/dock/taskmanager/x11windowmonitor.cpp b/panels/dock/taskmanager/x11windowmonitor.cpp index f3451a610..4ecaa442d 100644 --- a/panels/dock/taskmanager/x11windowmonitor.cpp +++ b/panels/dock/taskmanager/x11windowmonitor.cpp @@ -175,9 +175,8 @@ void X11WindowMonitor::onWindowMapped(xcb_window_t xcb_window) uint32_t value_list[] = { XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_VISIBILITY_CHANGE}; xcb_change_window_attributes(X11->getXcbConnection(), xcb_window, XCB_CW_EVENT_MASK, value_list); - Q_EMIT AbstractWindowMonitor::windowAdded(static_cast>(window.get())); trackWindow(window.get()); - + Q_EMIT AbstractWindowMonitor::windowAdded(static_cast>(window.get())); } void X11WindowMonitor::onWindowDestroyed(xcb_window_t xcb_window)