From db38043f8504f48afceae567e3ac17b5dbef82ee Mon Sep 17 00:00:00 2001 From: YeShanShan Date: Thu, 19 Oct 2023 20:02:45 +0800 Subject: [PATCH] feat: add dde-shell-wraper dde-shell loads org.deepin.ds.launchpad. e.g: ``` export DDE_SHELL_PACKAGE_PATH=/src-path/build/packages export DDE_SHELL_PLUGIN_PATH=/src-path/build/plugins dde-shell -p org.deepin.ds.launchpad ``` Issue: https://github.com/linuxdeepin/developer-center/issues/5810 --- .reuse/dep5 | 4 ++ CMakeLists.txt | 2 + dde-shell-wrapper/main.cpp | 79 +++++++++++++++++++++++++ dde-shell-wrapper/package/main.qml | 14 +++++ dde-shell-wrapper/package/metadata.json | 9 +++ dde-shell-wrapper/src.cmake | 51 ++++++++++++++++ debian/control | 1 + qml/Main.qml | 21 +++---- 8 files changed, 169 insertions(+), 12 deletions(-) create mode 100644 dde-shell-wrapper/main.cpp create mode 100644 dde-shell-wrapper/package/main.qml create mode 100644 dde-shell-wrapper/package/metadata.json create mode 100644 dde-shell-wrapper/src.cmake diff --git a/.reuse/dep5 b/.reuse/dep5 index 0947d894..8c1668b9 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -43,3 +43,7 @@ Files: *.deepin.dde.*.xml */org.desktopspec.*.xml Copyright: UnionTech Software Technology Co., Ltd. License: GPL-3.0-or-later +# package metadata +Files: */metadata.json +Copyright: None +License: CC0-1.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cae8dd6..cae6a682 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -167,3 +167,5 @@ install( FILES dist/org.deepin.dde.launchpad.appdata.xml DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo" ) + +include(dde-shell-wrapper/src.cmake) diff --git a/dde-shell-wrapper/main.cpp b/dde-shell-wrapper/main.cpp new file mode 100644 index 00000000..c6a41c48 --- /dev/null +++ b/dde-shell-wrapper/main.cpp @@ -0,0 +1,79 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "categorizedsortproxymodel.h" +#include "launchercontroller.h" +#include "debughelper.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "panel.h" +#include "qmlengine.h" +#include "pluginfactory.h" +DS_USE_NAMESPACE + +DCORE_USE_NAMESPACE +DGUI_USE_NAMESPACE + +// we should wait for dtkgui to have a "proper" loadTranslation() to use. +QStringList translationDir() { + QList translateDirs; + QString appName{"dde-launchpad"}; + //("/home/user/.local/share", "/usr/local/share", "/usr/share") + const QStringList dataDirs(DStandardPaths::standardLocations(QStandardPaths::GenericDataLocation)); + for (const auto &path : dataDirs) { + DPathBuf DPathBuf(path); + translateDirs << (DPathBuf / appName / "translations").toString(); + } + return translateDirs; +} + +class LanchpadPanel : public DPanel +{ + Q_OBJECT +public: + LanchpadPanel(QObject *parent) + : DPanel(parent) + { + } + virtual bool load() override + { + DGuiApplicationHelper::loadTranslator(QStringLiteral("dde-launchpad"), translationDir(), { QLocale::system() }); + + QDBusConnection connection = QDBusConnection::sessionBus(); + if (!connection.registerService(QStringLiteral("org.deepin.dde.Launcher1")) || + !connection.registerObject(QStringLiteral("/org/deepin/dde/Launcher1"), &LauncherController::instance())) { + qWarning() << "register dbus service failed"; + return false; + } + + CategorizedSortProxyModel::instance().setCategoryType(CategorizedSortProxyModel::Alphabetary); + + auto &engine = *DQmlEngine().engine(); + + engine.addImageProvider(QLatin1String("app-icon"), new LauncherAppIconProvider); + engine.addImageProvider(QLatin1String("folder-icon"), new LauncherFolderIconProvider); + engine.addImageProvider(QLatin1String("blurhash"), new BlurhashImageProvider); + + return DPanel::load(); + } + virtual bool init() override + { + return DPanel::init(); + } +}; + +D_APPLET_CLASS(LanchpadPanel) + +#include "main.moc" diff --git a/dde-shell-wrapper/package/main.qml b/dde-shell-wrapper/package/main.qml new file mode 100644 index 00000000..6070ee3b --- /dev/null +++ b/dde-shell-wrapper/package/main.qml @@ -0,0 +1,14 @@ +// 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.launchpad 1.0 + +ContainmentItem { + id: root + property point windowedPos: Qt.point(0, 0) + Main { + windowedPos: root.windowedPos + } +} diff --git a/dde-shell-wrapper/package/metadata.json b/dde-shell-wrapper/package/metadata.json new file mode 100644 index 00000000..a3e2e535 --- /dev/null +++ b/dde-shell-wrapper/package/metadata.json @@ -0,0 +1,9 @@ +{ + "Plugin": { + "Version": "1.0", + "Id": "org.deepin.ds.launchpad", + "Url": "main.qml", + "ContainmentType": "Panel", + "Category": "DDE" + } +} diff --git a/dde-shell-wrapper/src.cmake b/dde-shell-wrapper/src.cmake new file mode 100644 index 00000000..df1c1a5b --- /dev/null +++ b/dde-shell-wrapper/src.cmake @@ -0,0 +1,51 @@ +# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +# +# SPDX-License-Identifier: CC0-1.0 + +find_package(DDEShell) +if (DDEShell_FOUND) + + qt_add_qml_module(ds-launchpad-wrapper + URI org.deepin.launchpad + VERSION 1.0 + RESOURCES qml.qrc + RESOURCE_PREFIX + /qt/qml + QML_FILES + ${QML_FILES} + SOURCES ${CMAKE_CURRENT_LIST_DIR}/main.cpp + ${SOURCE_FILES} + ${DBUS_ADAPTER_FILES} + ${RESOURCES} + ${TRANSLATED_FILES} + ) + + qt_add_translations(ds-launchpad-wrapper + TS_FILES ${TRANSLATION_FILES} + SOURCES ${QML_FILES} ${SOURCE_FILES} ${PROJECT_SOURCE_DIR}/src/models/appitem.cpp + QM_FILES_OUTPUT_VARIABLE TRANSLATED_FILES + ) + + target_compile_definitions(ds-launchpad-wrapper + PRIVATE + DDE_LAUNCHPAD_VERSION=${CMAKE_PROJECT_VERSION} + ) + target_link_libraries(ds-launchpad-wrapper PRIVATE + Dde::Shell + + ${DTK_NS}::Core + ${DTK_NS}::Gui + Qt::Qml + Qt::Quick + Qt::QuickControls2 + + launcher-qml-windowed + gio-utils + launcher-utils + launcher-qml-utils + launcher-models + dde-integration-dbus + ) + ds_install_package(PACKAGE org.deepin.ds.launchpad TARGET ds-launchpad-wrapper PACKAGE_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/package) + +endif() diff --git a/debian/control b/debian/control index 705d4ea7..3114999b 100644 --- a/debian/control +++ b/debian/control @@ -21,6 +21,7 @@ Build-Depends: # v-- provides DHiDPIHelper libdtk6gui-dev, libdtk6declarative-dev, + libdde-shell-dev, libappstreamqt-dev Standards-Version: 4.6.0 Rules-Requires-Root: no diff --git a/qml/Main.qml b/qml/Main.qml index e4027a8f..bd71ebd6 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -8,6 +8,7 @@ import QtQuick.Layouts 1.15 import QtQuick.Controls 2.15 import QtQuick.Window 2.15 import org.deepin.dtk 1.0 +import org.deepin.ds 1.0 import org.deepin.dtk.style 1.0 as DS import org.deepin.launchpad 1.0 @@ -87,14 +88,15 @@ QtObject { return Qt.rect(rect.left / ratio, rect.top / ratio, rect.width / ratio, rect.height / ratio) } + property point windowedPos: Qt.point(0, 0) function updateWindowVisibilityAndPosition() { if (!LauncherController.visible) return; if (LauncherController.currentFrame === "WindowedFrame") { // root.visibility = Window.Windowed - let width = windowedFrameSize.width - let height = windowedFrameSize.height + let width = windowedFrameWindow.width + let height = windowedFrameWindow.height let x = 0 let y = 0 @@ -103,8 +105,8 @@ QtObject { // console.log(114514, dockGeometry) switch (DesktopIntegration.dockPosition) { case Qt.DownArrow: - x = dockGeometry.left - y = (dockGeometry.top >= 0 ? dockGeometry.top : (Screen.height - dockGeometry.height)) - height - DesktopIntegration.dockSpacing + x = windowedPos.x + y = windowedPos.y - height - DesktopIntegration.dockSpacing break case Qt.LeftArrow: x = dockGeometry.right + DesktopIntegration.dockSpacing @@ -124,12 +126,6 @@ QtObject { windowedFrame.setGeometry(x, y, width, height) windowedFrame.requestActivate() } else { -// root.visibility = Window.FullScreen - if (DesktopIntegration.environmentVariable("DDE_CURRENT_COMPOSITOR") !== "TreeLand") { - fullscreenFrame.setGeometry(Screen.virtualX, Screen.virtualY, Screen.width, Screen.height) - } else { - fullscreenFrame.showFullScreen() - } fullscreenFrame.requestActivate() } } @@ -235,8 +231,9 @@ QtObject { title: "Fullscreen Launchpad" visible: LauncherController.visible && (LauncherController.currentFrame !== "WindowedFrame") - width: Screen.width - height: Screen.height + DLayerShellWindow.anchors: DLayerShellWindow.AnchorBottom | DLayerShellWindow.AnchorTop | DLayerShellWindow.AnchorLeft | DLayerShellWindow.AnchorRight + DLayerShellWindow.layer: DLayerShellWindow.LayerTop + // visibility: Window.FullScreen flags: { if (DebugHelper.useRegularWindow) return Qt.Window