diff --git a/src/frameworkdbus/types/exportwindowinfo.cpp b/src/frameworkdbus/types/exportwindowinfo.cpp deleted file mode 100644 index e3a3bd0..0000000 --- a/src/frameworkdbus/types/exportwindowinfo.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#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 deleted file mode 100644 index 19ae7e1..0000000 --- a/src/frameworkdbus/types/exportwindowinfo.h +++ /dev/null @@ -1,31 +0,0 @@ -#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 deleted file mode 100644 index 04e3f72..0000000 --- a/src/frameworkdbus/types/exportwindowinfolist.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#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 deleted file mode 100644 index 519f454..0000000 --- a/src/frameworkdbus/types/exportwindowinfolist.h +++ /dev/null @@ -1,18 +0,0 @@ -#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/frameworkdbus/types/windowinfomap.cpp b/src/frameworkdbus/types/windowinfomap.cpp new file mode 100644 index 0000000..d879797 --- /dev/null +++ b/src/frameworkdbus/types/windowinfomap.cpp @@ -0,0 +1,48 @@ +#include "windowinfomap.h" + +#include + +void registerWindowInfoMapMetaType() +{ + registerWindowInfoMetaType(); + + qRegisterMetaType("WindowInfoMap"); + qDBusRegisterMetaType(); +} + +void registerWindowInfoMetaType() +{ + qRegisterMetaType("WindowInfo"); + qDBusRegisterMetaType(); +} + +QDebug operator<<(QDebug argument, const WindowInfo &info) +{ + argument << '(' << info.title << ',' << info.attention << ')'; + + return argument; +} + +QDBusArgument &operator<<(QDBusArgument &argument, const WindowInfo &info) +{ + argument.beginStructure(); + argument << info.title << info.attention; + argument.endStructure(); + + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, WindowInfo &info) +{ + argument.beginStructure(); + argument >> info.title >> info.attention; + argument.endStructure(); + + return argument; +} + +bool WindowInfo::operator==(const WindowInfo &rhs) const +{ + return attention == rhs.attention && + title == rhs.title; +} diff --git a/src/frameworkdbus/types/windowinfomap.h b/src/frameworkdbus/types/windowinfomap.h new file mode 100644 index 0000000..711c684 --- /dev/null +++ b/src/frameworkdbus/types/windowinfomap.h @@ -0,0 +1,29 @@ +#ifndef WINDOWINFOLIST_H +#define WINDOWINFOLIST_H + +#include +#include +#include + +class WindowInfo +{ +public: + friend QDebug operator<<(QDebug argument, const WindowInfo &info); + friend QDBusArgument &operator<<(QDBusArgument &argument, const WindowInfo &info); + friend const QDBusArgument &operator>>(const QDBusArgument &argument, WindowInfo &info); + + bool operator==(const WindowInfo &rhs) const; + +public: + bool attention; + QString title; +}; +Q_DECLARE_METATYPE(WindowInfo) + +typedef QMap WindowInfoMap; +Q_DECLARE_METATYPE(WindowInfoMap) + +void registerWindowInfoMetaType(); +void registerWindowInfoMapMetaType(); + +#endif // WINDOWINFOLIST_H diff --git a/src/lib/desktopinfo.cpp b/src/lib/desktopinfo.cpp index a3134d3..fd52578 100644 --- a/src/lib/desktopinfo.cpp +++ b/src/lib/desktopinfo.cpp @@ -204,6 +204,7 @@ std::vector DesktopInfo::getActions() DesktopAction action; action.name = m_keyFile.getLocaleStr(mainKey, KeyName, ""); action.exec = m_keyFile.getStr(mainKey, KeyExec); + action.section = mainKey; actions.push_back(action); } } diff --git a/src/lib/gsetting.cpp b/src/lib/gsetting.cpp index 3492fbc..96f507e 100644 --- a/src/lib/gsetting.cpp +++ b/src/lib/gsetting.cpp @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2021 ~ 2022 Deepin Technology Co., Ltd. + * + * Author: weizhixiang + * + * Maintainer: weizhixiang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "gsetting.h" #include diff --git a/src/lib/gsetting.h b/src/lib/gsetting.h index 8efe387..63f847e 100644 --- a/src/lib/gsetting.h +++ b/src/lib/gsetting.h @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2021 ~ 2022 Deepin Technology Co., Ltd. + * + * Author: weizhixiang + * + * Maintainer: weizhixiang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #ifndef GSETTING_H #define GSETTING_H diff --git a/src/lib/xcbutils.cpp b/src/lib/xcbutils.cpp index e0d49ea..0dfbe64 100644 --- a/src/lib/xcbutils.cpp +++ b/src/lib/xcbutils.cpp @@ -301,23 +301,29 @@ std::string XCBUtils::getWMIconName(XWindow xid) std::vector XCBUtils::getWMIcon(XWindow xid) { std::vector ret; - /* - xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_icon(&ewmh, xid); + xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_icon(&m_ewmh, xid); xcb_ewmh_get_wm_icon_reply_t reply; - if (xcb_ewmh_get_wm_icon_reply(&ewmh, cookie, &reply, nullptr)) { + if (xcb_ewmh_get_wm_icon_reply(&m_ewmh, cookie, &reply, nullptr)) { xcb_ewmh_wm_icon_iterator_t iter = xcb_ewmh_get_wm_icon_iterator(&reply); auto fcn = [](xcb_ewmh_wm_icon_iterator_t it) { - std::vector data; - uint32_t *dat = it.data; - int area = it.width * it.height; - for (int i = 0; i < (2 + area) * 4; i++, dat++) { // TODO check data accuracy - data.push_back(*dat); + std::vector ret; + // data数据是按行从左至右,从上至下排列 + uint32_t *data = it.data; + if (!data) { + return ret; } - return data; + + // 根据宽高获取每个位置的数据,每行前有两个位置offset + int area = it.width * it.height; + for (int i = 0; i < (2 + area) * 4; i++, data++) { + ret.push_back(*data); + } + return ret; }; ret.push_back({iter.width, iter.height, fcn(iter)}); + // 获取不同size图标数据 while (iter.rem >= 1) { xcb_ewmh_get_wm_icon_next(&iter); ret.push_back({iter.width, iter.height, fcn(iter)}); @@ -325,7 +331,7 @@ std::vector XCBUtils::getWMIcon(XWindow xid) xcb_ewmh_get_wm_icon_reply_wipe(&reply); // clear } -*/ + return ret; } diff --git a/src/lib/xcbutils.h b/src/lib/xcbutils.h index 71e2a4e..e120471 100644 --- a/src/lib/xcbutils.h +++ b/src/lib/xcbutils.h @@ -206,7 +206,7 @@ public: // 获取窗口图标 _NET_WM_ICON_NAME std::string getWMIconName(XWindow xid); - // _NET_WM_ICON + // 获取窗口图标信息 _NET_WM_ICON std::vector getWMIcon(XWindow xid); // WM_CLIENT_LEADER diff --git a/src/modules/dock/dbusadaptordock.cpp b/src/modules/dock/dbusadaptordock.cpp index 2f4eecf..c5e1999 100644 --- a/src/modules/dock/dbusadaptordock.cpp +++ b/src/modules/dock/dbusadaptordock.cpp @@ -29,10 +29,8 @@ DBusAdaptorDock::DBusAdaptorDock(QObject *parent) Dock *dock = static_cast(QObject::parent()); if (dock) { - connect(dock, &Dock::serviceRestarted, this, [&] { - Q_EMIT ServiceRestarted();}); - connect(dock, &Dock::entryAdded, this, [&](QString entryObjPath, int32_t index){ - Q_EMIT EntryAdded(QDBusObjectPath(entryObjPath), index);}); + connect(dock, &Dock::serviceRestarted, this, &DBusAdaptorDock::ServiceRestarted); + connect(dock, &Dock::entryAdded, this, &DBusAdaptorDock::EntryAdded); connect(dock, &Dock::entryRemoved, this, &DBusAdaptorDock::EntryRemoved); connect(dock, &Dock::hideStateChanged, this, &DBusAdaptorDock::HideStateChanged); connect(dock, &Dock::frontendWindowRectChanged, this, &DBusAdaptorDock::FrontendWindowRectChanged); diff --git a/src/modules/dock/dbusadaptorentry.cpp b/src/modules/dock/dbusadaptorentry.cpp index 96666c2..f33c234 100644 --- a/src/modules/dock/dbusadaptorentry.cpp +++ b/src/modules/dock/dbusadaptorentry.cpp @@ -27,11 +27,12 @@ DBusAdaptorEntry::DBusAdaptorEntry(QObject *parent) // constructor setAutoRelaySignals(true); - if (QMetaType::type("ExportWindowInfo") == QMetaType::UnknownType) - registerExportWindowInfoMetaType(); - if (QMetaType::type("ExportWindowInfoList") == QMetaType::UnknownType) - registerExportWindowInfoListMetaType(); + if (QMetaType::type("WindowInfo") == QMetaType::UnknownType) + registerWindowInfoMetaType(); + + if (QMetaType::type("WindowInfoMap") == QMetaType::UnknownType) + registerWindowInfoMapMetaType(); Entry *entry = static_cast(QObject::parent()); if (entry) { @@ -90,7 +91,7 @@ QString DBusAdaptorEntry::name() const return parent()->getName(); } -ExportWindowInfoList DBusAdaptorEntry::windowInfos() +WindowInfoMap DBusAdaptorEntry::windowInfos() { return parent()->getExportWindowInfos(); } diff --git a/src/modules/dock/dbusadaptorentry.h b/src/modules/dock/dbusadaptorentry.h index e8d95be..56ecb11 100644 --- a/src/modules/dock/dbusadaptorentry.h +++ b/src/modules/dock/dbusadaptorentry.h @@ -23,7 +23,7 @@ #define DBUSADAPTORENTRY_H #include "entry.h" -#include "exportwindowinfolist.h" +#include "windowinfomap.h" #include #include @@ -77,8 +77,8 @@ class DBusAdaptorEntry: public QDBusAbstractAdaptor " \n" " \n" " \n" - " \n" - " \n" + " \n" + " \n" " \n" "") @@ -111,8 +111,8 @@ public: // PROPERTIES Q_PROPERTY(QString Name READ name NOTIFY NameChanged) QString name() const; - Q_PROPERTY(ExportWindowInfoList WindowInfos READ windowInfos NOTIFY WindowInfosChanged) - ExportWindowInfoList windowInfos(); + Q_PROPERTY(WindowInfoMap WindowInfos READ windowInfos NOTIFY WindowInfosChanged) + WindowInfoMap windowInfos(); Entry *parent() const; @@ -136,7 +136,7 @@ Q_SIGNALS: // SIGNALS void NameChanged(QString value); void DesktopFileChanged(QString value); void CurrentWindowChanged(uint32_t value); - void WindowInfosChanged(ExportWindowInfoList value); + void WindowInfosChanged(WindowInfoMap value); }; #endif diff --git a/src/modules/dock/dock.cpp b/src/modules/dock/dock.cpp index d992442..33b7925 100644 --- a/src/modules/dock/dock.cpp +++ b/src/modules/dock/dock.cpp @@ -409,6 +409,14 @@ QList Dock::getClientList() return QList(clientList); } +/** + * @brief Dock::setClientList 设置窗口client列表 + */ +void Dock::setClientList(QList value) +{ + clientList = value; +} + /** * @brief Dock::closeWindow 关闭窗口 * @param windowId 窗口id diff --git a/src/modules/dock/dock.h b/src/modules/dock/dock.h index bb773a0..e4adf0f 100644 --- a/src/modules/dock/dock.h +++ b/src/modules/dock/dock.h @@ -128,6 +128,7 @@ public: WindowInfoBase *getActiveWindow(); void doActiveWindow(XWindow xid); QList getClientList(); + void setClientList(QList value); void closeWindow(XWindow windowId); QStringList getEntryIDs(); @@ -148,7 +149,7 @@ public: Q_SIGNALS: void serviceRestarted(); - void entryAdded(QString entryObjPath, int32_t index); + void entryAdded(QDBusObjectPath entryObjPath, int index); void entryRemoved(QString id); void hideStateChanged(int); void frontendWindowRectChanged(); diff --git a/src/modules/dock/entries.cpp b/src/modules/dock/entries.cpp index 6d7aa65..44bfa39 100644 --- a/src/modules/dock/entries.cpp +++ b/src/modules/dock/entries.cpp @@ -59,6 +59,7 @@ void Entries::insert(Entry *entry, int index) { if (index < 0 || index >= items.size()) { // append + index = items.size(); items.push_back(entry); } else { // insert @@ -70,11 +71,13 @@ void Entries::insert(Entry *entry, int index) void Entries::remove(Entry *entry) { - for (auto iter = items.begin(); iter != items.end(); iter++) { + for (auto iter = items.begin(); iter != items.end();) { if ((*iter)->getId() == entry->getId()) { - items.erase(iter); + iter = items.erase(iter); removeCb(entry); delete entry; + } else { + iter++; } } } @@ -205,7 +208,7 @@ void Entries::updateEntriesMenu() void Entries::insertCb(Entry *entry, int index) { QString objPath = entryDBusObjPathPrefix + entry->getId(); - Q_EMIT dock->entryAdded(objPath, index); + Q_EMIT dock->entryAdded(QDBusObjectPath(objPath), index); } void Entries::removeCb(Entry *entry) @@ -213,3 +216,4 @@ void Entries::removeCb(Entry *entry) Q_EMIT dock->entryRemoved(entry->getId()); entry->stopExport(); } + diff --git a/src/modules/dock/entry.cpp b/src/modules/dock/entry.cpp index dbf9059..c3b32d9 100644 --- a/src/modules/dock/entry.cpp +++ b/src/modules/dock/entry.cpp @@ -52,11 +52,11 @@ Entry::Entry(Dock *_dock, AppInfo *_app, QString _innerId, QObject *parent) Entry::~Entry() { - for (auto winInfo : windowInfos) { + for (auto winInfo : windowInfoMap) { if (winInfo) delete winInfo; } - windowInfos.clear(); + windowInfoMap.clear(); if (app) { delete app; @@ -196,7 +196,7 @@ void Entry::setIsDocked(bool value) } } -// 导出Dbus服务 +// 导出DBus服务 void Entry::startExport() { if (getId().isEmpty()) { @@ -219,7 +219,7 @@ void Entry::startExport() } } -// 停止导出Dbus服务 +// 停止导出DBus服务 void Entry::stopExport() { if (getId().isEmpty()) { @@ -291,8 +291,10 @@ void Entry::updateIsActive() { bool isActive = false; auto activeWin = dock->getActiveWindow(); - if (activeWin) - isActive = windowInfos.find(activeWin->getXid()) != windowInfos.end(); + if (activeWin) { + // 判断活跃窗口是否属于当前应用 + isActive = windowInfoMap.find(activeWin->getXid()) != windowInfoMap.end(); + } setPropIsActive(isActive); } @@ -300,7 +302,7 @@ void Entry::updateIsActive() WindowInfoBase *Entry::getWindowInfoByPid(int pid) { WindowInfoBase *ret = nullptr; - for (const auto &windowInfo : windowInfos) { + for (const auto &windowInfo : windowInfoMap) { if (windowInfo->getPid() == pid) { ret = windowInfo; break; @@ -313,8 +315,8 @@ WindowInfoBase *Entry::getWindowInfoByPid(int pid) WindowInfoBase *Entry::getWindowInfoByWinId(XWindow windowId) { WindowInfoBase *ret = nullptr; - if (windowInfos.find(windowId) != windowInfos.end()) { - ret = windowInfos[windowId]; + if (windowInfoMap.find(windowId) != windowInfoMap.end()) { + ret = windowInfoMap[windowId]; } return ret; @@ -377,7 +379,7 @@ WindowInfoBase *Entry::getCurrentWindowInfo() */ WindowInfoBase *Entry::findNextLeader() { - auto xids = windowInfos.keys(); + auto xids = windowInfoMap.keys(); qSort(xids); XWindow curWinId = current->getXid(); int index = xids.indexOf(curWinId); @@ -389,7 +391,7 @@ WindowInfoBase *Entry::findNextLeader() if (index < xids.size() - 1) nextIndex = index + 1; - return windowInfos[xids[nextIndex]]; + return windowInfoMap[xids[nextIndex]]; } QString Entry::getExec(bool oneLine) @@ -410,7 +412,7 @@ QString Entry::getExec(bool oneLine) bool Entry::hasWindow() { - return windowInfos.size() > 0; + return windowInfoMap.size() > 0; } /** @@ -418,22 +420,21 @@ bool Entry::hasWindow() */ void Entry::updateExportWindowInfos() { - ExportWindowInfoList infos; - for (auto info : windowInfos) { + WindowInfoMap infos; + for (auto info : windowInfoMap) { + WindowInfo winInfo; XWindow xid = info->getXid(); - QString title = info->getTitle(); - bool flash = info->isDemandingAttention(); - infos.push_back({xid, title, flash}); + winInfo.title = info->getTitle(); + winInfo.attention = info->isDemandingAttention(); + infos[xid] = winInfo; } 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()) { + for (auto iter = infos.begin(); iter != infos.end(); iter++) { + XWindow xid = iter.key(); + if (infos[xid].title != exportWindowInfos[xid].title || + infos[xid].attention != exportWindowInfos[xid].attention) { changed = true; break; } @@ -456,13 +457,13 @@ bool Entry::detachWindow(WindowInfoBase *info) XWindow winId = info->getXid(); deleteWindow(winId); - if (windowInfos.size() == 0) { + if (windowInfoMap.size() == 0) { if (!isDocked) // 既无窗口也非驻留应用,无需在任务栏显示 return true; setCurrentWindowInfo(nullptr); } else { - for (auto window : windowInfos) { + for (auto window : windowInfoMap) { if (window) { // 选择第一个窗口作为当前窗口 setCurrentWindowInfo(window); break; @@ -484,12 +485,12 @@ bool Entry::attachWindow(WindowInfoBase *info) qInfo() << "attatchWindow: window id:" << winId; info->setEntry(this); - if (windowInfos.find(winId) != windowInfos.end()) { + if (windowInfoMap.find(winId) != windowInfoMap.end()) { qInfo() << "attachWindow: window " << winId << " is already attached"; return false; } - windowInfos[winId] = info; + windowInfoMap[winId] = info; updateExportWindowInfos(); updateIsActive(); @@ -510,19 +511,14 @@ void Entry::launchApp(uint32_t timestamp) bool Entry::containsWindow(XWindow xid) { - return windowInfos.find(xid) != windowInfos.end(); + return windowInfoMap.find(xid) != windowInfoMap.end(); } void Entry::deleteWindow(XWindow xid) { - WindowInfoBase *info = windowInfos[xid]; - windowInfos.remove(xid); - for (int i = 0; i < exportWindowInfos.size(); i++) { - if (exportWindowInfos[i].getXid() == xid) { - exportWindowInfos.removeAt(i); - break; - } - } + WindowInfoBase *info = windowInfoMap[xid]; + windowInfoMap.remove(xid); + exportWindowInfos.remove(xid); if (info) { delete info; @@ -564,7 +560,7 @@ void Entry::newInstance(uint32_t timestamp) // 检查应用窗口分离、合并状态 void Entry::check() { - for (auto iter = windowInfos.begin(); iter != windowInfos.end(); iter++) { + for (auto iter = windowInfoMap.begin(); iter != windowInfoMap.end(); iter++) { dock->attachOrDetachWindow(iter.value()); } } @@ -573,28 +569,29 @@ void Entry::check() void Entry::forceQuit() { QMap> pidWinInfoMap; - for (auto iter = windowInfos.begin(); iter != windowInfos.end(); iter++) { + for (auto iter = windowInfoMap.begin(); iter != windowInfoMap.end(); iter++) { int pid = iter.value()->getPid(); if (pid != 0) { pidWinInfoMap[pid].push_back(iter.value()); } else { iter.value()->killClient(); } + } - for (auto iter = pidWinInfoMap.begin(); iter != pidWinInfoMap.end(); iter++) { - if (!killProcess(iter.key())) { // kill pid - for (auto &info : iter.value()) { // kill window - info->killClient(); - } + for (auto iter = pidWinInfoMap.begin(); iter != pidWinInfoMap.end(); iter++) { + if (!killProcess(iter.key())) { // kill pid + for (auto &info : iter.value()) { // kill window + info->killClient(); } } } + } void Entry::presentWindows() { QList windows; - for (auto iter = windowInfos.begin(); iter != windowInfos.end(); iter++) + for (auto iter = windowInfoMap.begin(); iter != windowInfoMap.end(); iter++) windows.push_back(iter.key()); dock->presentWindows(windows); @@ -632,7 +629,7 @@ void Entry::active(uint32_t timestamp) if (showing || winInfo->isMinimized()) { winInfo->activate(); } else { - if (windowInfos.size() == 1) { + if (windowInfoMap.size() == 1) { winInfo->minimize(); } else { WindowInfoBase *nextWin = findNextLeader(); @@ -662,7 +659,7 @@ void Entry::active(uint32_t timestamp) // 激活隐藏窗口 dock->doActiveWindow(xid); } else { - if (windowInfos.size() == 1) { + if (windowInfoMap.size() == 1) { XCB->minimizeWindow(xid); } else if (dock->getActiveWindow()->getXid() == xid) { WindowInfoBase *nextWin = findNextLeader(); @@ -698,7 +695,7 @@ QString Entry::getMenu() QVector Entry::getAllowedClosedWindowIds() { QVector ret; - for (auto iter = windowInfos.begin(); iter != windowInfos.end(); iter++) { + for (auto iter = windowInfoMap.begin(); iter != windowInfoMap.end(); iter++) { WindowInfoBase *info = iter.value(); if (info && info->allowClose()) ret.push_back(iter.key()); @@ -707,7 +704,7 @@ QVector Entry::getAllowedClosedWindowIds() return ret; } -ExportWindowInfoList Entry::getExportWindowInfos() +WindowInfoMap Entry::getExportWindowInfos() { return exportWindowInfos; } @@ -715,7 +712,7 @@ ExportWindowInfoList Entry::getExportWindowInfos() QVector Entry::getAllowedCloseWindows() { QVector ret; - for (auto iter = windowInfos.begin(); iter != windowInfos.end(); iter++) { + for (auto iter = windowInfoMap.begin(); iter != windowInfoMap.end(); iter++) { WindowInfoBase *info = iter.value(); if (info && info->allowClose()) ret.push_back(info); @@ -772,7 +769,7 @@ AppMenuItem Entry::getMenuItemCloseAll() qInfo() << "do MenuItem: Close All"; auto winInfos = getAllowedCloseWindows(); - // 从大到小排序, 方便后面关闭窗口 + // 根据创建时间从大到小排序, 方便后续关闭窗口 for (int i = 0; i < winInfos.size() - 1; i++) { for (int j = i + 1; j < winInfos.size(); j++) { if (winInfos[i]->getCreatedTime() < winInfos[j]->getCreatedTime()) { diff --git a/src/modules/dock/entry.h b/src/modules/dock/entry.h index 4d81b93..a85b535 100644 --- a/src/modules/dock/entry.h +++ b/src/modules/dock/entry.h @@ -25,7 +25,7 @@ #include "appinfo.h" #include "appmenu.h" #include "windowinfobase.h" -#include "exportwindowinfolist.h" +#include "windowinfomap.h" #include #include @@ -93,7 +93,7 @@ public: bool getIsActive(); QString getMenu(); QVector getAllowedClosedWindowIds(); - ExportWindowInfoList getExportWindowInfos(); + WindowInfoMap getExportWindowInfos(); public Q_SLOTS: QVector getAllowedCloseWindows(); @@ -106,7 +106,7 @@ Q_SIGNALS: void nameChanged(QString value); void desktopFileChanged(QString value); void currentWindowChanged(uint32_t value); - void windowInfosChanged(const ExportWindowInfoList &value); + void windowInfosChanged(const WindowInfoMap &value); private: // 右键菜单项 @@ -135,8 +135,8 @@ private: QString desktopFile; // Dbus属性直接放到interface上 - QMap windowInfos; // 该应用所有窗口 - ExportWindowInfoList exportWindowInfos; + QMap windowInfoMap; // 该应用所有窗口 + WindowInfoMap exportWindowInfos; // 该应用导出的窗口属性 WindowInfoBase *current; // 当前窗口 XWindow currentWindow; //当前窗口Id bool winIconPreferred; diff --git a/src/modules/dock/windowinfobase.h b/src/modules/dock/windowinfobase.h index 8624a85..85a8a8d 100644 --- a/src/modules/dock/windowinfobase.h +++ b/src/modules/dock/windowinfobase.h @@ -65,16 +65,16 @@ public: bool containAtom(QVector supports, XCBAtom ty) {return supports.indexOf(ty) != -1;} protected: - XWindow xid; - QString title; - QString icon; - int pid; - QString entryInnerId; - QString innerId; - Entry *entry; - AppInfo *app; - ProcessInfo *processInfo; - int64_t createdTime; + XWindow xid; // 窗口id + QString title; // 窗口标题 + QString icon; // 窗口图标 + int pid; // 窗口所属应用进程 + QString entryInnerId; // 窗口所属应用对应的innerId + QString innerId; // 窗口对应的innerId + Entry *entry; // 窗口所属应用 + AppInfo *app; // 窗口所属应用对应的desktopFile信息 + ProcessInfo *processInfo; // 窗口所属应用的进程信息 + int64_t createdTime; // 创建时间 }; #endif // WINDOWINFOBASE_H diff --git a/src/modules/dock/windowinfox.cpp b/src/modules/dock/windowinfox.cpp index dbe70ef..e606632 100644 --- a/src/modules/dock/windowinfox.cpp +++ b/src/modules/dock/windowinfox.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #define XCB XCBUtils::instance() @@ -367,9 +369,7 @@ void WindowInfoX::update() // TODO 从窗口中获取图标, 并设置best size be used in Entry QString WindowInfoX::getIconFromWindow() { - QString ret; - - return ret; + return QString(); } bool WindowInfoX::isActionMinimizeAllowed() diff --git a/src/modules/dock/x11manager.cpp b/src/modules/dock/x11manager.cpp index ca64037..95d5972 100644 --- a/src/modules/dock/x11manager.cpp +++ b/src/modules/dock/x11manager.cpp @@ -209,7 +209,9 @@ void X11Manager::handleClientListChanged() addClientList = newClientList - oldClientList; rmClientList = oldClientList - newClientList; + dock->setClientList(newClientList.toList()); + // 处理新增窗口 for (auto xid : addClientList) { WindowInfoX *info = registerWindow(xid); if (!XCB->isGoodWindow(xid)) @@ -220,9 +222,10 @@ void X11Manager::handleClientListChanged() QString wmName(XCB->getWMName(xid).c_str()); if (pid != 0 || (wmClass.className.size() > 0 && wmClass.instanceName.size() > 0) || wmName.size() > 0 || XCB->getWMCommand(xid).size() > 0) - dock->attachWindow(info); + dock->attachOrDetachWindow(info); } + // 处理需要移除的窗口 for (auto xid : rmClientList) { WindowInfoX *info = windowInfoMap[xid]; if (info) { @@ -370,7 +373,7 @@ void X11Manager::handlePropertyNotifyEvent(XWindow xid, XCBAtom atom) } if (needAttachOrDetach) - dock->attachWindow(winInfo); + dock->attachOrDetachWindow(winInfo); Entry *entry = dock->getEntryByWindowId(xid); if (!entry) diff --git a/src/modules/launcher/dbusadaptorlauncher.cpp b/src/modules/launcher/dbusadaptorlauncher.cpp index 0a974ab..2e432a1 100644 --- a/src/modules/launcher/dbusadaptorlauncher.cpp +++ b/src/modules/launcher/dbusadaptorlauncher.cpp @@ -1,9 +1,29 @@ +/* + * Copyright (C) 2021 ~ 2022 Deepin Technology Co., Ltd. + * + * Author: weizhixiang + * + * Maintainer: weizhixiang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "dbusadaptorlauncher.h" DBusAdaptorLauncher::DBusAdaptorLauncher(QObject *parent) : QDBusAbstractAdaptor(parent) { - // constructor setAutoRelaySignals(true); Launcher *launcher = static_cast(QObject::parent()); diff --git a/src/modules/launcher/dbusadaptorlauncher.h b/src/modules/launcher/dbusadaptorlauncher.h index 84bfce5..5503216 100644 --- a/src/modules/launcher/dbusadaptorlauncher.h +++ b/src/modules/launcher/dbusadaptorlauncher.h @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2021 ~ 2022 Deepin Technology Co., Ltd. + * + * Author: weizhixiang + * + * Maintainer: weizhixiang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #ifndef DBUSADAPTORLAUNCHER_H #define DBUSADAPTORLAUNCHER_H @@ -88,7 +109,7 @@ class DBusAdaptorLauncher: public QDBusAbstractAdaptor " \n" "") public: - DBusAdaptorLauncher(QObject *parent); + explicit DBusAdaptorLauncher(QObject *parent); virtual ~DBusAdaptorLauncher(); Launcher *parent() const; diff --git a/src/modules/launcher/launcher.cpp b/src/modules/launcher/launcher.cpp index 89a7c0b..e0ae884 100644 --- a/src/modules/launcher/launcher.cpp +++ b/src/modules/launcher/launcher.cpp @@ -168,7 +168,7 @@ LauncherItemInfoList Launcher::getAllItemInfos() * @brief Launcher::getAllNewInstalledApps 获取所有新安装且未打开的应用 * @return */ - QStringList Launcher::getAllNewInstalledApps() +QStringList Launcher::getAllNewInstalledApps() { QStringList ret; QMap newApps; @@ -185,7 +185,7 @@ LauncherItemInfoList Launcher::getAllItemInfos() return ret; } - /** +/** * @brief Launcher::getDisableScaling 获取应用是否禁用缩放 * @param appId * @return @@ -1193,8 +1193,9 @@ Item Launcher:: NewItemWithDesktopInfo(DesktopInfo &info) item.exec = info.getCommandLine().c_str(); item.genericName = info.getGenericName().c_str(); item.comment = enComment; - if (!info.getIcon().empty()) + if (!info.getIcon().empty()) { item.info.icon = info.getIcon().c_str(); + } xDeepinCategory = xDeepinCategory.toLower(); diff --git a/src/service/CMakeLists.txt b/src/service/CMakeLists.txt index beb782c..04f8f12 100644 --- a/src/service/CMakeLists.txt +++ b/src/service/CMakeLists.txt @@ -2,7 +2,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -find_package(Qt5 REQUIRED COMPONENTS Core DBus Concurrent) +find_package(Qt5 REQUIRED COMPONENTS Core DBus Concurrent Gui) find_package(DtkCore REQUIRED) pkg_check_modules(XCB REQUIRED IMPORTED_TARGET xcb-icccm xcb-ewmh xcb) @@ -45,6 +45,7 @@ target_link_libraries(deepin-application-manager PkgConfig::XCB PkgConfig::X11 PkgConfig::GIO + ${Qt5Gui_LIBRARIES} ) target_include_directories(deepin-application-manager PUBLIC @@ -55,6 +56,7 @@ target_include_directories(deepin-application-manager PUBLIC ../frameworkdbus ../frameworkdbus/qtdbusextended ../frameworkdbus/types + ${Qt5Gui_PRIVATE_INCLUDE_DIRS} ) install(TARGETS deepin-application-manager DESTINATION bin)