Skip to content

Commit deeca9f

Browse files
committed
feat: add shutdown applet
Add shutdown applet to handle power management for x11 and treeland in a unified manner Log: add shutdown applet
1 parent 9deb101 commit deeca9f

File tree

12 files changed

+127
-12
lines changed

12 files changed

+127
-12
lines changed

applets/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
add_subdirectory(dde-am)
66
add_subdirectory(dde-appearance)
77
add_subdirectory(dde-apps)
8+
add_subdirectory(dde-shutdown)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
add_library(dde-shutdown SHARED
6+
shutdownapplet.cpp
7+
shutdownapplet.h
8+
)
9+
10+
target_link_libraries(dde-shutdown PRIVATE
11+
dde-shell-frame
12+
Qt${QT_MAJOR_VERSION}::DBus
13+
)
14+
15+
ds_install_package(PACKAGE org.deepin.ds.dde-shutdown TARGET dde-shutdown)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"Plugin": {
3+
"Version": "1.0",
4+
"Id": "org.deepin.ds.dde-shutdown",
5+
"Category": "DDE"
6+
}
7+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#include "shutdownapplet.h"
6+
#include "pluginfactory.h"
7+
8+
#include <QDebug>
9+
#include <QGuiApplication>
10+
11+
#include <DDBusSender>
12+
DCORE_USE_NAMESPACE
13+
14+
DS_BEGIN_NAMESPACE
15+
namespace shutdown {
16+
17+
ShutdownApplet::ShutdownApplet(QObject *parent)
18+
: DApplet(parent)
19+
{
20+
}
21+
22+
ShutdownApplet::~ShutdownApplet()
23+
{
24+
}
25+
26+
bool ShutdownApplet::load()
27+
{
28+
return true;
29+
}
30+
31+
bool ShutdownApplet::requestShutdown()
32+
{
33+
if (QStringLiteral("wayland") == QGuiApplication::platformName()) {
34+
qDebug() << "request treeland shutdown";
35+
} else {
36+
DDBusSender()
37+
.service("org.deepin.dde.ShutdownFront1")
38+
.interface("org.deepin.dde.ShutdownFront1")
39+
.path("/org/deepin/dde/ShutdownFront1")
40+
.method("Show")
41+
.call();
42+
}
43+
44+
return true;
45+
}
46+
47+
D_APPLET_CLASS(ShutdownApplet)
48+
}
49+
DS_END_NAMESPACE
50+
51+
#include "shutdownapplet.moc"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-FileCopyrightText: 2024 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+
9+
DS_BEGIN_NAMESPACE
10+
namespace shutdown {
11+
class ShutdownApplet : public DApplet
12+
{
13+
Q_OBJECT
14+
public:
15+
explicit ShutdownApplet(QObject *parent = nullptr);
16+
~ShutdownApplet();
17+
18+
virtual bool load() override;
19+
20+
public Q_SLOTS:
21+
bool requestShutdown();
22+
};
23+
24+
}
25+
DS_END_NAMESPACE

panels/dock/DockCompositor.qml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Item {
2727

2828
signal pluginSurfacesUpdated()
2929
signal popupCreated(var popup)
30+
signal requestShutdown()
3031

3132
function removeDockPluginSurface(model, object) {
3233
for (var i = 0; i < model.count; ++i) {
@@ -101,6 +102,10 @@ Item {
101102
console.log("plugin popup created", popup.pluginId, popup.itemKey, popup.popupType)
102103
dockCompositor.popupCreated(popup)
103104
}
105+
106+
onRequestShutdown: {
107+
dockCompositor.requestShutdown()
108+
}
104109
}
105110
}
106111
}

panels/dock/pluginmanagerextension.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ void PluginSurface::plugin_dcc_icon(Resource *resource, const QString &icon)
115115
m_dccIcon = icon;
116116
}
117117

118+
void PluginSurface::plugin_request_shutdown(Resource *resource)
119+
{
120+
Q_UNUSED(resource);
121+
Q_EMIT m_manager->requestShutdown();
122+
}
123+
118124
void PluginSurface::plugin_destroy_resource(Resource *resource)
119125
{
120126
Q_UNUSED(resource);

panels/dock/pluginmanagerextension_p.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class PluginManager : public QWaylandCompositorExtensionTemplate<PluginManager>,
5050
void pluginSurfaceDestroyed(PluginSurface*);
5151
void messageRequest(PluginSurface *, const QString &msg);
5252
void dockSizeChanged();
53+
void requestShutdown();
5354

5455
protected:
5556
virtual void plugin_manager_v1_request_message(Resource *resource, const QString &plugin_id, const QString &item_key, const QString &msg) override;
@@ -131,6 +132,7 @@ class PluginSurface : public QWaylandShellSurfaceTemplate<PluginSurface>, public
131132
protected:
132133
virtual void plugin_mouse_event(Resource *resource, int32_t type) override;
133134
virtual void plugin_dcc_icon(Resource *resource, const QString &icon) override;
135+
virtual void plugin_request_shutdown(Resource *resource) override;
134136
virtual void plugin_destroy_resource(Resource *resource) override;
135137
virtual void plugin_destroy(Resource *resource) override;
136138

panels/dock/tray/package/tray.qml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ AppletItem {
156156
DDT.TraySortOrderModel.availableSurfaces = surfacesData
157157
console.log("onPluginSurfacesUpdated", surfacesData.length)
158158
}
159+
160+
function onRequestShutdown() {
161+
var shutdown = DS.applet("org.deepin.ds.dde-shutdown")
162+
if (shutdown) {
163+
shutdown.requestShutdown()
164+
} else {
165+
console.warn("shutdown applet not found")
166+
}
167+
}
159168
}
160169

161170
WaylandOutput {

panels/dock/tray/quickpanel/PanelPluginPage.qml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ Item {
5858
icon.name: "quickpanel-power"
5959
onClicked: function () {
6060
console.log("clicked shutdown")
61-
model.openShutdownScreen()
61+
var shutdown = DS.applet("org.deepin.ds.dde-shutdown")
62+
if (shutdown) {
63+
shutdown.requestShutdown()
64+
} else {
65+
console.warn("shutdown applet not found")
66+
}
6267
}
6368
}
6469
}

0 commit comments

Comments
 (0)