From b2acfbbc5f61553d6c2bfe520aa1275b01660ab1 Mon Sep 17 00:00:00 2001 From: ssk-wh Date: Mon, 29 Apr 2024 13:58:28 +0800 Subject: [PATCH] feat: add dock-shell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加DDockApplet类型,dock的子插件应统一继承此类,方便统一管理 增加DDockItem类型,导出qml组件,提供统一视觉的的tips,icon,... log: as title --- debian/dde-shell.install | 1 + debian/libdde-shell.install | 1 + panels/dock/CMakeLists.txt | 29 ++++- panels/dock/DockItem.qml | 63 ++++++++++ panels/dock/ddockapplet.cpp | 109 ++++++++++++++++++ panels/dock/ddockapplet.h | 56 +++++++++ panels/dock/dock-shell-example/CMakeLists.txt | 14 +++ panels/dock/dock-shell-example/item.cpp | 50 ++++++++ panels/dock/dock-shell-example/item.h | 24 ++++ .../dock/dock-shell-example/package/item.qml | 24 ++++ .../dock-shell-example/package/metadata.json | 8 ++ panels/dock/private/ddockapplet_p.h | 25 ++++ panels/dock/qmlplugin.cpp | 31 +++++ panels/dock/qmlplugin.h | 21 ++++ 14 files changed, 451 insertions(+), 5 deletions(-) create mode 100644 panels/dock/DockItem.qml create mode 100644 panels/dock/ddockapplet.cpp create mode 100644 panels/dock/ddockapplet.h create mode 100644 panels/dock/dock-shell-example/CMakeLists.txt create mode 100644 panels/dock/dock-shell-example/item.cpp create mode 100644 panels/dock/dock-shell-example/item.h create mode 100644 panels/dock/dock-shell-example/package/item.qml create mode 100644 panels/dock/dock-shell-example/package/metadata.json create mode 100644 panels/dock/private/ddockapplet_p.h create mode 100644 panels/dock/qmlplugin.cpp create mode 100644 panels/dock/qmlplugin.h diff --git a/debian/dde-shell.install b/debian/dde-shell.install index 17a122b62..448d58e9a 100644 --- a/debian/dde-shell.install +++ b/debian/dde-shell.install @@ -6,6 +6,7 @@ usr/share/dde-shell/org.deepin.ds.osd*/ usr/lib/*/dde-shell/org.deepin.ds.dock* usr/share/dde-shell/org.deepin.ds.dock*/ usr/lib/*/qt6/qml/org/deepin/ds/dock/* +usr/lib/*/qt6/qml/org/deepin/ds/dockshell/* usr/lib/*/dde-shell/org.deepin.ds.notification* usr/share/dde-shell/org.deepin.ds.notification*/ usr/lib/*/dde-shell/org.deepin.ds.dde-appearance* diff --git a/debian/libdde-shell.install b/debian/libdde-shell.install index 9495c74dc..a557d8850 100644 --- a/debian/libdde-shell.install +++ b/debian/libdde-shell.install @@ -1,3 +1,4 @@ usr/lib/*/libdde-shell.so.* +usr/lib/*/libdock-shell.so.* usr/lib/*/qt6/qml/org/deepin/ds/*.so usr/lib/*/qt6/qml/org/deepin/ds/qmldir diff --git a/panels/dock/CMakeLists.txt b/panels/dock/CMakeLists.txt index 708482b01..a9bf02807 100644 --- a/panels/dock/CMakeLists.txt +++ b/panels/dock/CMakeLists.txt @@ -78,6 +78,11 @@ endif(BUILD_WITH_X11) ds_install_package(PACKAGE org.deepin.ds.dock TARGET dockpanel) ds_handle_package_translation(PACKAGE org.deepin.ds.dock) +# # dock shell +if ((${CMAKE_BUILD_TYPE} MATCHES "Debug")) + add_subdirectory(dock-shell-example) +endif () + # sub plugins add_subdirectory(clipboarditem) add_subdirectory(workspaceitem) @@ -93,14 +98,20 @@ add_subdirectory(dockplugin) # dock qml element(include Dock.xx defines and DockCompositor) file( - GLOB dock_plugin_sources + GLOB dock_plugin_headers constants.h + ddockapplet.h +) +file( + GLOB dock_plugin_sources # dockfilterproxymodel.cpp # dockfilterproxymodel.h dockpluginmanagerextension_p.h dockpluginmanagerextension.cpp dockpluginmanagerintegration_p.h dockpluginmanagerintegration.cpp + private/ddockapplet_p.h + ddockapplet.cpp ) set_source_files_properties(DockCompositor.qml PROPERTIES @@ -117,12 +128,12 @@ set_source_files_properties(DockPalette.qml PROPERTIES qt_policy(SET QTP0001 OLD) qt_add_qml_module(dock-plugin - PLUGIN_TARGET dock-plugin + PLUGIN_TARGET dock-qml-plugin URI "org.deepin.ds.dock" VERSION "1.0" SHARED - SOURCES ${dock_plugin_sources} - QML_FILES DockCompositor.qml OverflowContainer.qml MenuHelper.qml DockPalette.qml + SOURCES ${dock_plugin_headers} ${dock_plugin_sources} + QML_FILES DockCompositor.qml OverflowContainer.qml MenuHelper.qml DockPalette.qml DockItem.qml OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/plugins/org/deepin/ds/dock/ ) @@ -137,6 +148,7 @@ target_link_libraries(dock-plugin PUBLIC Qt${QT_VERSION_MAJOR}::Qml Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::WaylandCompositor + dde-shell-frame PRIVATE PkgConfig::WaylandClient Qt${QT_VERSION_MAJOR}::WaylandCompositorPrivate @@ -147,6 +159,13 @@ target_include_directories(dock-plugin $ ) -install(DIRECTORY "${PROJECT_BINARY_DIR}/plugins/org/deepin/ds/dock/" DESTINATION "${QML_INSTALL_DIR}/org/deepin/ds/dock/") +target_include_directories(dock-plugin INTERFACE + $ + $ + $ +) + +install(FILES ${dock_plugin_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/dockshell") +install(DIRECTORY "${PROJECT_BINARY_DIR}/plugins/org/deepin/ds/dock" DESTINATION "${QML_INSTALL_DIR}/org/deepin/ds/dock/") dtk_add_config_meta_files(APPID org.deepin.ds.dock FILES dconfig/org.deepin.ds.dock.json) dtk_add_config_meta_files(APPID org.deepin.ds.dock FILES dconfig/org.deepin.ds.dock.power.json) diff --git a/panels/dock/DockItem.qml b/panels/dock/DockItem.qml new file mode 100644 index 000000000..3e312929c --- /dev/null +++ b/panels/dock/DockItem.qml @@ -0,0 +1,63 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +import QtQuick 2.15 +import QtQuick.Controls 2.15 + +import org.deepin.ds 1.0 +import org.deepin.dtk 1.0 as D +import org.deepin.dtk.private 1.0 as DP +import org.deepin.ds.dock 1.0 + +AppletItem { + id: root + property int dockOrder + property bool shouldVisible + property alias toolButtonColor: backgroundButton.color1 + property alias toolButtonBorderColor: backgroundButton.outsideBorderColor + property alias toolTip: toolTip.text + property alias icon: button.icon.name + + signal clicked + + PanelToolTip { + id: toolTip + } + D.ToolButton { + id: button + anchors.centerIn: parent + width: 30 + height: 30 + icon.width: 16 + icon.height: 16 + + display: D.IconLabel.IconOnly + onClicked: { + toolTip.close() + root.clicked() + } + + onHoveredChanged: { + if (toolTip.text === "") + return + + if (hovered) { + var point = Applet.rootObject.mapToItem(null, Applet.rootObject.width / 2, 0) + toolTip.toolTipX = point.x + toolTip.toolTipY = point.y + toolTip.open() + } else { + toolTip.close() + } + } + + background: DP.ButtonPanel { + id: backgroundButton + + button: button + color2: color1 + insideBorderColor: null + } + } +} diff --git a/panels/dock/ddockapplet.cpp b/panels/dock/ddockapplet.cpp new file mode 100644 index 000000000..55135e795 --- /dev/null +++ b/panels/dock/ddockapplet.cpp @@ -0,0 +1,109 @@ +// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "ddockapplet.h" +#include "private/ddockapplet_p.h" + +#include + +DS_BEGIN_NAMESPACE + +DCORE_USE_NAMESPACE + +Q_DECLARE_LOGGING_CATEGORY(dsLog) + +DDockAppletPrivate::DDockAppletPrivate(DDockApplet *qq) + : DAppletPrivate(qq) +{ + +} + +DDockAppletPrivate::~DDockAppletPrivate() +{ + +} + +DDockApplet::DDockApplet(QObject *parent) + : DDockApplet(*new DDockAppletPrivate(this), parent) +{ + +} + +DDockApplet::DDockApplet(DDockAppletPrivate &dd, QObject *parent) + : DApplet(dd, parent) +{ + +} + +DDockApplet::~DDockApplet() +{ + qDebug(dsLog) << "Destroyed DDockApplet:" << pluginId() << id(); +} + +/*! + A unique name that identifies the plug-in. The default implementation is `pluginId`. +*/ +QString DDockApplet::name() const +{ + return DApplet::pluginId(); +} + +/*! + A name that displays a name that matches the current locale +*/ +/** + * @brief DDockApplet::displayName + * @return + */ + +/** + * @brief DDockApplet::itemKey + * @return + */ + +/** + * @brief DDockApplet::settingKey + * @return + */ + +/*! + A dci icon for display +*/ +QString DDockApplet::icon() const +{ + D_DC(DDockApplet); + + return d->icon; +} + +void DDockApplet::setIcon(const QString &icon) +{ + D_D(DDockApplet); + + d->icon = icon; + Q_EMIT iconChanged(icon); +} + +/*! + Whether the plug-in is displayed on the panel +*/ +bool DDockApplet::visible() const +{ + D_DC(DDockApplet); + + return d->visible; +} + +void DDockApplet::setVisible(bool visible) +{ + D_D(DDockApplet); + + if (d->visible == visible) + return; + + d->visible = visible; + Q_EMIT visibleChanged(visible); +} + +DS_END_NAMESPACE diff --git a/panels/dock/ddockapplet.h b/panels/dock/ddockapplet.h new file mode 100644 index 000000000..b31e2df48 --- /dev/null +++ b/panels/dock/ddockapplet.h @@ -0,0 +1,56 @@ +// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "applet.h" +#include "dsglobal.h" + +#include +#include + +#include + +DGUI_USE_NAMESPACE +DS_BEGIN_NAMESPACE +/** + * @brief You Can Used As Dock Plugins Sub Class + */ +class DDockAppletPrivate; +class DS_SHARE DDockApplet : public DApplet +{ + Q_OBJECT + Q_PROPERTY(QString name READ name CONSTANT FINAL) + Q_PROPERTY(QString displayName READ displayName CONSTANT FINAL) + Q_PROPERTY(QString itemKey READ itemKey CONSTANT FINAL) + Q_PROPERTY(QString settingKey READ settingKey CONSTANT FINAL) + Q_PROPERTY(QString icon READ icon NOTIFY iconChanged FINAL) + Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged FINAL); + + D_DECLARE_PRIVATE(DDockApplet); + +public: + explicit DDockApplet(QObject *parent = nullptr); + virtual ~DDockApplet() override; + + virtual QString name() const; + virtual QString displayName() const = 0; + virtual QString itemKey() const = 0; + virtual QString settingKey() const = 0; + + QString icon() const; + void setIcon(const QString &icon); + + bool visible() const; + void setVisible(bool visible); + +Q_SIGNALS: + void iconChanged(const QString &); + void visibleChanged(bool); + +protected: + explicit DDockApplet(DDockAppletPrivate &dd, QObject *parent = nullptr); +}; + +DS_END_NAMESPACE diff --git a/panels/dock/dock-shell-example/CMakeLists.txt b/panels/dock/dock-shell-example/CMakeLists.txt new file mode 100644 index 000000000..8848cd1a8 --- /dev/null +++ b/panels/dock/dock-shell-example/CMakeLists.txt @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +# +# SPDX-License-Identifier: GPL-3.0-or-later + +add_library(dock-shell-example SHARED + item.cpp + item.h +) + +target_link_libraries(dock-shell-example PRIVATE + dock-plugin +) + +ds_install_package(PACKAGE org.deepin.ds.dock.dock-shell-example TARGET dock-shell-example) diff --git a/panels/dock/dock-shell-example/item.cpp b/panels/dock/dock-shell-example/item.cpp new file mode 100644 index 000000000..98fe163e7 --- /dev/null +++ b/panels/dock/dock-shell-example/item.cpp @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "item.h" +#include "pluginfactory.h" + +#include +#include +#include + +#include +#include + +DGUI_USE_NAMESPACE + +namespace dock { + +Item::Item(QObject *parent) + : DDockApplet(parent) +{ + // for debug + setVisible(true); +} + +void Item::activate() +{ + qDebug() << "item clicked"; +} + +QString Item::displayName() const +{ + return "dock-shell-example"; +} + +QString Item::itemKey() const +{ + return "dock-shell-example"; +} + +QString Item::settingKey() const +{ + return "dock-shell-example"; +} + +D_APPLET_CLASS(Item) +} + + +#include "item.moc" diff --git a/panels/dock/dock-shell-example/item.h b/panels/dock/dock-shell-example/item.h new file mode 100644 index 000000000..aad33bfff --- /dev/null +++ b/panels/dock/dock-shell-example/item.h @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "ddockapplet.h" +#include "dsglobal.h" + +namespace dock { + +class Item : public DS_NAMESPACE::DDockApplet +{ + Q_OBJECT +public: + explicit Item(QObject *parent = nullptr); + + QString displayName() const override; + QString itemKey() const override; + QString settingKey() const override; + + Q_INVOKABLE void activate(); +}; +} diff --git a/panels/dock/dock-shell-example/package/item.qml b/panels/dock/dock-shell-example/package/item.qml new file mode 100644 index 000000000..34da542d8 --- /dev/null +++ b/panels/dock/dock-shell-example/package/item.qml @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +import org.deepin.ds 1.0 +import org.deepin.ds.dock 1.0 +// import org.deepin.ds.dockshell 1.0 + +DockItem { + dockOrder: 1 + shouldVisible: Applet.visible + toolButtonColor: DockPalette.toolButtonColor + toolButtonBorderColor: DockPalette.toolButtonBorderColor + toolTip: "I am tips" + icon: Applet.icon === "" ? "x-application-desktop" : Applet.icon + + property int dockSize: Panel.rootObject.dockSize + implicitWidth: Panel.rootObject.useColumnLayout ? dockSize : 30 + implicitHeight: Panel.rootObject.useColumnLayout ? 30 : dockSize + + onClicked: { + DDockApplet.activate() + } +} diff --git a/panels/dock/dock-shell-example/package/metadata.json b/panels/dock/dock-shell-example/package/metadata.json new file mode 100644 index 000000000..4cae671ea --- /dev/null +++ b/panels/dock/dock-shell-example/package/metadata.json @@ -0,0 +1,8 @@ +{ + "Plugin": { + "Version": "1.0", + "Id": "org.deepin.ds.dock.dock-shell-example", + "Url": "item.qml", + "Parent": "org.deepin.ds.dock" + } +} diff --git a/panels/dock/private/ddockapplet_p.h b/panels/dock/private/ddockapplet_p.h new file mode 100644 index 000000000..303a85829 --- /dev/null +++ b/panels/dock/private/ddockapplet_p.h @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "private/applet_p.h" +#include "ddockapplet.h" + +#include +#include + +DS_BEGIN_NAMESPACE +class DDockAppletPrivate : public DAppletPrivate +{ +public: + explicit DDockAppletPrivate(DDockApplet *qq); + ~DDockAppletPrivate() override; + + bool visible = false; + QString icon; + D_DECLARE_PUBLIC(DDockApplet); +}; + +DS_END_NAMESPACE diff --git a/panels/dock/qmlplugin.cpp b/panels/dock/qmlplugin.cpp new file mode 100644 index 000000000..4a0d0bae6 --- /dev/null +++ b/panels/dock/qmlplugin.cpp @@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "qmlplugin.h" +#include "ddockapplet.h" +#include "ddockappletitem.h" +#include "layershell/dlayershellwindow.h" + +#include + +QML_DECLARE_TYPEINFO(DS_NAMESPACE::DLayerShellWindow, QML_HAS_ATTACHED_PROPERTIES) + +DS_BEGIN_NAMESPACE + +void QmlpluginPlugin::registerTypes(const char *uri) +{ + // @uri org.deepin.ds.dockshell + qmlRegisterModule(uri, 1, 0); + + qmlRegisterAnonymousType(uri, 1); + qmlRegisterType(uri, 1, 0, "DDockAppletItem"); + qmlRegisterUncreatableType(uri, 1, 0, "DDockApplet", "DDockApplet Attached"); +} + +void QmlpluginPlugin::initializeEngine(QQmlEngine *engine, const char *uri) +{ + QQmlExtensionPlugin::initializeEngine(engine, uri); +} + +DS_END_NAMESPACE diff --git a/panels/dock/qmlplugin.h b/panels/dock/qmlplugin.h new file mode 100644 index 000000000..4de609b15 --- /dev/null +++ b/panels/dock/qmlplugin.h @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "dsglobal.h" + +#include + +DS_BEGIN_NAMESPACE +class QmlpluginPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + // Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + void registerTypes(const char *uri) override; + void initializeEngine(QQmlEngine *engine, const char *uri) override; +}; +DS_END_NAMESPACE