Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions panels/dock/dconfig/org.deepin.ds.dock.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@
"description": "lock dock to prevent dragging resize",
"permissions": "readwrite",
"visibility": "private"
},
"enableShowDesktop": {
"value": true,
"serial": 0,
"flags": [],
"name": "Enable ShowDesktop",
"name[zh_CN]": "启用显示桌面区域",
"description": "Enable or disable the show desktop area on the right side of the dock",
"permissions": "readwrite",
"visibility": "private"
}
}
}
1 change: 1 addition & 0 deletions panels/dock/showdesktop/package/showdesktop.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ AppletItem {
property bool useColumnLayout: Panel.position % 2
property int dockSize: Panel.rootObject.dockItemMaxSize
property int dockOrder: 30
property bool shouldVisible: Applet.visible
implicitWidth: useColumnLayout ? Panel.rootObject.dockSize : showDesktopWidth
implicitHeight: useColumnLayout ? showDesktopWidth : Panel.rootObject.dockSize

Expand Down
46 changes: 45 additions & 1 deletion panels/dock/showdesktop/showdesktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,34 @@

#include <QProcess>
#include <QGuiApplication>
#include <QDBusInterface>

Check warning on line 12 in panels/dock/showdesktop/showdesktop.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusInterface> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLoggingCategory>

Check warning on line 13 in panels/dock/showdesktop/showdesktop.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <DConfig>

Check warning on line 15 in panels/dock/showdesktop/showdesktop.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DConfig> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DCORE_USE_NAMESPACE

Q_LOGGING_CATEGORY(showDesktop, "dde.shell.dock.showdesktop")

namespace dock {

ShowDesktop::ShowDesktop(QObject *parent)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider replacing the raw DConfig pointer and separate slot with an in-place DConfig member and a single lambda to update visibility.

Consider ditching the raw DConfig* + validity checks + extra slot and just keep a DConfig member initialized in-place, read the default once, and hook one lambda to update your m_visible. You can collapse ctor + init into:

// showdesktop.h
class ShowDesktop : public DApplet {
    Q_OBJECT
    Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
public:
    explicit ShowDesktop(QObject *parent = nullptr);

    bool visible() const { return m_visible; }
    void setVisible(bool v) {
        if (m_visible == v) return;
        m_visible = v;
        Q_EMIT visibleChanged();
    }

signals:
    void visibleChanged();

private:
    DConfig m_dockConfig{"org.deepin.dde.shell", "org.deepin.ds.dock"};
    bool    m_visible{true};
};
// showdesktop.cpp
ShowDesktop::ShowDesktop(QObject *parent)
    : DApplet(parent)
    , m_visible(m_dockConfig.value("Enable_ShowDesktop", true).toBool())
{
    // One shot: emit initial state
    Q_EMIT visibleChanged();

    // Update on config change
    connect(&m_dockConfig, &DConfig::valueChanged, this, [this](const QString &key) {
        if (key == QLatin1String("Enable_ShowDesktop")) {
            setVisible(m_dockConfig.value(key, true).toBool());
        }
    });

    DApplet::init();
}

This:

  • Removes the raw pointer + .isValid() guards
  • Inlines the “read default” & “watch for changes” in one place
  • Eliminates a separate onEnableShowDesktopChanged() slot
  • Keeps all existing behavior intact but cuts ~20 lines of boilerplate.

: DApplet(parent)
, m_windowManager(nullptr)
, m_dockConfig(nullptr)
, m_visible(true)
{

// 创建DConfig实例来读取dock配置
m_dockConfig = DConfig::create("org.deepin.dde.shell", "org.deepin.ds.dock", QString(), this);

if (m_dockConfig) {
// 监听配置变化
connect(m_dockConfig, &DConfig::valueChanged, this, [this](const QString &key) {
if (key == "enableShowDesktop") {
onEnableShowDesktopChanged();
}
});
}
}

bool ShowDesktop::load()
Expand All @@ -33,6 +49,12 @@
if (QStringLiteral("wayland") == QGuiApplication::platformName()) {
m_windowManager = new TreelandWindowManager(this);
}

// 从配置中读取初始的可见性状态
if (m_dockConfig && m_dockConfig->isValid()) {
m_visible = m_dockConfig->value("enableShowDesktop", true).toBool();
}

DApplet::init();
return true;
}
Expand Down Expand Up @@ -60,6 +82,28 @@
return false;
}

bool ShowDesktop::visible() const
{
return m_visible;
}

void ShowDesktop::setVisible(bool visible)
{
if (m_visible != visible) {
m_visible = visible;
Q_EMIT visibleChanged();
}
}

void ShowDesktop::onEnableShowDesktopChanged()
{
if (m_dockConfig && m_dockConfig->isValid()) {
bool enabled = m_dockConfig->value("enableShowDesktop", true).toBool();
qCDebug(showDesktop) << "onEnableShowDesktopChanged" << enabled;
setVisible(enabled);
}
}

D_APPLET_CLASS(ShowDesktop)
}

Expand Down
15 changes: 15 additions & 0 deletions panels/dock/showdesktop/showdesktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,39 @@
#pragma once

#include "applet.h"
#include "dsglobal.h"

Check warning on line 8 in panels/dock/showdesktop/showdesktop.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dsglobal.h" not found.
#include "treelandwindowmanager.h"

#include <DConfig>

Check warning on line 11 in panels/dock/showdesktop/showdesktop.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DConfig> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace dock {

class ShowDesktop : public DS_NAMESPACE::DApplet
{
Q_OBJECT
Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)

public:
explicit ShowDesktop(QObject *parent = nullptr);
virtual bool init() override;
virtual bool load() override;

Q_INVOKABLE void toggleShowDesktop();
Q_INVOKABLE bool checkNeedShowDesktop();

bool visible() const;
void setVisible(bool visible);

Q_SIGNALS:
void visibleChanged();

private slots:

Check warning on line 34 in panels/dock/showdesktop/showdesktop.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.
void onEnableShowDesktopChanged();

private:
TreelandWindowManager *m_windowManager;
Dtk::Core::DConfig *m_dockConfig;
bool m_visible;
};

}