2022-04-24 14:52:13 +08:00
|
|
|
/*
|
2022-05-15 12:10:42 +08:00
|
|
|
* Copyright (C) 2021 ~ 2022 Deepin Technology Co., Ltd.
|
2022-04-24 14:52:13 +08:00
|
|
|
*
|
|
|
|
* Author: weizhixiang <weizhixiang@uniontech.com>
|
|
|
|
*
|
|
|
|
* Maintainer: weizhixiang <weizhixiang@uniontech.com>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "waylandmanager.h"
|
|
|
|
#include "dock.h"
|
|
|
|
#include "xcbutils.h"
|
|
|
|
|
|
|
|
#define XCB XCBUtils::instance()
|
|
|
|
|
|
|
|
WaylandManager::WaylandManager(Dock *_dock, QObject *parent)
|
|
|
|
: QObject(parent)
|
2022-10-27 11:52:18 +08:00
|
|
|
, m_dock(_dock)
|
|
|
|
, m_mutex(QMutex(QMutex::NonRecursive))
|
2022-04-24 14:52:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-19 13:13:55 +08:00
|
|
|
/**
|
|
|
|
* @brief WaylandManager::registerWindow 注册窗口
|
|
|
|
* @param objPath
|
|
|
|
*/
|
2022-04-24 14:52:13 +08:00
|
|
|
void WaylandManager::registerWindow(const QString &objPath)
|
|
|
|
{
|
|
|
|
qInfo() << "registerWindow: " << objPath;
|
|
|
|
if (findWindowByObjPath(objPath))
|
|
|
|
return;
|
|
|
|
|
2022-10-27 11:52:18 +08:00
|
|
|
PlasmaWindow *plasmaWindow = m_dock->createPlasmaWindow(objPath);
|
2022-04-24 14:52:13 +08:00
|
|
|
if (!plasmaWindow) {
|
|
|
|
qWarning() << "registerWindowWayland: createPlasmaWindow failed";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString appId = plasmaWindow->AppId();
|
|
|
|
QStringList list {"dde-dock", "dde-launcher", "dde-clipboard", "dde-osd", "dde-polkit-agent", "dde-simple-egl", "dmcs"};
|
2022-08-08 13:20:42 +08:00
|
|
|
if (list.indexOf(appId) >= 0)
|
2022-04-24 14:52:13 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
XWindow winId = XCB->allocId(); // XCB中未发现释放XID接口
|
|
|
|
XWindow realId = plasmaWindow->WindowId();
|
2022-08-08 13:20:42 +08:00
|
|
|
if (realId)
|
2022-04-24 14:52:13 +08:00
|
|
|
winId = realId;
|
|
|
|
|
|
|
|
WindowInfoK *winInfo = new WindowInfoK(plasmaWindow, winId);
|
2022-10-27 11:52:18 +08:00
|
|
|
m_dock->listenKWindowSignals(winInfo);
|
2022-04-24 14:52:13 +08:00
|
|
|
insertWindow(objPath, winInfo);
|
2022-10-27 11:52:18 +08:00
|
|
|
m_dock->attachOrDetachWindow(winInfo);
|
2022-08-08 13:20:42 +08:00
|
|
|
if (winId) {
|
2022-10-27 11:52:18 +08:00
|
|
|
m_windowInfoMap[winId] = winInfo;
|
2022-04-24 14:52:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 取消注册窗口
|
|
|
|
void WaylandManager::unRegisterWindow(const QString &objPath)
|
|
|
|
{
|
|
|
|
qInfo() << "unRegisterWindow: " << objPath;
|
|
|
|
WindowInfoK *winInfo = findWindowByObjPath(objPath);
|
|
|
|
if (!winInfo)
|
|
|
|
return;
|
|
|
|
|
2022-10-27 11:52:18 +08:00
|
|
|
m_dock->removePlasmaWindowHandler(winInfo->getPlasmaWindow());
|
|
|
|
m_dock->detachWindow(winInfo);
|
2022-04-24 14:52:13 +08:00
|
|
|
deleteWindow(objPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowInfoK *WaylandManager::handleActiveWindowChangedK(uint activeWin)
|
|
|
|
{
|
|
|
|
WindowInfoK *winInfo = nullptr;
|
2022-10-27 11:52:18 +08:00
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
for (auto iter = m_kWinInfos.begin(); iter != m_kWinInfos.end(); iter++) {
|
2022-04-24 14:52:13 +08:00
|
|
|
if (iter.value()->getInnerId() == activeWin) {
|
|
|
|
winInfo = iter.value();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return winInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowInfoK *WaylandManager::findWindowByXid(XWindow xid)
|
|
|
|
{
|
|
|
|
WindowInfoK *winInfo = nullptr;
|
2022-10-27 11:52:18 +08:00
|
|
|
for (auto iter = m_kWinInfos.begin(); iter != m_kWinInfos.end(); iter++) {
|
2022-04-24 14:52:13 +08:00
|
|
|
if (iter.value()->getXid() == xid) {
|
|
|
|
winInfo = iter.value();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return winInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowInfoK *WaylandManager::findWindowByObjPath(QString objPath)
|
|
|
|
{
|
2022-10-27 11:52:18 +08:00
|
|
|
if (m_kWinInfos.find(objPath) == m_kWinInfos.end())
|
2022-04-24 14:52:13 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2022-10-27 11:52:18 +08:00
|
|
|
return m_kWinInfos[objPath];
|
2022-04-24 14:52:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandManager::insertWindow(QString objPath, WindowInfoK *windowInfo)
|
|
|
|
{
|
2022-10-27 11:52:18 +08:00
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
m_kWinInfos[objPath] = windowInfo;
|
2022-04-24 14:52:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandManager::deleteWindow(QString objPath)
|
|
|
|
{
|
2022-10-27 11:52:18 +08:00
|
|
|
m_kWinInfos.remove(objPath);
|
2022-04-24 14:52:13 +08:00
|
|
|
}
|
|
|
|
|