Skip to content

Commit acfbd97

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 acfbd97

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

panels/dock/tray/package/TrayContainer.qml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ Item {
145145
property bool dragExited: false
146146
property string source: ""
147147
property string surfaceId: ""
148+
149+
// 检查是否是禁止拖拽的插件
150+
function isForbiddenDropTarget(mouseX, mouseY) {
151+
let dropIdx = DDT.TrayItemPositionManager.itemIndexByPoint(Qt.point(mouseX, mouseY))
152+
let visualIndex = dropIdx.index
153+
154+
let sectionType = DDT.TraySortOrderModel.getSectionTypeByVisualIndex(visualIndex)
155+
if (sectionType === "fixed") {
156+
return true
157+
}
158+
return false
159+
}
160+
148161
onEntered: function (dragEvent) {
149162
dragExited = false
150163
isDropped = false
@@ -167,6 +180,12 @@ Item {
167180
dropHoverIndex = Math.floor(currentItemIndex)
168181
let isStash = dragEvent.getDataAsString("text/x-dde-shell-tray-dnd-sectionType") === "stashed"
169182

183+
// 检查当前悬停位置是否是禁止拖拽的插件
184+
if (isForbiddenDropTarget(drag.x, drag.y)) {
185+
dragEvent.accepted = false
186+
return
187+
}
188+
170189
// 检查 ActionShowStashDelegate 是否显示
171190
let showStashActionVisible = false
172191
for (let i = 0; i < root.model.rowCount(); i++) {

panels/dock/tray/traysortordermodel.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ void TraySortOrderModel::updateVisualIndexes()
428428
// "internal/action-toggle-quick-settings"
429429
results = findItems("internal/action-toggle-quick-settings");
430430
Q_ASSERT(!results.isEmpty());
431+
results[0]->setData(SECTION_FIXED, TraySortOrderModel::SectionTypeRole);
431432
results[0]->setData(currentVisualIndex, TraySortOrderModel::VisualIndexRole);
432433
currentVisualIndex++;
433434

@@ -551,4 +552,19 @@ void TraySortOrderModel::handlePluginVisibleChanged(const QString &surfaceId, bo
551552
}
552553
}
553554

555+
QString TraySortOrderModel::getSectionTypeByVisualIndex(int visualIndex) const
556+
{
557+
for (int i = 0; i < rowCount(); i++) {
558+
QModelIndex index = this->index(i, 0);
559+
int itemVisualIndex = data(index, VisualIndexRole).toInt();
560+
bool visibility = data(index, VisibilityRole).toBool();
561+
562+
if (visibility && itemVisualIndex == visualIndex) {
563+
return data(index, SectionTypeRole).toString();
564+
}
565+
}
566+
567+
return QString(); // 未找到对应项目
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 QString getSectionTypeByVisualIndex(int visualIndex) const;
6667

6768
signals:
6869
void collapsedChanged(bool);

0 commit comments

Comments
 (0)