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
11 changes: 11 additions & 0 deletions panels/dock/dconfig/org.deepin.ds.dock.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@
"description": "Enable or disable the show desktop area on the right side of the dock",
"permissions": "readwrite",
"visibility": "private"
},
"enableContextMenu": {
"value": true,
"serial": 0,
"flags": [],
"name": "Enable Dock Context Menu",
"name[zh_CN]": "启用任务栏右键菜单",
"description": "Enable or disable the context menu on the empty area of the dock.",
"description[zh_CN]": "启用或禁用任务栏空白区域的右键菜单和触摸长按菜单。",
"permissions": "readwrite",
"visibility": "private"
}
}
}
6 changes: 6 additions & 0 deletions panels/dock/dockpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ bool DockPanel::init()
connect(SETTINGS, &DockSettings::itemAlignmentChanged, this, &DockPanel::itemAlignmentChanged);
connect(SETTINGS, &DockSettings::indicatorStyleChanged, this, &DockPanel::indicatorStyleChanged);
connect(SETTINGS, &DockSettings::lockedChanged, this, &DockPanel::lockedChanged);
connect(SETTINGS, &DockSettings::contextMenuEnabledChanged, this, &DockPanel::contextMenuEnabledChanged);

connect(SETTINGS, &DockSettings::dockSizeChanged, this, [this, dockDaemonAdaptor](){
Q_EMIT dockDaemonAdaptor->WindowSizeEfficientChanged(dockSize());
Expand Down Expand Up @@ -425,6 +426,11 @@ bool DockPanel::locked() const
return SETTINGS->locked();
}

bool DockPanel::contextMenuEnabled() const
{
return SETTINGS->contextMenuEnabled();
}

void DockPanel::setLocked(bool newLocked)
{
SETTINGS->setLocked(newLocked);
Expand Down
3 changes: 3 additions & 0 deletions panels/dock/dockpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DockPanel : public DS_NAMESPACE::DPanel, public QDBusContext
Q_PROPERTY(QString screenName READ screenName NOTIFY screenNameChanged FINAL)
Q_PROPERTY(bool locked READ locked WRITE setLocked NOTIFY lockedChanged FINAL)
Q_PROPERTY(bool isResizing READ isResizing WRITE setIsResizing NOTIFY isResizingChanged FINAL)
Q_PROPERTY(bool contextMenuEnabled READ contextMenuEnabled NOTIFY contextMenuEnabledChanged FINAL)

Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged FINAL)

Expand Down Expand Up @@ -93,6 +94,7 @@ class DockPanel : public DS_NAMESPACE::DPanel, public QDBusContext

bool locked() const;
void setLocked(bool newLocked);
bool contextMenuEnabled() const;

void setHideState(HideState newHideState);
QScreen* dockScreen();
Expand Down Expand Up @@ -135,6 +137,7 @@ private Q_SLOTS:
void leftEdgeClicked(const QString &minOrder);
void devicePixelRatioChanged(qreal ratio);
void lockedChanged(bool locked);
void contextMenuEnabledChanged(bool enabled);

void contextDraggingChanged();
void isResizingChanged(bool isResizing);
Expand Down
13 changes: 13 additions & 0 deletions panels/dock/docksettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const static QString keyIndicatorStyle = "Indicator_Style";
const static QString keyPluginsVisible = "Plugins_Visible";
const static QString keyShowInPrimary = "Show_In_Primary";
const static QString keyLocked = "Locked";
const static QString keyEnableContextMenu = "enableContextMenu";

namespace dock {

Expand Down Expand Up @@ -156,6 +157,7 @@ DockSettings::DockSettings(QObject* parent)
, m_alignment(dock::CenterAlignment)
, m_style(dock::Fashion)
, m_locked(false)
, m_contextMenuEnabled(true)
{
m_writeTimer->setSingleShot(true);
m_writeTimer->setInterval(1000);
Expand All @@ -174,6 +176,7 @@ void DockSettings::init()
m_pluginsVisible = m_dockConfig->value(keyPluginsVisible).toMap();
m_showInPrimary = m_dockConfig->value(keyShowInPrimary).toBool();
m_locked = m_dockConfig->value(keyLocked).toBool();
m_contextMenuEnabled = m_dockConfig->value(keyEnableContextMenu, true).toBool();

// Log dock config on startup - merge shell_pos and shell_dock_mode into one log entry
logDockConfig(m_dockPosition, m_alignment, QStringLiteral("on startup"));
Expand Down Expand Up @@ -217,6 +220,11 @@ void DockSettings::init()
if (locked == m_locked) return;
m_locked = locked;
Q_EMIT lockedChanged(m_locked);
} else if (keyEnableContextMenu == key) {
const auto enabled = m_dockConfig->value(keyEnableContextMenu, true).toBool();
if (enabled == m_contextMenuEnabled) return;
m_contextMenuEnabled = enabled;
Q_EMIT contextMenuEnabledChanged(m_contextMenuEnabled);
}
});
} else {
Expand Down Expand Up @@ -331,6 +339,11 @@ bool DockSettings::locked() const
return m_locked;
}

bool DockSettings::contextMenuEnabled() const
{
return m_contextMenuEnabled;
}

void DockSettings::setLocked(bool newLocked)
{
if (m_locked == newLocked) {
Expand Down
4 changes: 4 additions & 0 deletions panels/dock/docksettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DockSettings : public QObject
Q_PROPERTY(QVariantMap pluginsVisible READ pluginsVisible WRITE setPluginsVisible NOTIFY pluginsVisibleChanged FINAL)
Q_PROPERTY(bool showInPrimary READ showInPrimary WRITE setShowInPrimary NOTIFY showInPrimaryChanged FINAL)
Q_PROPERTY(bool locked READ locked WRITE setLocked NOTIFY lockedChanged FINAL)
Q_PROPERTY(bool contextMenuEnabled READ contextMenuEnabled NOTIFY contextMenuEnabledChanged FINAL)

public:
static DockSettings* instance();
Expand All @@ -40,6 +41,7 @@ class DockSettings : public QObject
QVariantMap pluginsVisible();
bool showInPrimary() const;
bool locked() const;
bool contextMenuEnabled() const;

void setDockSize(const uint& size);
void setHideMode(const HideMode& mode);
Expand Down Expand Up @@ -76,6 +78,7 @@ class DockSettings : public QObject

void showInPrimaryChanged(bool showInPrimary);
void lockedChanged(bool locked);
void contextMenuEnabledChanged(bool enabled);

private:
QScopedPointer<DConfig> m_dockConfig;
Expand All @@ -90,5 +93,6 @@ class DockSettings : public QObject
QVariantMap m_pluginsVisible;
bool m_showInPrimary;
bool m_locked;
bool m_contextMenuEnabled;
};
}
28 changes: 23 additions & 5 deletions panels/dock/package/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ Window {
}

function requestShowDockMenu() {
if (!Panel.contextMenuEnabled)
return

// maybe has popup visible, close it.
Panel.requestClosePopup()
viewDeactivated()
Expand Down Expand Up @@ -381,6 +384,18 @@ Window {
}
}

Connections {
target: Panel
function onContextMenuEnabledChanged() {
if (Panel.contextMenuEnabled)
return

if (MenuHelper.activeMenu === dockMenuLoader.item)
MenuHelper.closeCurrent()
dockMenuLoader.active = false
}
}

Item {
id: dockContainer
width: dock.useColumnLayout ? dock.dockSize : parent.width
Expand Down Expand Up @@ -418,8 +433,10 @@ Window {
onTapped: function(eventPoint, button) {
let lastActive = MenuHelper.activeMenu
MenuHelper.closeCurrent()
dockMenuLoader.active = true
if (button === Qt.RightButton && lastActive !== dockMenuLoader.item) {
if (button === Qt.RightButton && Panel.contextMenuEnabled) {
dockMenuLoader.active = true
}
if (button === Qt.RightButton && Panel.contextMenuEnabled && lastActive !== dockMenuLoader.item) {
requestShowDockMenu()
}
if (button === Qt.LeftButton) {
Expand All @@ -441,7 +458,6 @@ Window {
}
let lastActive = MenuHelper.activeMenu
MenuHelper.closeCurrent()
dockMenuLoader.active = true
// try to close popup when clicked empty, because dock does not have focus.
Panel.requestClosePopup()
viewDeactivated()
Expand All @@ -450,8 +466,10 @@ Window {
dockContainer.touchLongPressed = true
let lastActive = MenuHelper.activeMenu
MenuHelper.closeCurrent()
dockMenuLoader.active = true
if (lastActive !== dockMenuLoader.item) {
if (Panel.contextMenuEnabled) {
dockMenuLoader.active = true
}
if (Panel.contextMenuEnabled && lastActive !== dockMenuLoader.item) {
requestShowDockMenu()
}
}
Expand Down
14 changes: 9 additions & 5 deletions panels/dock/taskmanager/appitem.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -27,6 +27,8 @@ AppItem::AppItem(QString id, QObject *parent)
connect(this, &AbstractItem::dataChanged, this, &AppItem::checkAppItemNeedDeleteAndDelete);

connect(this, &AppItem::currentActiveWindowChanged, this, &AbstractItem::iconChanged);
connect(TaskManagerSettings::instance(), &TaskManagerSettings::dockedApplicationsEnabledChanged,
this, [this] { Q_EMIT menusChanged(); });
}

AppItem::~AppItem()
Expand Down Expand Up @@ -105,10 +107,12 @@ QString AppItem::menus() const
// array.append(allWindowMenu);
// }

QJsonObject dockMenu;
dockMenu["id"] = DOCK_ACTION_DOCK;
dockMenu["name"] = isDocked() ? tr("Undock") : tr("Dock");
array.append(dockMenu);
if (TaskManagerSettings::instance()->dockedApplicationsEnabled()) {
QJsonObject dockMenu;
dockMenu["id"] = DOCK_ACTION_DOCK;
dockMenu["name"] = isDocked() ? tr("Undock") : tr("Dock");
array.append(dockMenu);
}

if (hasWindow()) {
QJsonObject foreceQuit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@
"description": "List of app id that should prefer window icon when window split is disabled",
"permissions": "readwrite",
"visibility": "private"
},
"enableDockedApplications": {
"value": true,
"serial": 0,
"flags": [],
"name": "Enable Docked Applications",
"name[zh_CN]": "启用驻留任务栏应用",
"description": "Enable or disable docked applications on the taskbar. When disabled, docked applications that are not running are hidden and docking changes are rejected, while the saved docked application list is preserved.",
"description[zh_CN]": "启用或禁用任务栏驻留应用;关闭时隐藏未运行的驻留应用并禁止更改驻留状态,但保留已保存的驻留应用列表。",
"permissions": "readwrite",
"visibility": "private"
}

}
Expand Down
7 changes: 6 additions & 1 deletion panels/dock/taskmanager/desktopfileabstractparser.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -139,6 +139,11 @@ bool DesktopfileAbstractParser::isDocked()

void DesktopfileAbstractParser::setDocked(bool docked)
{
if (!TaskManagerSettings::instance()->dockedApplicationsEnabled()) {
qDebug() << "Docked application changes are disabled by DConfig";
return;
}

if (!isValied().first && docked) {
qDebug() << isValied().second;
return;
Expand Down
4 changes: 3 additions & 1 deletion panels/dock/taskmanager/desktopfileamparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "desktopfileamparser.h"
#include "desktopfileabstractparser.h"
#include "objectmanager1interface.h"
#include "taskmanagersettings.h"

#include <unistd.h>
#include <sys/syscall.h>
Expand Down Expand Up @@ -43,7 +44,8 @@ DesktopFileAMParser::DesktopFileAMParser(QString id, QObject* parent)
connect(&desktopobjectManager, &ObjectManager::InterfacesRemoved, this, [this] (const QDBusObjectPath& path, const QStringList& interfaces) {
Q_UNUSED(interfaces)
if (m_applicationInterface->path() == path.path()) {
getAppItem()->setDocked(false);
TaskManagerSettings::instance()->removeDockedElement(QStringLiteral("desktop/%1").arg(this->id()));
Q_EMIT dockedChanged();
return;
}
});
Expand Down
63 changes: 34 additions & 29 deletions panels/dock/taskmanager/dockglobalelementmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ DockGlobalElementModel::DockGlobalElementModel(QAbstractItemModel *appsModel, Do
{
connect(TaskManagerSettings::instance(), &TaskManagerSettings::dockedElementsChanged, this, &DockGlobalElementModel::loadDockedElements);
connect(TaskManagerSettings::instance(), &TaskManagerSettings::windowSplitChanged, this, &DockGlobalElementModel::groupItemsByApp);
connect(TaskManagerSettings::instance(), &TaskManagerSettings::dockedApplicationsEnabledChanged, this, &DockGlobalElementModel::loadDockedElements);

connect(
m_appsModel,
Expand Down Expand Up @@ -258,39 +259,41 @@ void DockGlobalElementModel::initDockedElements(bool unused)
void DockGlobalElementModel::loadDockedElements()
{
QList<std::tuple<QString, QString>> newDocked;
for (auto elementInfo : TaskManagerSettings::instance()->dockedElements()) {
auto pair = elementInfo.split('/');
if (pair.size() != 2)
continue;
if (TaskManagerSettings::instance()->dockedApplicationsEnabled()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

dockedApplicationsEnabled 如果为false,后面的都不用执行了吧,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

最后一部分是在 禁用驻留的时候, 保证任务栏已驻留应用能够消失 的判断。

for (auto elementInfo : TaskManagerSettings::instance()->dockedElements()) {
auto pair = elementInfo.split('/');
if (pair.size() != 2)
continue;

auto type = pair[0];
auto id = pair[1];
auto type = pair[0];
auto id = pair[1];

auto tmp = std::make_tuple(type, id);
auto tmp = std::make_tuple(type, id);

// check desktop is installed
QAbstractItemModel *model = nullptr;
int row = 0;
if (type == "desktop") {
model = m_appsModel;
auto res = m_appsModel->match(m_appsModel->index(0, 0), TaskManager::DesktopIdRole, id, 1, Qt::MatchExactly).value(0);
if (!res.isValid())
continue;
row = res.row();
}
// check desktop is installed
QAbstractItemModel *model = nullptr;
int row = 0;
if (type == "desktop") {
model = m_appsModel;
auto res = m_appsModel->match(m_appsModel->index(0, 0), TaskManager::DesktopIdRole, id, 1, Qt::MatchExactly).value(0);
if (!res.isValid())
continue;
row = res.row();
}

newDocked.append(tmp);
if (m_dockedElements.contains(tmp))
continue;
newDocked.append(tmp);
if (m_dockedElements.contains(tmp))
continue;

auto isRunning = std::any_of(m_data.constBegin(), m_data.constEnd(), [this, &id](const auto &data) {
return std::get<0>(data) == id;
});
auto isRunning = std::any_of(m_data.constBegin(), m_data.constEnd(), [&id](const auto &data) {
return std::get<0>(data) == id;
});

if (!isRunning) {
beginInsertRows(QModelIndex(), m_data.size(), m_data.size());
m_data.append(std::make_tuple(id, model, row));
endInsertRows();
if (!isRunning) {
beginInsertRows(QModelIndex(), m_data.size(), m_data.size());
m_data.append(std::make_tuple(id, model, row));
endInsertRows();
}
}
}

Expand Down Expand Up @@ -342,8 +345,10 @@ QString DockGlobalElementModel::getMenus(const QModelIndex &index) const
menusArray.append(action);
}

bool isDocked = (model == nullptr) || m_dockedElements.contains(std::make_tuple("desktop", id));
menusArray.append(QJsonObject{{"id", DOCK_ACTION_DOCK}, {"name", isDocked ? tr("Undock") : tr("Dock")}});
if (TaskManagerSettings::instance()->dockedApplicationsEnabled()) {
bool isDocked = (model == nullptr) || m_dockedElements.contains(std::make_tuple("desktop", id));
menusArray.append(QJsonObject{{"id", DOCK_ACTION_DOCK}, {"name", isDocked ? tr("Undock") : tr("Dock")}});
}

if (model == m_activeAppModel) {
if (TaskManagerSettings::instance()->isAllowedForceQuit()) {
Expand Down
1 change: 1 addition & 0 deletions panels/dock/taskmanager/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static inline const QString TASKMANAGER_CGROUPS_BASED_GROUPING_SKIP_CATEGORIES =
static inline const QString TASKMANAGER_DOCKEDITEMS_KEY = "Docked_Items";
constexpr auto TASKMANAGER_DOCKEDELEMENTS_KEY = "dockedElements";
constexpr auto TASKMANAGER_WINDOW_ICON_WHITELIST_KEY = "windowIconWhitelist";
constexpr auto TASKMANAGER_ENABLE_DOCKED_APPLICATIONS_KEY = "enableDockedApplications";

// model roleNames
constexpr auto MODEL_WINID = "winId";
Expand Down
Loading
Loading