diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bda99aac..67e9219c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ include(KDEGitCommitHooks) find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Gui Concurrent Quick WaylandClient DBus LinguistTools Sql) find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui) find_package(WaylandProtocols REQUIRED) +find_package(TreelandProtocols REQUIRED) find_package(PkgConfig REQUIRED) add_subdirectory(frame) diff --git a/frame/CMakeLists.txt b/frame/CMakeLists.txt index 7c88b390d..de231edc0 100644 --- a/frame/CMakeLists.txt +++ b/frame/CMakeLists.txt @@ -83,6 +83,7 @@ set_target_properties(dde-shell-frame PROPERTIES qt_generate_wayland_protocol_client_sources(dde-shell-frame FILES ${CMAKE_CURRENT_SOURCE_DIR}/layershell/protocol/wlr-layer-shell-unstable-v1.xml ${WaylandProtocols_DATADIR}/stable/xdg-shell/xdg-shell.xml + ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-dde-shell-v1.xml ) set_target_properties(dde-shell-frame PROPERTIES diff --git a/frame/layershell/qwaylandlayershellsurface.cpp b/frame/layershell/qwaylandlayershellsurface.cpp index 629d88c9b..fbaaae0cb 100644 --- a/frame/layershell/qwaylandlayershellsurface.cpp +++ b/frame/layershell/qwaylandlayershellsurface.cpp @@ -11,9 +11,11 @@ #include +#include #include #include #include +#include Q_LOGGING_CATEGORY(layershellsurface, "dde.shell.layershell.surface") @@ -45,7 +47,8 @@ QWaylandLayerShellSurface::QWaylandLayerShellSurface(QtWayland::zwlr_layer_shell } } - init(shell->get_layer_surface(window->waylandSurface()->object(), output, m_dlayerShellWindow->layer(), m_dlayerShellWindow->scope())); + m_surface = window->waylandSurface()->object(); + init(shell->get_layer_surface(m_surface, output, m_dlayerShellWindow->layer(), m_dlayerShellWindow->scope())); set_layer(m_dlayerShellWindow->layer()); connect(m_dlayerShellWindow, &DLayerShellWindow::layerChanged, this, [this, window](){ @@ -80,6 +83,7 @@ QWaylandLayerShellSurface::QWaylandLayerShellSurface(QtWayland::zwlr_layer_shell if (m_requestSize.isValid()) { set_size(m_requestSize.width(), m_requestSize.height()); } + m_ddeShellSurface.reset(TreeLandDDEShellManager::instance()->getDDEShellSurface(m_surface)); } QWaylandLayerShellSurface::~QWaylandLayerShellSurface() @@ -166,4 +170,47 @@ void QWaylandLayerShellSurface::attachPopup(QtWaylandClient::QWaylandShellSurfac } } +bool QWaylandLayerShellSurface::resize(QtWaylandClient::QWaylandInputDevice *inputDevice, Qt::Edges edges) +{ + if (!m_ddeShellSurface) { + m_ddeShellSurface.reset(TreeLandDDEShellManager::instance()->getDDEShellSurface(m_surface)); + } + + if (TreeLandDDEShellManager::instance()->isActive() && m_ddeShellSurface) { + m_ddeShellSurface->resize(inputDevice->wl_seat(), inputDevice->serial(), 1); + return true; + } + + return false; +} + +TreeLandDDEShellManager::TreeLandDDEShellManager() + : QWaylandClientExtensionTemplate(treeland_dde_shell_manager_v1_interface.version) +{ +} + +TreeLandDDEShellManager *TreeLandDDEShellManager::instance() +{ + static TreeLandDDEShellManager _instance; + return &_instance; +} + +DDEShellSurface *TreeLandDDEShellManager::getDDEShellSurface(struct ::wl_surface *surface) +{ + if (isActive()) + return new DDEShellSurface(this->get_shell_surface(surface)); + return nullptr; +} + +DDEShellSurface::DDEShellSurface(struct ::treeland_dde_shell_surface_v1 *object) + : QWaylandClientExtensionTemplate(treeland_dde_shell_surface_v1_interface.version) + , treeland_dde_shell_surface_v1(object) +{ +} + +DDEShellSurface::~DDEShellSurface() +{ + destroy(); +} + DS_END_NAMESPACE diff --git a/frame/layershell/qwaylandlayershellsurface_p.h b/frame/layershell/qwaylandlayershellsurface_p.h index f05c08183..bb1743884 100644 --- a/frame/layershell/qwaylandlayershellsurface_p.h +++ b/frame/layershell/qwaylandlayershellsurface_p.h @@ -11,8 +11,11 @@ #include #include -DS_BEGIN_NAMESPACE +#include "qwayland-treeland-dde-shell-v1.h" +#include +DS_BEGIN_NAMESPACE +class DDEShellSurface; class QWaylandLayerShellSurface : public QtWaylandClient::QWaylandShellSurface, public QtWayland::zwlr_layer_surface_v1 { Q_OBJECT @@ -28,6 +31,7 @@ class QWaylandLayerShellSurface : public QtWaylandClient::QWaylandShellSurface, void applyConfigure() override; void setWindowGeometry(const QRect &geometry) override; void attachPopup(QWaylandShellSurface *popup) override; + bool resize(QtWaylandClient::QWaylandInputDevice *, Qt::Edges) override; private: void zwlr_layer_surface_v1_configure(uint32_t serial, uint32_t width, uint32_t height) override; @@ -37,10 +41,33 @@ class QWaylandLayerShellSurface : public QtWaylandClient::QWaylandShellSurface, bool anchorsSizeConflict() const; void trySetAnchorsAndSize(); + struct ::wl_surface *m_surface; + QScopedPointer m_ddeShellSurface; DLayerShellWindow* m_dlayerShellWindow; QSize m_pendingSize; QSize m_requestSize; bool m_configured = false; }; +class TreeLandDDEShellManager : public QWaylandClientExtensionTemplate, public QtWayland::treeland_dde_shell_manager_v1 +{ + Q_OBJECT + +private: + explicit TreeLandDDEShellManager(); + +public: + static TreeLandDDEShellManager *instance(); + DDEShellSurface *getDDEShellSurface(struct ::wl_surface *surface); +}; + +class DDEShellSurface : public QWaylandClientExtensionTemplate, public QtWayland::treeland_dde_shell_surface_v1 +{ + Q_OBJECT + +public: + explicit DDEShellSurface(struct ::treeland_dde_shell_surface_v1 *object); + ~DDEShellSurface() override; +}; + DS_END_NAMESPACE diff --git a/panels/dock/dockpanel.cpp b/panels/dock/dockpanel.cpp index 9c6ee76a9..b8597e2e3 100644 --- a/panels/dock/dockpanel.cpp +++ b/panels/dock/dockpanel.cpp @@ -240,7 +240,7 @@ void DockPanel::setHideMode(const HideMode& mode) Q_EMIT hideStateChanged(hideState()); } -Position DockPanel::position() +Position DockPanel::position() const { return SETTINGS->position(); } @@ -330,6 +330,26 @@ void DockPanel::openDockSettings() const .call(); } +void DockPanel::startSystemResize() const +{ + Qt::Edge edge; + switch (position()) { + case Position::Top: + edge = Qt::BottomEdge; + break; + case Position::Bottom: + edge = Qt::TopEdge; + break; + case Position::Left: + edge = Qt::RightEdge; + break; + case Position::Right: + edge = Qt::LeftEdge; + break; + } + window()->startSystemResize(edge); +} + void DockPanel::launcherVisibleChanged(bool visible) { if (visible == m_launcherShown) return; diff --git a/panels/dock/dockpanel.h b/panels/dock/dockpanel.h index b0d6943de..8b5fe85a2 100644 --- a/panels/dock/dockpanel.h +++ b/panels/dock/dockpanel.h @@ -60,7 +60,7 @@ class DockPanel : public DS_NAMESPACE::DPanel, public QDBusContext HideMode hideMode(); void setHideMode(const HideMode& mode); - Position position(); + Position position() const; void setPosition(const Position& position); ItemAlignment itemAlignment(); @@ -75,6 +75,7 @@ class DockPanel : public DS_NAMESPACE::DPanel, public QDBusContext bool debugMode() const; Q_INVOKABLE void openDockSettings() const; + Q_INVOKABLE void startSystemResize() const; bool showInPrimary() const; void setShowInPrimary(bool newShowInPrimary); diff --git a/panels/dock/package/main.qml b/panels/dock/package/main.qml index a4da63b9c..8fe0fcf2c 100644 --- a/panels/dock/package/main.qml +++ b/panels/dock/package/main.qml @@ -24,17 +24,13 @@ Window { (Screen.width - dockLeftPart.implicitWidth - dockRightPart.implicitWidth) // TODO signal dockCenterPartPosChanged() - signal pressedAndDragging(bool isDragging) property int dockCenterPartCount: dockCenterPartModel.count property int dockSize: Applet.dockSize property int dockItemMaxSize: dockSize - property int itemIconSizeBase: 0 property int itemSpacing: 0 - property bool isDragging: false - property real dockItemIconSize: dockItemMaxSize * 9 / 14 // NOTE: -1 means not set its size, follow the platform size @@ -42,6 +38,16 @@ Window { height: Panel.position == Dock.Left || Panel.position == Dock.Right ? -1 : dockSize color: "transparent" flags: Qt.WindowDoesNotAcceptFocus + maximumHeight: useColumnLayout ? Screen.height : Dock.MAX_DOCK_SIZE + minimumHeight: useColumnLayout? Screen.height : Dock.MIN_DOCK_SIZE + maximumWidth: useColumnLayout ? Dock.MAX_DOCK_SIZE : Screen.width + minimumWidth: useColumnLayout ? Dock.MIN_DOCK_SIZE : Screen.width + + Binding { + target: Applet + property: "dockSize" + value: useColumnLayout ? width : height + } function blendColorAlpha(fallback) { var appearance = DS.applet("org.deepin.ds.dde-appearance") @@ -72,12 +78,6 @@ Window { } } - Binding on itemIconSizeBase { - when: !isDragging - value: dockItemMaxSize - restoreMode: Binding.RestoreNone - } - // only add blendColor effect when DWindow.enableBlurWindow is true, // avoid to updating blur area frequently.-- D.StyledBehindWindowBlur { @@ -360,10 +360,6 @@ Window { MouseArea { id: dragArea - property point oldMousePos: Qt.point(0, 0) - property int oldDockSize: 0 - property list recentDeltas: [] - property int averageCount: 5 hoverEnabled: true propagateComposedEvents: true @@ -375,59 +371,9 @@ Window { } onPressed: function(mouse) { - dock.isDragging = true - oldMousePos = mapToGlobal(mouse.x, mouse.y) - oldDockSize = dockSize - recentDeltas = [] Panel.requestClosePopup() - DS.grabMouse(Panel.rootObject, true) - } - - // this used for blocking MouseEvent sent to bottom MouseArea - onClicked: {} - - onPositionChanged: function(mouse) { - if (!dock.isDragging) return - var newPos = mapToGlobal(mouse.x, mouse.y) - var xChange = newPos.x - oldMousePos.x - var yChange = newPos.y - oldMousePos.y - - if (Panel.position === Dock.Bottom || Panel.position === Dock.Top) { - recentDeltas.push(yChange) - } else { - recentDeltas.push(xChange) - } - - if (recentDeltas.length > averageCount) { - recentDeltas.shift() - } - // Taking the average makes the data smooth without jumps - var changeAverage = recentDeltas.reduce(function(acc, val) { return acc + val; }, 0) / recentDeltas.length; - - var newDockSize = 0 - if (Panel.position == Dock.Bottom) { - newDockSize = Math.min(Math.max(oldDockSize - changeAverage, Dock.MIN_DOCK_SIZE), Dock.MAX_DOCK_SIZE) - } else if (Panel.position == Dock.Top) { - newDockSize = Math.min(Math.max(oldDockSize + changeAverage, Dock.MIN_DOCK_SIZE), Dock.MAX_DOCK_SIZE) - } else if (Panel.position == Dock.Left) { - newDockSize = Math.min(Math.max(oldDockSize + changeAverage, Dock.MIN_DOCK_SIZE), Dock.MAX_DOCK_SIZE) - } else { - newDockSize = Math.min(Math.max(oldDockSize - changeAverage, Dock.MIN_DOCK_SIZE), Dock.MAX_DOCK_SIZE) - } - - if (newDockSize !== dockSize) { - dockSize = newDockSize - } - - pressedAndDragging(true) - } - - onReleased: function(mouse) { - dock.isDragging = false - Applet.dockSize = dockSize - itemIconSizeBase = dockItemMaxSize - pressedAndDragging(false) - DS.grabMouse(Panel.rootObject, false) + Panel.startSystemResize() + return } function anchorToTop() { @@ -556,7 +502,6 @@ Window { return Panel.devicePixelRatio }) - dock.itemIconSizeBase = dock.dockItemMaxSize dock.visible = Panel.hideState !== Dock.Hide changeDragAreaAnchor() }