Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions panels/dock/taskmanager/taskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <QStandardPaths>

#include <appletbridge.h>
#include <DSGApplication>

#ifdef BUILD_WITH_X11
#include "x11windowmonitor.h"
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions panels/dock/taskmanager/x11window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand Down
3 changes: 1 addition & 2 deletions panels/dock/taskmanager/x11windowmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QPointer<AbstractWindow>>(window.get()));
trackWindow(window.get());

Q_EMIT AbstractWindowMonitor::windowAdded(static_cast<QPointer<AbstractWindow>>(window.get()));
}

void X11WindowMonitor::onWindowDestroyed(xcb_window_t xcb_window)
Expand Down