Skip to content

Commit 97c2cbe

Browse files
committed
fix: prevent dragging items to fixed plugin section
Added validation to prevent drag and drop operations from targeting fixed plugin sections in the system tray. The changes include: 1. Implemented isForbiddenDropTarget function to check if drop target is a fixed section 2. Added drag event rejection when attempting to drop on fixed sections 3. Marked quick settings toggle as fixed section in the model 4. This prevents users from accidentally moving or reordering critical system components fix: 防止拖拽项目到固定插件区域 添加验证以防止拖放操作目标为系统托盘中的固定插件区域。更改包括: 1. 实现 isForbiddenDropTarget 函数检查拖放目标是否为固定区域 2. 在尝试拖放到固定区域时添加拖放事件拒绝 3. 在模型中标记快速设置切换为固定区域 4. 防止用户意外移动或重新排列关键系统组件 Pms: BUG-289447 BUG-289445
1 parent c06f1bc commit 97c2cbe

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

panels/dock/tray/package/TrayContainer.qml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ Item {
145145
property bool dragExited: false
146146
property string source: ""
147147
property string surfaceId: ""
148+
148149
onEntered: function (dragEvent) {
149150
dragExited = false
150151
isDropped = false
@@ -161,11 +162,19 @@ Item {
161162
onPositionChanged: function (dragEvent) {
162163
let surfaceId = dragEvent.getDataAsString("text/x-dde-shell-tray-dnd-surfaceId")
163164
let pos = root.isHorizontal ? drag.x : drag.y
164-
let currentItemIndex = pos / (root.itemVisualSize + root.itemSpacing)
165-
let currentPosMapToItem = pos % (root.itemVisualSize + root.itemSpacing)
166-
let isBefore = currentPosMapToItem < root.itemVisualSize / 2
167-
dropHoverIndex = Math.floor(currentItemIndex)
165+
let dropIdx = DDT.TrayItemPositionManager.itemIndexByPoint(Qt.point(drag.x, drag.y))
166+
let currentItemIndex = dropIdx.index
167+
let isBefore = dropIdx.isBefore
168168
let isStash = dragEvent.getDataAsString("text/x-dde-shell-tray-dnd-sectionType") === "stashed"
169+
dropHoverIndex = dropIdx.index
170+
171+
// 检查当前悬停位置是否是禁止拖拽的插件
172+
let modelIndex = DDT.TraySortOrderModel.getModelIndexByVisualIndex(currentItemIndex)
173+
let sectionType =root.model.data(modelIndex, DDT.TraySortOrderModel.SectionTypeRole)
174+
if (sectionType === "fixed") {
175+
dragEvent.accepted = false
176+
return
177+
}
169178

170179
// 检查 ActionShowStashDelegate 是否显示
171180
let showStashActionVisible = false

panels/dock/tray/traysortordermodel.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <QDBusConnection>
1111

1212
#include <DConfig>
13+
#include <qabstractitemmodel.h>
1314

1415
namespace docktray {
1516

@@ -428,6 +429,7 @@ void TraySortOrderModel::updateVisualIndexes()
428429
// "internal/action-toggle-quick-settings"
429430
results = findItems("internal/action-toggle-quick-settings");
430431
Q_ASSERT(!results.isEmpty());
432+
results[0]->setData(SECTION_FIXED, TraySortOrderModel::SectionTypeRole);
431433
results[0]->setData(currentVisualIndex, TraySortOrderModel::VisualIndexRole);
432434
currentVisualIndex++;
433435

@@ -551,4 +553,18 @@ void TraySortOrderModel::handlePluginVisibleChanged(const QString &surfaceId, bo
551553
}
552554
}
553555

556+
QModelIndex TraySortOrderModel::getModelIndexByVisualIndex(int visualIndex) const
557+
{
558+
for (int i = 0; i < rowCount(); i++) {
559+
QModelIndex index = this->index(i, 0);
560+
int itemVisualIndex = data(index, VisualIndexRole).toInt();
561+
bool visibility = data(index, VisibilityRole).toBool();
562+
563+
if (visibility && itemVisualIndex == visualIndex) {
564+
return index;
565+
}
566+
}
567+
return QModelIndex();
568+
}
569+
554570
}

panels/dock/tray/traysortordermodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class TraySortOrderModel : public QStandardItemModel
6363
Q_INVOKABLE bool dropToDockTray(const QString & draggedSurfaceId, int dropVisualIndex, bool isBefore);
6464
Q_INVOKABLE void setSurfaceVisible(const QString & surfaceId, bool visible);
6565
Q_INVOKABLE bool isDisplayedSurface(const QString &surfaceId) const;
66+
Q_INVOKABLE QModelIndex getModelIndexByVisualIndex(int visualIndex) const;
6667

6768
signals:
6869
void collapsedChanged(bool);

0 commit comments

Comments
 (0)