mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
feat: 适配wayland
适配wayland Log: 适配wayland Influence: wayland适配 Change-Id: I61ec8f82aa2f7e92e81e3f669d6b8019bffb4e75
This commit is contained in:
parent
0d1f12dc1b
commit
f8984e9c61
@ -25,6 +25,7 @@
|
||||
#include "xcb_misc.h"
|
||||
#include "appswingeffectbuilder.h"
|
||||
#include "appspreviewprovider.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
@ -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()) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -32,7 +32,10 @@
|
||||
#include <QVariantAnimation>
|
||||
#include <QX11Info>
|
||||
#include <QDBusConnection>
|
||||
#include <QGuiApplication>
|
||||
|
||||
#include <qpa/qplatformscreen.h>
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
|
||||
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<QVariant> 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<QVariant> 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<xcb_window_t>(parent()->winId()), orientation,
|
||||
static_cast<uint>(strut + WINDOWMARGIN * ratio), // 设置窗口与屏幕边缘距离,需要乘缩放
|
||||
static_cast<uint>(strutStart), // 设置任务栏起点坐标(上下为x,左右为y)
|
||||
static_cast<uint>(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<xcb_window_t>(parent()->winId()), orientation,
|
||||
// static_cast<uint>(strut + WINDOWMARGIN * ratio), // 设置窗口与屏幕边缘距离,需要乘缩放
|
||||
// static_cast<uint>(strutStart), // 设置任务栏起点坐标(上下为x,左右为y)
|
||||
// static_cast<uint>(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)
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user