From e817c291bc34d8702154bc87fe838acbe69302dc Mon Sep 17 00:00:00 2001 From: weizhixiang Date: Thu, 26 May 2022 18:10:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DDock=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E5=B1=9E=E6=80=A7=E5=BC=82=E5=B8=B8=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复Dock模块窗口属性WindowInfo异常的问题 log: Task: https://pms.uniontech.com/task-view-136759.html Influence: 无 Change-Id: I9bf9e532ec003d4ba7d35d6a5ed0af4e3b5d299d --- src/frameworkdbus/types/dockrect.cpp | 2 +- src/frameworkdbus/types/exportwindowinfo.cpp | 51 ++++++++++++ src/frameworkdbus/types/exportwindowinfo.h | 31 +++++++ .../types/exportwindowinfolist.cpp | 18 +++++ .../types/exportwindowinfolist.h | 18 +++++ src/modules/dock/dbusadaptorentry.cpp | 36 ++------- src/modules/dock/dbusadaptorentry.h | 81 +++++++++---------- src/modules/dock/dbushandler.cpp | 4 +- src/modules/dock/dock.cpp | 5 +- src/modules/dock/entry.cpp | 58 ++++++++----- src/modules/dock/entry.h | 14 ++-- src/modules/dock/windowidentify.cpp | 4 + src/modules/dock/windowinfox.cpp | 5 ++ src/modules/dock/windowpatterns.cpp | 7 ++ src/modules/dock/windowpatterns.h | 2 +- src/modules/dock/x11manager.cpp | 4 +- 16 files changed, 231 insertions(+), 109 deletions(-) create mode 100644 src/frameworkdbus/types/exportwindowinfo.cpp create mode 100644 src/frameworkdbus/types/exportwindowinfo.h create mode 100644 src/frameworkdbus/types/exportwindowinfolist.cpp create mode 100644 src/frameworkdbus/types/exportwindowinfolist.h diff --git a/src/frameworkdbus/types/dockrect.cpp b/src/frameworkdbus/types/dockrect.cpp index e2390d8..d486056 100644 --- a/src/frameworkdbus/types/dockrect.cpp +++ b/src/frameworkdbus/types/dockrect.cpp @@ -12,7 +12,7 @@ DockRect::DockRect() QDebug operator<<(QDebug debug, const DockRect &rect) { - debug << QString("Rect(%1, %2, %3, %4)").arg(rect.X) + debug << QString("DockRect(%1, %2, %3, %4)").arg(rect.X) .arg(rect.Y) .arg(rect.Width) .arg(rect.Height); diff --git a/src/frameworkdbus/types/exportwindowinfo.cpp b/src/frameworkdbus/types/exportwindowinfo.cpp new file mode 100644 index 0000000..e3a3bd0 --- /dev/null +++ b/src/frameworkdbus/types/exportwindowinfo.cpp @@ -0,0 +1,51 @@ +#include "exportwindowinfo.h" + +#include + +ExportWindowInfo::ExportWindowInfo() + : m_xid(0) + , m_flash(false) +{ + +} + +ExportWindowInfo::ExportWindowInfo(uint32_t xid, const QString &title, bool flash) + : m_xid(xid) + , m_title(title) + , m_flash(flash) +{ + +} + +QDebug operator<<(QDebug debug, const ExportWindowInfo &info) +{ + debug << QString("ExportWindowInfo(%1, %2, %3)").arg(info.m_xid) + .arg(info.m_title) + .arg(info.m_flash); + + return debug; +} + +QDBusArgument &operator<<(QDBusArgument &arg, const ExportWindowInfo &info) +{ + arg.beginStructure(); + arg << info.m_xid << info.m_title << info.m_flash; + arg.endStructure(); + + return arg; +} + +const QDBusArgument &operator>>(const QDBusArgument &arg, ExportWindowInfo &info) +{ + arg.beginStructure(); + arg >> info.m_xid >> info.m_title >> info.m_flash; + arg.endStructure(); + + return arg; +} + +void registerExportWindowInfoMetaType() +{ + qRegisterMetaType("ExportWindowInfo"); + qDBusRegisterMetaType(); +} diff --git a/src/frameworkdbus/types/exportwindowinfo.h b/src/frameworkdbus/types/exportwindowinfo.h new file mode 100644 index 0000000..19ae7e1 --- /dev/null +++ b/src/frameworkdbus/types/exportwindowinfo.h @@ -0,0 +1,31 @@ +#ifndef EXPORTWINDOWINFO_H +#define EXPORTWINDOWINFO_H + +#include +#include + +struct ExportWindowInfo +{ +public: + ExportWindowInfo(); + ExportWindowInfo(uint32_t xid, const QString &title, bool flash); + + friend QDebug operator<<(QDebug debug, const ExportWindowInfo &rect); + friend const QDBusArgument &operator>>(const QDBusArgument &arg, ExportWindowInfo &rect); + friend QDBusArgument &operator<<(QDBusArgument &arg, const ExportWindowInfo &rect); + + uint32_t getXid() {return m_xid;} + QString getTitle() {return m_title;} + bool getFlash() {return m_flash;} + +private: + uint32_t m_xid; + QString m_title; + bool m_flash; +}; + +Q_DECLARE_METATYPE(ExportWindowInfo) + +void registerExportWindowInfoMetaType(); + +#endif // EXPORTWINDOWINFO_H diff --git a/src/frameworkdbus/types/exportwindowinfolist.cpp b/src/frameworkdbus/types/exportwindowinfolist.cpp new file mode 100644 index 0000000..04e3f72 --- /dev/null +++ b/src/frameworkdbus/types/exportwindowinfolist.cpp @@ -0,0 +1,18 @@ +#include "exportwindowinfolist.h" + +void sortExprotWindowInfoList(ExportWindowInfoList &list) +{ + qSort(list.begin(), list.end(), compareWindowXid); +} + +void registerExportWindowInfoListMetaType() +{ + qRegisterMetaType("ExportWindowInfoList"); + qDBusRegisterMetaType(); +} + +// 按xid进行排序 +bool compareWindowXid(ExportWindowInfo &info1, ExportWindowInfo &info2) +{ + return info1.getXid() < info2.getXid(); +} diff --git a/src/frameworkdbus/types/exportwindowinfolist.h b/src/frameworkdbus/types/exportwindowinfolist.h new file mode 100644 index 0000000..519f454 --- /dev/null +++ b/src/frameworkdbus/types/exportwindowinfolist.h @@ -0,0 +1,18 @@ +#ifndef EXPORTWINDOWINFOLIST_H +#define EXPORTWINDOWINFOLIST_H +#include "exportwindowinfo.h" + +#include +#include + +typedef QList ExportWindowInfoList; + +bool compareWindowXid(ExportWindowInfo &info1, ExportWindowInfo &info2); + +void sortExprotWindowInfoList(ExportWindowInfoList &list); + +Q_DECLARE_METATYPE(ExportWindowInfoList) + +void registerExportWindowInfoListMetaType(); + +#endif // EXPORTWINDOWINFOLIST_H diff --git a/src/modules/dock/dbusadaptorentry.cpp b/src/modules/dock/dbusadaptorentry.cpp index 269229f..96666c2 100644 --- a/src/modules/dock/dbusadaptorentry.cpp +++ b/src/modules/dock/dbusadaptorentry.cpp @@ -27,7 +27,11 @@ DBusAdaptorEntry::DBusAdaptorEntry(QObject *parent) // constructor setAutoRelaySignals(true); - //qDBusRegisterMetaType(); + if (QMetaType::type("ExportWindowInfo") == QMetaType::UnknownType) + registerExportWindowInfoMetaType(); + + if (QMetaType::type("ExportWindowInfoList") == QMetaType::UnknownType) + registerExportWindowInfoListMetaType(); Entry *entry = static_cast(QObject::parent()); if (entry) { @@ -38,12 +42,12 @@ DBusAdaptorEntry::DBusAdaptorEntry(QObject *parent) connect(entry, &Entry::nameChanged, this, &DBusAdaptorEntry::NameChanged); connect(entry, &Entry::desktopFileChanged, this, &DBusAdaptorEntry::DesktopFileChanged); connect(entry, &Entry::currentWindowChanged, this, &DBusAdaptorEntry::CurrentWindowChanged); + connect(entry, &Entry::windowInfosChanged, this, &DBusAdaptorEntry::WindowInfosChanged); } } DBusAdaptorEntry::~DBusAdaptorEntry() { - // destructor } uint DBusAdaptorEntry::currentWindow() const @@ -86,12 +90,11 @@ QString DBusAdaptorEntry::name() const return parent()->getName(); } -/* -QList DBusAdaptorEntry::windowInfos() +ExportWindowInfoList DBusAdaptorEntry::windowInfos() { return parent()->getExportWindowInfos(); } -*/ + Entry *DBusAdaptorEntry::parent() const { return static_cast(QObject::parent()); @@ -152,26 +155,3 @@ void DBusAdaptorEntry::RequestUndock() parent()->requestUndock(); } - -QDBusArgument &operator <<(QDBusArgument &argument, const ExportWindowInfo &info) -{ - argument.beginStructure(); - argument << info.xid << info.title << info.flash; - argument.endStructure(); - return argument; -} - -const QDBusArgument &operator >>(const QDBusArgument &argument, ExportWindowInfo &info) -{ - argument.beginStructure(); - argument >> info.xid >> info.title >> info.flash; - argument.endStructure(); - return argument; -} - -QDebug operator<<(QDebug deg, const ExportWindowInfo &info) -{ - qDebug() << "xid: " << info.xid << " title:" << info.title << " flash:" << info.flash; - - return deg; -} diff --git a/src/modules/dock/dbusadaptorentry.h b/src/modules/dock/dbusadaptorentry.h index a91adc6..e8d95be 100644 --- a/src/modules/dock/dbusadaptorentry.h +++ b/src/modules/dock/dbusadaptorentry.h @@ -23,6 +23,7 @@ #define DBUSADAPTORENTRY_H #include "entry.h" +#include "exportwindowinfolist.h" #include #include @@ -37,12 +38,6 @@ #include -Q_DECLARE_METATYPE(ExportWindowInfo) - -QDBusArgument &operator <<(QDBusArgument &argument, const ExportWindowInfo &info); -const QDBusArgument &operator >>(const QDBusArgument &argument, ExportWindowInfo &info); -QDebug operator<<(QDebug deg, const ExportWindowInfo &info); - /* * Adaptor class for interface org.deepin.dde.daemon.Dock1.Entry */ @@ -51,40 +46,41 @@ class DBusAdaptorEntry: public QDBusAbstractAdaptor Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.deepin.dde.daemon.Dock1.Entry") Q_CLASSINFO("D-Bus Introspection", "" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" - "") + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "") public: DBusAdaptorEntry(QObject *parent); @@ -115,8 +111,8 @@ public: // PROPERTIES Q_PROPERTY(QString Name READ name NOTIFY NameChanged) QString name() const; - //Q_PROPERTY(QString WindowInfos READ windowInfos) - //QList windowInfos(); + Q_PROPERTY(ExportWindowInfoList WindowInfos READ windowInfos NOTIFY WindowInfosChanged) + ExportWindowInfoList windowInfos(); Entry *parent() const; @@ -140,6 +136,7 @@ Q_SIGNALS: // SIGNALS void NameChanged(QString value); void DesktopFileChanged(QString value); void CurrentWindowChanged(uint32_t value); + void WindowInfosChanged(ExportWindowInfoList value); }; #endif diff --git a/src/modules/dock/dbushandler.cpp b/src/modules/dock/dbushandler.cpp index 5c0cbb4..dfd02a4 100644 --- a/src/modules/dock/dbushandler.cpp +++ b/src/modules/dock/dbushandler.cpp @@ -149,7 +149,7 @@ void DBusHandler::listenKWindowSignals(WindowInfoK *windowInfo) if (entry->getCurrentWindowInfo() == windowInfo) entry->updateName(); - entry->updateWindowInfos(); + entry->updateExportWindowInfos(); }); // Icon changed @@ -169,7 +169,7 @@ void DBusHandler::listenKWindowSignals(WindowInfoK *windowInfo) if (!entry) return; - entry->updateWindowInfos(); + entry->updateExportWindowInfos(); }); // Geometry changed diff --git a/src/modules/dock/dock.cpp b/src/modules/dock/dock.cpp index ea9a8fd..d992442 100644 --- a/src/modules/dock/dock.cpp +++ b/src/modules/dock/dock.cpp @@ -1008,11 +1008,12 @@ void Dock::attachOrDetachWindow(WindowInfoBase *info) } else { // attach if (info->getEntryInnerId().isEmpty()) { - // 识别窗口并创建entryInnerId + // 窗口entryInnerId为空表示未识别,需要识别窗口并创建entryInnerId qInfo() << "attach operate: window " << winId << " entryInnerId is empty, now call IdentifyWindow"; QString innerId; AppInfo *appInfo = windowIdentify->identifyWindow(info, innerId); - info->setEntryInnerId(innerId); // windowBaseInfo entryInnerId is AppInfo innerId, for binding window and appInfo + // 窗口entryInnerId即AppInfo的innerId, 用来将窗口和应用绑定关系 + info->setEntryInnerId(innerId); info->setAppInfo(appInfo); markAppLaunched(appInfo); } else { diff --git a/src/modules/dock/entry.cpp b/src/modules/dock/entry.cpp index b9e6c04..dbf9059 100644 --- a/src/modules/dock/entry.cpp +++ b/src/modules/dock/entry.cpp @@ -33,16 +33,16 @@ #define XCB XCBUtils::instance() Entry::Entry(Dock *_dock, AppInfo *_app, QString _innerId, QObject *parent) - : QObject(parent) - , dock(_dock) - , app(nullptr) - , menu(nullptr) - , isActive(false) - , isDocked(false) - , innerId(_innerId) - , current(nullptr) - , currentWindow(0) - , winIconPreferred(false) + : QObject(parent) + , dock(_dock) + , app(nullptr) + , menu(nullptr) + , isActive(false) + , isDocked(false) + , innerId(_innerId) + , current(nullptr) + , currentWindow(0) + , winIconPreferred(false) { setApp(_app); id = dock->allocEntryId(); @@ -413,26 +413,40 @@ bool Entry::hasWindow() return windowInfos.size() > 0; } -void Entry::updateWindowInfos() +/** + * @brief Entry::updateExportWindowInfos 同步更新导出窗口信息 + */ +void Entry::updateExportWindowInfos() { - QList infos; - bool changed = false; + ExportWindowInfoList infos; for (auto info : windowInfos) { XWindow xid = info->getXid(); QString title = info->getTitle(); bool flash = info->isDemandingAttention(); infos.push_back({xid, title, flash}); - if (!changed) { - for (auto info : exportWindowInfos) { - if (info.title != title || info.flash != flash) - changed = true; + } + + bool changed = false; + if (infos.size() == exportWindowInfos.size()) { + sortExprotWindowInfoList(infos); + sortExprotWindowInfoList(exportWindowInfos); + for (int i = 0; i < infos.size(); i++) { + if (infos[i].getXid() != exportWindowInfos[i].getXid() + || infos[i].getFlash() != exportWindowInfos[i].getFlash() + || infos[i].getTitle() != exportWindowInfos[i].getTitle()) { + changed = true; + break; } } + } else { + changed = true; } if (changed) { - exportWindowInfos = infos; + Q_EMIT windowInfosChanged(infos); } + + exportWindowInfos = infos; } // 分离窗口, 返回是否需要从任务栏remove @@ -456,7 +470,7 @@ bool Entry::detachWindow(WindowInfoBase *info) } } - updateWindowInfos(); + updateExportWindowInfos(); updateIcon(); updateIsActive(); updateMenu(); @@ -476,7 +490,7 @@ bool Entry::attachWindow(WindowInfoBase *info) } windowInfos[winId] = info; - updateWindowInfos(); + updateExportWindowInfos(); updateIsActive(); if (!current) { @@ -504,7 +518,7 @@ void Entry::deleteWindow(XWindow xid) WindowInfoBase *info = windowInfos[xid]; windowInfos.remove(xid); for (int i = 0; i < exportWindowInfos.size(); i++) { - if (exportWindowInfos[i].xid == xid) { + if (exportWindowInfos[i].getXid() == xid) { exportWindowInfos.removeAt(i); break; } @@ -693,7 +707,7 @@ QVector Entry::getAllowedClosedWindowIds() return ret; } -QList Entry::getExportWindowInfos() +ExportWindowInfoList Entry::getExportWindowInfos() { return exportWindowInfos; } diff --git a/src/modules/dock/entry.h b/src/modules/dock/entry.h index b4af5f4..4d81b93 100644 --- a/src/modules/dock/entry.h +++ b/src/modules/dock/entry.h @@ -25,17 +25,12 @@ #include "appinfo.h" #include "appmenu.h" #include "windowinfobase.h" +#include "exportwindowinfolist.h" #include #include #include -struct ExportWindowInfo { - XWindow xid; - QString title; - bool flash; -}; - // 单个应用类 class Dock; class Entry: public QObject @@ -76,7 +71,7 @@ public: WindowInfoBase *findNextLeader(); QString getExec(bool oneLine); bool hasWindow(); - void updateWindowInfos(); + void updateExportWindowInfos(); bool detachWindow(WindowInfoBase *info); bool attachWindow(WindowInfoBase *info); void launchApp(uint32_t timestamp); @@ -98,7 +93,7 @@ public: bool getIsActive(); QString getMenu(); QVector getAllowedClosedWindowIds(); - QList getExportWindowInfos(); + ExportWindowInfoList getExportWindowInfos(); public Q_SLOTS: QVector getAllowedCloseWindows(); @@ -111,6 +106,7 @@ Q_SIGNALS: void nameChanged(QString value); void desktopFileChanged(QString value); void currentWindowChanged(uint32_t value); + void windowInfosChanged(const ExportWindowInfoList &value); private: // 右键菜单项 @@ -140,7 +136,7 @@ private: // Dbus属性直接放到interface上 QMap windowInfos; // 该应用所有窗口 - QList exportWindowInfos; + ExportWindowInfoList exportWindowInfos; WindowInfoBase *current; // 当前窗口 XWindow currentWindow; //当前窗口Id bool winIconPreferred; diff --git a/src/modules/dock/windowidentify.cpp b/src/modules/dock/windowidentify.cpp index bc5bfc1..5237d4f 100644 --- a/src/modules/dock/windowidentify.cpp +++ b/src/modules/dock/windowidentify.cpp @@ -118,6 +118,10 @@ AppInfo *WindowIdentify::identifyWindow(WindowInfoBase *winInfo, QString &innerI AppInfo *WindowIdentify::identifyWindowX11(WindowInfoX *winInfo, QString &innerId) { AppInfo *appInfo = nullptr; + if (winInfo->getInnerId().isEmpty()) { + qInfo() << "identifyWindowX11: window innerId is empty"; + return appInfo; + } for (auto iter = identifyWindowFuns.begin(); iter != identifyWindowFuns.end(); iter++) { QString name = iter.key(); diff --git a/src/modules/dock/windowinfox.cpp b/src/modules/dock/windowinfox.cpp index 1346804..2f5bcf6 100644 --- a/src/modules/dock/windowinfox.cpp +++ b/src/modules/dock/windowinfox.cpp @@ -245,6 +245,11 @@ void WindowInfoX::updateHasXEmbedInfo() hasXEmbedInfo = XCB->hasXEmbedInfo(xid); } +/** + * @brief WindowInfoX::genInnerId 生成innerId + * @param winInfo + * @return + */ QString WindowInfoX::genInnerId(WindowInfoX *winInfo) { XWindow winId = winInfo->getXid(); diff --git a/src/modules/dock/windowpatterns.cpp b/src/modules/dock/windowpatterns.cpp index 47f8b9e..041c08f 100644 --- a/src/modules/dock/windowpatterns.cpp +++ b/src/modules/dock/windowpatterns.cpp @@ -93,9 +93,16 @@ WindowPatterns::WindowPatterns() } +/** + * @brief WindowPatterns::match 匹配窗口 + * @param winInfo + * @return + */ QString WindowPatterns::match(WindowInfoX *winInfo) { + for (auto pattern : patterns) { + } return ""; } diff --git a/src/modules/dock/windowpatterns.h b/src/modules/dock/windowpatterns.h index 52e46d0..05af3c9 100644 --- a/src/modules/dock/windowpatterns.h +++ b/src/modules/dock/windowpatterns.h @@ -47,7 +47,7 @@ class WindowPatterns struct WindowPattern { QVector> rules; // rules QString result; // ret - QVector< RuleValueParse> parseRules; + QVector parseRules; }; public: diff --git a/src/modules/dock/x11manager.cpp b/src/modules/dock/x11manager.cpp index 8ed9698..5e46421 100644 --- a/src/modules/dock/x11manager.cpp +++ b/src/modules/dock/x11manager.cpp @@ -369,7 +369,7 @@ void X11Manager::handlePropertyNotifyEvent(XWindow xid, XCBAtom atom) return; if (atom == XCB->getAtom("_NET_WM_STATE")) { - entry->updateWindowInfos(); + entry->updateExportWindowInfos(); } else if (atom == XCB->getAtom("_NET_WM_ICON")) { if (entry->getCurrentWindowInfo() == winInfo) { entry->updateIcon(); @@ -378,7 +378,7 @@ void X11Manager::handlePropertyNotifyEvent(XWindow xid, XCBAtom atom) if (entry->getCurrentWindowInfo() == winInfo) { entry->updateName(); } - entry->updateWindowInfos(); + entry->updateExportWindowInfos(); } else if (atom == XCB->getAtom("_NET_WM_ALLOWED_ACTIONS")) { entry->updateMenu(); }