From f8984e9c61f249be6b216c3303743aba4406e911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E6=9C=8B=E7=A8=8B?= Date: Fri, 5 Nov 2021 21:45:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=82=E9=85=8Dwayland?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 适配wayland Log: 适配wayland Influence: wayland适配 Change-Id: I61ec8f82aa2f7e92e81e3f669d6b8019bffb4e75 --- frame/item/appitem.cpp | 5 + frame/item/components/previewcontainer.cpp | 2 + frame/main.cpp | 6 + frame/util/abstractpluginscontroller.cpp | 2 +- frame/util/dockpopupwindow.cpp | 2 + frame/util/multiscreenworker.cpp | 184 +++++++++++++-------- frame/window/mainpanelcontrol.cpp | 2 + frame/window/mainwindow.h | 3 + 8 files changed, 138 insertions(+), 68 deletions(-) diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index 1e1643687..d294c6861 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -25,6 +25,7 @@ #include "xcb_misc.h" #include "appswingeffectbuilder.h" #include "appspreviewprovider.h" +#include "utils.h" #include #include @@ -142,6 +143,10 @@ bool AppItem::isValid() const // window behaviors like minimization. void AppItem::updateWindowIconGeometries() { + // wayland没做处理 + if (Utils::IS_WAYLAND_DISPLAY) + return; + const QRect r(mapToGlobal(QPoint(0, 0)), mapToGlobal(QPoint(width(), height()))); if (!QX11Info::connection()) { diff --git a/frame/item/components/previewcontainer.cpp b/frame/item/components/previewcontainer.cpp index 2b835b56d..d5047bad1 100644 --- a/frame/item/components/previewcontainer.cpp +++ b/frame/item/components/previewcontainer.cpp @@ -224,6 +224,8 @@ void PreviewContainer::updatePreviewCursor() int cursorSize = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-size", 24).toInt(); if (theme != lastCursorTheme || cursorSize != lastCursorSize) { QCursor *cursor = ImageUtil::loadQCursorFromX11Cursor(theme.toStdString().c_str(), "left_ptr", cursorSize); + if (!cursor) + return; lastCursorTheme = theme; lastCursorSize = cursorSize; setCursor(*cursor); diff --git a/frame/main.cpp b/frame/main.cpp index 47c32cb8e..bdc1665f1 100644 --- a/frame/main.cpp +++ b/frame/main.cpp @@ -221,6 +221,12 @@ int main(int argc, char *argv[]) // 注册任务栏的DBus服务 MainWindow mw; DBusDockAdaptors adaptor(&mw); + + if(Utils::IS_WAYLAND_DISPLAY) { + mw.setAttribute(Qt::WA_NativeWindow); + mw.windowHandle()->setProperty("_d_dwayland_window-type", "dock"); + } + QDBusConnection::sessionBus().registerService("com.deepin.dde.Dock"); QDBusConnection::sessionBus().registerObject("/com/deepin/dde/Dock", "com.deepin.dde.Dock", &mw); diff --git a/frame/util/abstractpluginscontroller.cpp b/frame/util/abstractpluginscontroller.cpp index ac434dbdd..ac0cec3ab 100644 --- a/frame/util/abstractpluginscontroller.cpp +++ b/frame/util/abstractpluginscontroller.cpp @@ -233,7 +233,7 @@ void AbstractPluginsController::loadPlugin(const QString &pluginFile) } if (interface->pluginName() == "multitasking") { - if (qEnvironmentVariable("XDG_SESSION_TYPE").contains("wayland") or Dtk::Core::DSysInfo::deepinType() == Dtk::Core::DSysInfo::DeepinServer) { + if (Utils::IS_WAYLAND_DISPLAY or Dtk::Core::DSysInfo::deepinType() == Dtk::Core::DSysInfo::DeepinServer) { for (auto &pair : m_pluginLoadMap.keys()) { if (pair.first == pluginFile) { m_pluginLoadMap.remove(pair); diff --git a/frame/util/dockpopupwindow.cpp b/frame/util/dockpopupwindow.cpp index 3cd5e63bb..5bef46025 100644 --- a/frame/util/dockpopupwindow.cpp +++ b/frame/util/dockpopupwindow.cpp @@ -138,6 +138,8 @@ void DockPopupWindow::updatePopupWindowCursor() int cursorSize = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-size", 24).toInt(); if (theme != lastCursorTheme || cursorSize != lastCursorSize) { QCursor *cursor = ImageUtil::loadQCursorFromX11Cursor(theme.toStdString().c_str(), "left_ptr", cursorSize); + if (!cursor) + return; lastCursorTheme = theme; lastCursorSize = cursorSize; setCursor(*cursor); diff --git a/frame/util/multiscreenworker.cpp b/frame/util/multiscreenworker.cpp index 5172eed9a..87ffa5ca6 100644 --- a/frame/util/multiscreenworker.cpp +++ b/frame/util/multiscreenworker.cpp @@ -32,7 +32,10 @@ #include #include #include +#include + #include +#include const QString MonitorsSwitchTime = "monitorsSwitchTime"; const QString OnlyShowPrimary = "onlyShowPrimary"; @@ -320,16 +323,16 @@ void MultiScreenWorker::updateParentGeometry(const QVariant &value, const Positi case Position::Top: { parent()->panel()->move(0, rect.height() - panelSize); } - break; + break; case Position::Left: { parent()->panel()->move(rect.width() - panelSize, 0); } - break; + break; case Position::Bottom: case Position::Right: { parent()->panel()->move(0, 0); } - break; + break; } } @@ -516,28 +519,28 @@ void MultiScreenWorker::onRequestUpdateRegionMonitor() monitorRect.x2 = screenRect.x() + screenRect.width(); monitorRect.y2 = screenRect.y() + monitorHeight; } - break; + break; case Bottom: { monitorRect.x1 = screenRect.x(); monitorRect.y1 = screenRect.y() + screenRect.height() - monitorHeight; monitorRect.x2 = screenRect.x() + screenRect.width(); monitorRect.y2 = screenRect.y() + screenRect.height(); } - break; + break; case Left: { monitorRect.x1 = screenRect.x(); monitorRect.y1 = screenRect.y(); monitorRect.x2 = screenRect.x() + monitorHeight; monitorRect.y2 = screenRect.y() + screenRect.height(); } - break; + break; case Right: { monitorRect.x1 = screenRect.x() + screenRect.width() - monitorHeight; monitorRect.y1 = screenRect.y(); monitorRect.x2 = screenRect.x() + screenRect.width(); monitorRect.y2 = screenRect.y() + screenRect.height(); } - break; + break; } if (!m_monitorRectList.contains(monitorRect)) { @@ -565,28 +568,28 @@ void MultiScreenWorker::onRequestUpdateRegionMonitor() monitorRect.x2 = screenRect.x() + screenRect.width(); monitorRect.y2 = screenRect.y() + screenRect.height(); } - break; + break; case Bottom: { monitorRect.x1 = screenRect.x(); monitorRect.y1 = screenRect.y(); monitorRect.x2 = screenRect.x() + screenRect.width(); monitorRect.y2 = screenRect.y() + screenRect.height() - realDockSize; } - break; + break; case Left: { monitorRect.x1 = screenRect.x() + realDockSize; monitorRect.y1 = screenRect.y(); monitorRect.x2 = screenRect.x() + screenRect.width(); monitorRect.y2 = screenRect.y() + screenRect.height(); } - break; + break; case Right: { monitorRect.x1 = screenRect.x(); monitorRect.y1 = screenRect.y(); monitorRect.x2 = screenRect.x() + screenRect.width() - realDockSize; monitorRect.y2 = screenRect.y() + screenRect.height(); } - break; + break; } if (!m_extralRectList.contains(monitorRect)) { @@ -618,28 +621,28 @@ void MultiScreenWorker::onRequestUpdateRegionMonitor() monitorRect.x2 = screenRect.x() + screenRect.width(); monitorRect.y2 = screenRect.y() + monitHeight; } - break; + break; case Bottom: { monitorRect.x1 = screenRect.x(); monitorRect.y1 = screenRect.y() + screenRect.height() - monitHeight; monitorRect.x2 = screenRect.x() + screenRect.width(); monitorRect.y2 = screenRect.y() + screenRect.height(); } - break; + break; case Left: { monitorRect.x1 = screenRect.x(); monitorRect.y1 = screenRect.y(); monitorRect.x2 = screenRect.x() + monitHeight; monitorRect.y2 = screenRect.y() + screenRect.height(); } - break; + break; case Right: { monitorRect.x1 = screenRect.x() + screenRect.width() - monitHeight; monitorRect.y1 = screenRect.y(); monitorRect.x2 = screenRect.x() + screenRect.width(); monitorRect.y2 = screenRect.y() + screenRect.height(); } - break; + break; } @@ -714,13 +717,25 @@ void MultiScreenWorker::onRequestNotifyWindowManager() if ((!DIS_INS->isCopyMode() && m_ds.current() != m_ds.primary()) || m_hideMode != HideMode::KeepShowing) { lastRect = QRect(); - const auto display = QX11Info::display(); - if (!display) { - qWarning() << "QX11Info::display() is " << display; - return; + if (Utils::IS_WAYLAND_DISPLAY) { + QList varList; + varList.append(0);//dock位置 + varList.append(0);//dock高度/宽度 + varList.append(0);//start值 + varList.append(0);//end值 + if (parent()->windowHandle()->handle()) { + QGuiApplication::platformNativeInterface()->setWindowProperty(parent()->windowHandle()->handle(),"_d_dwayland_dockstrut", varList); + } + } else { + const auto display = QX11Info::display(); + if (!display) { + qWarning() << "QX11Info::display() is " << display; + return; + } + + XcbMisc::instance()->clear_strut_partial(xcb_window_t(parent()->winId())); } - //XcbMisc::instance()->clear_strut_partial(xcb_window_t(parent()->winId())); return; } @@ -737,52 +752,87 @@ void MultiScreenWorker::onRequestNotifyWindowManager() qDebug() << "dock real geometry:" << dockGeometry; qDebug() << "screen width:" << DIS_INS->screenRawWidth() << ", height:" << DIS_INS->screenRawHeight(); - const qreal ratio = qApp->devicePixelRatio(); + const qreal &ratio = qApp->devicePixelRatio(); + if (Utils::IS_WAYLAND_DISPLAY) { + // TODO 下面可能是问题的代码 + // TODO 未计算时尚模式的边距 + QList varList = {0, 0, 0, 0}; + switch (m_position) { + case Position::Top: + varList[0] = 1; + varList[1] = dockGeometry.height() * ratio; + varList[2] = dockGeometry.x() * ratio; + varList[3] = (dockGeometry.x() + dockGeometry.width()) * ratio; + break; + case Position::Bottom: + varList[0] = 3; + varList[1] = dockGeometry.height() * ratio; + varList[2] = dockGeometry.x() * ratio; + varList[3] = (dockGeometry.x() + dockGeometry.width()) * ratio; + break; + case Position::Left: + varList[0] = 0; + varList[1] = dockGeometry.width() * ratio; + varList[2] = dockGeometry.x() * ratio; + varList[3] = dockGeometry.height() * ratio; + break; + case Position::Right: + varList[0] = 2; + varList[1] = dockGeometry.width() * ratio; + varList[2] = dockGeometry.x() * ratio; + varList[3] = dockGeometry.height() * ratio; + break; + } - XcbMisc::Orientation orientation = XcbMisc::OrientationTop; - double strut = 0; - double strutStart = 0; - double strutEnd = 0; + if (parent()->windowHandle()->handle()) { + QGuiApplication::platformNativeInterface()->setWindowProperty(parent()->windowHandle()->handle(),"_d_dwayland_dockstrut", varList); + } + } else { + XcbMisc::Orientation orientation = XcbMisc::OrientationTop; + double strut = 0; + double strutStart = 0; + double strutEnd = 0; - switch (m_position) { - case Position::Top: - orientation = XcbMisc::OrientationTop; - strut = dockGeometry.y() + dockGeometry.height(); - strutStart = dockGeometry.x(); - strutEnd = qMin(dockGeometry.x() + dockGeometry.width(), dockGeometry.right()); - break; - case Position::Bottom: - orientation = XcbMisc::OrientationBottom; - strut = DIS_INS->screenRawHeight() - dockGeometry.y(); - strutStart = dockGeometry.x(); - strutEnd = qMin(dockGeometry.x() + dockGeometry.width(), dockGeometry.right()); - break; - case Position::Left: - orientation = XcbMisc::OrientationLeft; - strut = dockGeometry.x() + dockGeometry.width(); - strutStart = dockGeometry.y(); - strutEnd = qMin(dockGeometry.y() + dockGeometry.height(), dockGeometry.bottom()); - break; - case Position::Right: - orientation = XcbMisc::OrientationRight; - strut = DIS_INS->screenRawWidth() - dockGeometry.x(); - strutStart = dockGeometry.y(); - strutEnd = qMin(dockGeometry.y() + dockGeometry.height(), dockGeometry.bottom()); - break; + switch (m_position) { + case Position::Top: + orientation = XcbMisc::OrientationTop; + strut = dockGeometry.y() + dockGeometry.height(); + strutStart = dockGeometry.x(); + strutEnd = qMin(dockGeometry.x() + dockGeometry.width(), dockGeometry.right()); + break; + case Position::Bottom: + orientation = XcbMisc::OrientationBottom; + strut = DIS_INS->screenRawHeight() - dockGeometry.y(); + strutStart = dockGeometry.x(); + strutEnd = qMin(dockGeometry.x() + dockGeometry.width(), dockGeometry.right()); + break; + case Position::Left: + orientation = XcbMisc::OrientationLeft; + strut = dockGeometry.x() + dockGeometry.width(); + strutStart = dockGeometry.y(); + strutEnd = qMin(dockGeometry.y() + dockGeometry.height(), dockGeometry.bottom()); + break; + case Position::Right: + orientation = XcbMisc::OrientationRight; + strut = DIS_INS->screenRawWidth() - dockGeometry.x(); + strutStart = dockGeometry.y(); + strutEnd = qMin(dockGeometry.y() + dockGeometry.height(), dockGeometry.bottom()); + break; + } + + qDebug() << "set reserved area to xcb:" << strut << strutStart << strutEnd; + + const auto display = QX11Info::display(); + if (!display) { + qWarning() << "QX11Info::display() is " << display; + return; + } + + XcbMisc::instance()->set_strut_partial(static_cast(parent()->winId()), orientation, + static_cast(strut + WINDOWMARGIN * ratio), // 设置窗口与屏幕边缘距离,需要乘缩放 + static_cast(strutStart), // 设置任务栏起点坐标(上下为x,左右为y) + static_cast(strutEnd)); // 设置任务栏终点坐标(上下为x,左右为y) } - - qDebug() << "set reserved area to xcb:" << strut << strutStart << strutEnd; - - const auto display = QX11Info::display(); - if (!display) { - qWarning() << "QX11Info::display() is " << display; - return; - } - - // XcbMisc::instance()->set_strut_partial(static_cast(parent()->winId()), orientation, - // static_cast(strut + WINDOWMARGIN * ratio), // 设置窗口与屏幕边缘距离,需要乘缩放 - // static_cast(strutStart), // 设置任务栏起点坐标(上下为x,左右为y) - // static_cast(strutEnd)); // 设置任务栏终点坐标(上下为x,左右为y) } void MultiScreenWorker::onRequestUpdatePosition(const Position &fromPos, const Position &toPos) @@ -1181,7 +1231,7 @@ void MultiScreenWorker::changeDockPosition(QString fromScreen, QString toScreen, // 隐藏后需要通知界面更新布局方向 emit requestUpdateLayout(); - }); + }); connect(group, &QVariantAnimation::finished, this, [ = ] { setStates(ChangePositionAnimationStart, false); @@ -1519,9 +1569,9 @@ const QPoint MultiScreenWorker::rawXPosition(const QPoint &scaledPos) QScreen const *screen = Utils::screenAtByScaled(scaledPos); return screen ? screen->geometry().topLeft() + - (scaledPos - screen->geometry().topLeft()) * - screen->devicePixelRatio() - : scaledPos; + (scaledPos - screen->geometry().topLeft()) * + screen->devicePixelRatio() + : scaledPos; } void MultiScreenWorker::onTouchPress(int type, int x, int y, const QString &key) diff --git a/frame/window/mainpanelcontrol.cpp b/frame/window/mainpanelcontrol.cpp index 762d10e7d..5f89d8005 100755 --- a/frame/window/mainpanelcontrol.cpp +++ b/frame/window/mainpanelcontrol.cpp @@ -1313,6 +1313,8 @@ void MainPanelControl::updatePanelCursor() int cursorSize = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-size", 24).toInt(); if (theme != lastCursorTheme || cursorSize != lastCursorSize) { QCursor *cursor = ImageUtil::loadQCursorFromX11Cursor(theme.toStdString().c_str(), "left_ptr", cursorSize); + if (!cursor) + return; lastCursorTheme = theme; lastCursorSize = cursorSize; setCursor(*cursor); diff --git a/frame/window/mainwindow.h b/frame/window/mainwindow.h index 92e1de972..44a177c28 100644 --- a/frame/window/mainwindow.h +++ b/frame/window/mainwindow.h @@ -143,6 +143,9 @@ private: lastCursorSize = cursorSize; const char* cursorName = (position == Bottom || position == Top) ? "v_double_arrow" : "h_double_arrow"; QCursor *newCursor = ImageUtil::loadQCursorFromX11Cursor(theme.toStdString().c_str(), cursorName, cursorSize); + if (!newCursor) + return; + setCursor(*newCursor); if (lastCursor) delete lastCursor;