Skip to content

Commit e5a85a4

Browse files
committed
feat: add dock-shell
增加DDockApplet类型,dock的子插件应统一继承此类,方便统一管理 增加DDockItem类型,导出qml组件,提供统一视觉的的tips,icon,... log: as title
1 parent b29f8d6 commit e5a85a4

File tree

11 files changed

+410
-4
lines changed

11 files changed

+410
-4
lines changed

debian/dde-shell.install

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ usr/share/dde-shell/org.deepin.ds.dde-am*/
1515
usr/libexec/dockplugin-loader
1616
usr/lib/*/qt5/plugins/wayland-shell-integration
1717
usr/lib/*/libdde-dockplugin-interface.so.*
18+
usr/lib/*/libdock-plugin.so.*
1819
usr/share/dsg/configs/org.deepin.ds.dock/
1920
usr/lib/dde-dock/tmp/plugins
2021
usr/lib/dde-dock/tmp/plugins/quick-trays

panels/dock/CMakeLists.txt

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ endif(BUILD_WITH_X11)
7878
ds_install_package(PACKAGE org.deepin.ds.dock TARGET dockpanel)
7979
ds_handle_package_translation(PACKAGE org.deepin.ds.dock)
8080

81+
# dock shell
82+
if ((${CMAKE_BUILD_TYPE} MATCHES "Debug"))
83+
add_subdirectory(dock-shell-example)
84+
endif ()
85+
8186
# sub plugins
8287
add_subdirectory(clipboarditem)
8388
add_subdirectory(workspaceitem)
@@ -93,14 +98,20 @@ add_subdirectory(dockplugin)
9398

9499
# dock qml element(include Dock.xx defines and DockCompositor)
95100
file(
96-
GLOB dock_plugin_sources
101+
GLOB dock_plugin_headers
97102
constants.h
103+
ddockapplet.h
104+
)
105+
file(
106+
GLOB dock_plugin_sources
98107
# dockfilterproxymodel.cpp
99108
# dockfilterproxymodel.h
100109
dockpluginmanagerextension_p.h
101110
dockpluginmanagerextension.cpp
102111
dockpluginmanagerintegration_p.h
103112
dockpluginmanagerintegration.cpp
113+
private/ddockapplet_p.h
114+
ddockapplet.cpp
104115
)
105116

106117
set_source_files_properties(DockCompositor.qml PROPERTIES
@@ -117,15 +128,22 @@ set_source_files_properties(DockPalette.qml PROPERTIES
117128

118129
qt_policy(SET QTP0001 OLD)
119130
qt_add_qml_module(dock-plugin
120-
PLUGIN_TARGET dock-plugin
131+
PLUGIN_TARGET dock-qml-plugin
121132
URI "org.deepin.ds.dock"
122133
VERSION "1.0"
123134
SHARED
124-
SOURCES ${dock_plugin_sources}
125-
QML_FILES DockCompositor.qml OverflowContainer.qml MenuHelper.qml DockPalette.qml
135+
SOURCES ${dock_plugin_headers} ${dock_plugin_sources}
136+
QML_FILES DockCompositor.qml OverflowContainer.qml MenuHelper.qml DockPalette.qml DockItem.qml
126137
OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/plugins/org/deepin/ds/dock/
127138
)
128139

140+
set_target_properties(dock-plugin PROPERTIES
141+
VERSION ${CMAKE_PROJECT_VERSION}
142+
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
143+
OUTPUT_NAME dock-plugin
144+
EXPORT_NAME DockShell
145+
)
146+
129147
qt_generate_wayland_protocol_server_sources(dock-plugin
130148
FILES
131149
${CMAKE_CURRENT_SOURCE_DIR}/dockplugin/protocol/dock-plugin-manager-v1.xml
@@ -137,6 +155,7 @@ target_link_libraries(dock-plugin PUBLIC
137155
Qt${QT_VERSION_MAJOR}::Qml
138156
Qt${QT_VERSION_MAJOR}::Widgets
139157
Qt${QT_VERSION_MAJOR}::WaylandCompositor
158+
dde-shell-frame
140159
PRIVATE
141160
PkgConfig::WaylandClient
142161
Qt${QT_VERSION_MAJOR}::WaylandCompositorPrivate
@@ -147,6 +166,19 @@ target_include_directories(dock-plugin
147166
$<TARGET_PROPERTY:dde-shell-frame,INTERFACE_INCLUDE_DIRECTORIES>
148167
)
149168

169+
target_include_directories(dock-plugin INTERFACE
170+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
171+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
172+
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}/dockshell>
173+
)
174+
175+
target_link_directories(dock-plugin INTERFACE
176+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/plugins/org/deepin/ds/dock/>
177+
$<INSTALL_INTERFACE:${LIB_INSTALL_DIR}>
178+
)
179+
180+
install(FILES ${dock_plugin_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/dockshell")
181+
install(TARGETS dock-plugin DESTINATION "${LIB_INSTALL_DIR}")
150182
install(DIRECTORY "${PROJECT_BINARY_DIR}/plugins/org/deepin/ds/dock/" DESTINATION "${QML_INSTALL_DIR}/org/deepin/ds/dock/")
151183
dtk_add_config_meta_files(APPID org.deepin.ds.dock FILES dconfig/org.deepin.ds.dock.json)
152184
dtk_add_config_meta_files(APPID org.deepin.ds.dock FILES dconfig/org.deepin.ds.dock.power.json)

panels/dock/DockItem.qml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
import QtQuick 2.15
6+
import QtQuick.Controls 2.15
7+
8+
import org.deepin.ds 1.0
9+
import org.deepin.dtk 1.0 as D
10+
import org.deepin.dtk.private 1.0 as DP
11+
import org.deepin.ds.dock 1.0
12+
13+
AppletItem {
14+
id: root
15+
property int dockOrder
16+
property bool shouldVisible
17+
property alias toolButtonColor: backgroundButton.color1
18+
property alias toolButtonBorderColor: backgroundButton.outsideBorderColor
19+
property alias toolTip: toolTip.text
20+
property alias icon: button.icon.name
21+
22+
signal clicked
23+
24+
PanelToolTip {
25+
id: toolTip
26+
}
27+
D.ToolButton {
28+
id: button
29+
anchors.centerIn: parent
30+
width: 30
31+
height: 30
32+
icon.width: 16
33+
icon.height: 16
34+
35+
display: D.IconLabel.IconOnly
36+
onClicked: {
37+
toolTip.close()
38+
root.clicked()
39+
}
40+
41+
onHoveredChanged: {
42+
if (toolTip.text === "")
43+
return
44+
45+
if (hovered) {
46+
var point = Applet.rootObject.mapToItem(null, Applet.rootObject.width / 2, 0)
47+
toolTip.toolTipX = point.x
48+
toolTip.toolTipY = point.y
49+
toolTip.open()
50+
} else {
51+
toolTip.close()
52+
}
53+
}
54+
55+
background: DP.ButtonPanel {
56+
id: backgroundButton
57+
58+
button: button
59+
color2: color1
60+
insideBorderColor: null
61+
}
62+
}
63+
}

panels/dock/ddockapplet.cpp

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#include "ddockapplet.h"
6+
#include "private/ddockapplet_p.h"
7+
8+
#include <QLoggingCategory>
9+
10+
DS_BEGIN_NAMESPACE
11+
12+
DCORE_USE_NAMESPACE
13+
14+
Q_DECLARE_LOGGING_CATEGORY(dsLog)
15+
16+
DDockAppletPrivate::DDockAppletPrivate(DDockApplet *qq)
17+
: DAppletPrivate(qq)
18+
{
19+
20+
}
21+
22+
DDockAppletPrivate::~DDockAppletPrivate()
23+
{
24+
25+
}
26+
27+
DDockApplet::DDockApplet(QObject *parent)
28+
: DDockApplet(*new DDockAppletPrivate(this), parent)
29+
{
30+
31+
}
32+
33+
DDockApplet::DDockApplet(DDockAppletPrivate &dd, QObject *parent)
34+
: DApplet(dd, parent)
35+
{
36+
37+
}
38+
39+
DDockApplet::~DDockApplet()
40+
{
41+
qDebug(dsLog) << "Destroyed DDockApplet:" << pluginId() << id();
42+
}
43+
44+
/*!
45+
A unique name that identifies the plug-in. The default implementation is `pluginId`.
46+
*/
47+
QString DDockApplet::name() const
48+
{
49+
return DApplet::pluginId();
50+
}
51+
52+
/*!
53+
A name that displays a name that matches the current locale
54+
*/
55+
/**
56+
* @brief DDockApplet::displayName
57+
* @return
58+
*/
59+
60+
/**
61+
* @brief DDockApplet::itemKey
62+
* @return
63+
*/
64+
65+
/**
66+
* @brief DDockApplet::settingKey
67+
* @return
68+
*/
69+
70+
/*!
71+
A dci icon for display
72+
*/
73+
QString DDockApplet::icon() const
74+
{
75+
D_DC(DDockApplet);
76+
77+
return d->icon;
78+
}
79+
80+
void DDockApplet::setIcon(const QString &icon)
81+
{
82+
D_D(DDockApplet);
83+
84+
d->icon = icon;
85+
Q_EMIT iconChanged(icon);
86+
}
87+
88+
/*!
89+
Whether the plug-in is displayed on the panel
90+
*/
91+
bool DDockApplet::visible() const
92+
{
93+
D_DC(DDockApplet);
94+
95+
return d->visible;
96+
}
97+
98+
void DDockApplet::setVisible(bool visible)
99+
{
100+
D_D(DDockApplet);
101+
102+
if (d->visible == visible)
103+
return;
104+
105+
d->visible = visible;
106+
Q_EMIT visibleChanged(visible);
107+
}
108+
109+
DS_END_NAMESPACE

panels/dock/ddockapplet.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#pragma once
6+
7+
#include "applet.h"
8+
#include "dsglobal.h"
9+
10+
#include <DObject>
11+
#include <DDciIcon>
12+
13+
#include <QVariant>
14+
15+
DGUI_USE_NAMESPACE
16+
DS_BEGIN_NAMESPACE
17+
/**
18+
* @brief You Can Used As Dock Plugins Sub Class
19+
*/
20+
class DDockAppletPrivate;
21+
class DS_SHARE DDockApplet : public DApplet
22+
{
23+
Q_OBJECT
24+
Q_PROPERTY(QString name READ name CONSTANT FINAL)
25+
Q_PROPERTY(QString displayName READ displayName CONSTANT FINAL)
26+
Q_PROPERTY(QString itemKey READ itemKey CONSTANT FINAL)
27+
Q_PROPERTY(QString settingKey READ settingKey CONSTANT FINAL)
28+
Q_PROPERTY(QString icon READ icon NOTIFY iconChanged FINAL)
29+
Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged FINAL);
30+
31+
D_DECLARE_PRIVATE(DDockApplet);
32+
33+
public:
34+
explicit DDockApplet(QObject *parent = nullptr);
35+
virtual ~DDockApplet() override;
36+
37+
virtual QString name() const;
38+
virtual QString displayName() const = 0;
39+
virtual QString itemKey() const = 0;
40+
virtual QString settingKey() const = 0;
41+
42+
QString icon() const;
43+
void setIcon(const QString &icon);
44+
45+
bool visible() const;
46+
void setVisible(bool visible);
47+
48+
Q_SIGNALS:
49+
void iconChanged(const QString &);
50+
void visibleChanged(bool);
51+
52+
protected:
53+
explicit DDockApplet(DDockAppletPrivate &dd, QObject *parent = nullptr);
54+
};
55+
56+
DS_END_NAMESPACE
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
add_library(dock-shell-example SHARED
6+
item.cpp
7+
item.h
8+
)
9+
10+
target_link_libraries(dock-shell-example PRIVATE
11+
dock-plugin
12+
)
13+
14+
ds_install_package(PACKAGE org.deepin.ds.dock.dock-shell-example TARGET dock-shell-example)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#include "item.h"
6+
#include "pluginfactory.h"
7+
8+
#include <DDBusSender>
9+
#include <DDciIcon>
10+
#include <DGuiApplicationHelper>
11+
12+
#include <QGuiApplication>
13+
#include <QBuffer>
14+
15+
DGUI_USE_NAMESPACE
16+
17+
namespace dock {
18+
19+
Item::Item(QObject *parent)
20+
: DDockApplet(parent)
21+
{
22+
// for debug
23+
setVisible(true);
24+
}
25+
26+
void Item::activate()
27+
{
28+
qDebug() << "item clicked";
29+
}
30+
31+
QString Item::displayName() const
32+
{
33+
return "dock-shell-example";
34+
}
35+
36+
QString Item::itemKey() const
37+
{
38+
return "dock-shell-example";
39+
}
40+
41+
QString Item::settingKey() const
42+
{
43+
return "dock-shell-example";
44+
}
45+
46+
D_APPLET_CLASS(Item)
47+
}
48+
49+
50+
#include "item.moc"

0 commit comments

Comments
 (0)