Skip to content

Commit

Permalink
fix: unable to set visibility of 'Show Desktop' in DCC
Browse files Browse the repository at this point in the history
  • Loading branch information
zsien authored and yixinshark committed Jul 26, 2024
1 parent 057636c commit 55c8c0b
Show file tree
Hide file tree
Showing 25 changed files with 316 additions and 2 deletions.
20 changes: 19 additions & 1 deletion panels/dock/dockdbusproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ DockDBusProxy::DockDBusProxy(DockPanel* parent)
, m_clipboardApplet(nullptr)
, m_searchApplet(nullptr)
, m_multitaskviewApplet(nullptr)
, m_showdesktopApplet(nullptr)
, m_trayApplet(nullptr)
{
registerPluginInfoMetaType();
Expand All @@ -29,12 +30,14 @@ DockDBusProxy::DockDBusProxy(DockPanel* parent)
setPluginVisible("org.deepin.ds.dock.clipboarditem", pluginsVisible);
setPluginVisible("org.deepin.ds.dock.searchitem", pluginsVisible);
setPluginVisible("org.deepin.ds.dock.multitaskview", pluginsVisible);
setPluginVisible("org.deepin.ds.dock.showdesktop", pluginsVisible);
});
connect(parent, &DockPanel::rootObjectChanged, this, [this]() {
auto pluginsVisible = DockSettings::instance()->pluginsVisible();
setPluginVisible("org.deepin.ds.dock.clipboarditem", pluginsVisible);
setPluginVisible("org.deepin.ds.dock.searchitem", pluginsVisible);
setPluginVisible("org.deepin.ds.dock.multitaskview", pluginsVisible);
setPluginVisible("org.deepin.ds.dock.showdesktop", pluginsVisible);
});

// Communicate with the other module
Expand All @@ -51,7 +54,10 @@ DockDBusProxy::DockDBusProxy(DockPanel* parent)
list = appletList("org.deepin.ds.dock.multitaskview");
if (!list.isEmpty()) m_multitaskviewApplet = list.first();

return m_trayApplet && m_clipboardApplet && m_searchApplet && m_multitaskviewApplet;
list = appletList("org.deepin.ds.dock.showdesktop");
if (!list.isEmpty()) m_showdesktopApplet = list.first();

return m_trayApplet && m_clipboardApplet && m_searchApplet && m_multitaskviewApplet && m_showdesktopApplet;
};

// TODO: DQmlGlobal maybe missing a signal which named `appletListChanged`?
Expand Down Expand Up @@ -259,6 +265,13 @@ DockItemInfos DockDBusProxy::plugins()
iteminfos.append(info);
}
}

if (m_showdesktopApplet && DWindowManagerHelper::instance()->hasComposite()) {
DockItemInfo info;
if (QMetaObject::invokeMethod(m_showdesktopApplet, "dockItemInfo", Qt::DirectConnection, qReturnArg(info))) {
iteminfos.append(info);
}
}
return iteminfos;
}

Expand Down Expand Up @@ -289,6 +302,11 @@ void DockDBusProxy::setItemOnDock(const QString &settingKey, const QString &item
auto pluginsVisible = DockSettings::instance()->pluginsVisible();
pluginsVisible[itemKey] = visible;
DockSettings::instance()->setPluginsVisible(pluginsVisible);
} else if (itemKey == "showdesktop" && m_showdesktopApplet) {
QMetaObject::invokeMethod(m_showdesktopApplet, "setVisible", Qt::QueuedConnection, visible);
auto pluginsVisible = DockSettings::instance()->pluginsVisible();
pluginsVisible[itemKey] = visible;
DockSettings::instance()->setPluginsVisible(pluginsVisible);
} else if (m_trayApplet) {
Q_EMIT pluginVisibleChanged(itemKey, visible);
QMetaObject::invokeMethod(m_trayApplet, "setItemOnDock", Qt::QueuedConnection, settingKey, itemKey, visible);
Expand Down
1 change: 1 addition & 0 deletions panels/dock/dockdbusproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class DockDBusProxy final: public QObject, public QDBusContext
DS_NAMESPACE::DApplet *m_clipboardApplet;
DS_NAMESPACE::DApplet *m_searchApplet;
DS_NAMESPACE::DApplet *m_multitaskviewApplet;
DS_NAMESPACE::DApplet *m_showdesktopApplet;
DS_NAMESPACE::DApplet *m_trayApplet;
};
}
Expand Down
10 changes: 10 additions & 0 deletions panels/dock/showdesktop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@
add_library(dock-showdesktop SHARED
showdesktop.cpp
showdesktop.h
../dockiteminfo.cpp
../dockiteminfo.h
)

target_include_directories(dock-showdesktop PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}/../"
"../"
)

target_link_libraries(dock-showdesktop PRIVATE
dde-shell-frame
)

ds_install_package(PACKAGE org.deepin.ds.dock.showdesktop TARGET dock-showdesktop)
ds_handle_package_translation(PACKAGE org.deepin.ds.dock.showdesktop)

install(FILES "package/icons/showdesktop.svg" DESTINATION share/dde-dock/icons/dcc-setting)
13 changes: 13 additions & 0 deletions panels/dock/showdesktop/package/icons/showdesktop.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 32 additions & 1 deletion panels/dock/showdesktop/showdesktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@
#include "applet.h"
#include "showdesktop.h"
#include "pluginfactory.h"
#include "../constants.h"

#include <QProcess>
#include <QGuiApplication>
#include <QDBusInterface>
#include <QLoggingCategory>
#include <DWindowManagerHelper>

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

DGUI_USE_NAMESPACE

namespace dock {

ShowDesktop::ShowDesktop(QObject *parent)
: DApplet(parent)
, m_visible(true)
{

connect(DWindowManagerHelper::instance(), &DWindowManagerHelper::hasCompositeChanged, this, &ShowDesktop::visibleChanged);
}

bool ShowDesktop::load()
Expand Down Expand Up @@ -50,6 +55,32 @@ bool ShowDesktop::checkNeedShowDesktop()
return false;
}

DockItemInfo ShowDesktop::dockItemInfo()
{
DockItemInfo info;
info.name = "showdesktop";
info.displayName = tr("Show Desktop");
info.itemKey = "showdesktop";
info.settingKey = "showdesktop";
info.visible = visible();
info.dccIcon = DCCIconPath + "showdesktop.svg";
return info;
}

bool ShowDesktop::visible() const
{
return m_visible && DWindowManagerHelper::instance()->hasComposite();
}

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

Q_EMIT visibleChanged();
}
}

D_APPLET_CLASS(ShowDesktop)
}

Expand Down
13 changes: 13 additions & 0 deletions panels/dock/showdesktop/showdesktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,32 @@

#include "applet.h"
#include "dsglobal.h"
#include "../dockiteminfo.h"

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();

Q_INVOKABLE DockItemInfo dockItemInfo();
Q_INVOKABLE bool visible() const;
Q_INVOKABLE void setVisible(bool visible);

Q_SIGNALS:
void visibleChanged();

private:
bool m_visible;
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>dock::ShowDesktop</name>
<message>
<location filename="../showdesktop.cpp" line="62"/>
<source>Show Desktop</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Loading

0 comments on commit 55c8c0b

Please sign in to comment.