Skip to content

Commit 9044411

Browse files
committed
chore: drag out from dock to remove icon
将应用图标拖出任务栏时,即取消固定。 PMS: BUG-284079 BUG-288773 Log:
1 parent f204b7a commit 9044411

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

panels/dock/taskmanager/package/AppItem.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Item {
3131
Drag.hotSpot.x: icon.width / 2
3232
Drag.hotSpot.y: icon.height / 2
3333
Drag.dragType: Drag.Automatic
34-
Drag.mimeData: { "text/x-dde-dock-dnd-appid": itemId }
34+
Drag.mimeData: { "text/x-dde-dock-dnd-appid": itemId, "text/x-dde-dock-dnd-source": "taskbar" }
3535

3636
property bool useColumnLayout: Panel.position % 2
3737
property int statusIndicatorSize: useColumnLayout ? root.width * 0.72 : root.height * 0.72
@@ -72,7 +72,7 @@ Item {
7272

7373
WindowIndicator {
7474
id: windowIndicator
75-
dotWidth: root.useColumnLayout ? Math.max(Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE * iconScale / 16, 2) : Math.max(Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE * iconScale / 3, 2)
75+
dotWidth: root.useColumnLayout ? Math.max(Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE * iconScale / 16, 2) : Math.max(Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE * iconScale / 3, 2)
7676
dotHeight: root.useColumnLayout ? Math.max(Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE * iconScale / 3, 2) : Math.max(Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE * iconScale / 16, 2)
7777
windows: root.windows
7878
displayMode: root.displayMode

panels/dock/taskmanager/package/TaskManager.qml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ContainmentItem {
5959
required property list<string> windows
6060
keys: ["text/x-dde-dock-dnd-appid"]
6161
z: attention ? -1 : 0
62-
property bool visibility: itemId !== launcherDndDropArea.launcherDndDesktopId
62+
property bool visibility: itemId !== taskmanager.Applet.desktopIdToAppId(launcherDndDropArea.launcherDndDesktopId)
6363

6464
states: [
6565
State {
@@ -100,13 +100,12 @@ ContainmentItem {
100100
menus: delegateRoot.menus
101101
windows: delegateRoot.windows
102102
visualIndex: delegateRoot.visualIndex
103+
ListView.delayRemove: Drag.active
103104
Component.onCompleted: {
104105
clickItem.connect(taskmanager.Applet.clickItem)
105106
}
106-
107107
onDragFinished: function() {
108-
// 就算在非法区域松开也更新 Model
109-
taskmanager.Applet.dataModel.moveTo(itemId, visualIndex)
108+
launcherDndDropArea.resetDndState()
110109
}
111110
anchors.fill: parent // This is mandatory for draggable item center in drop area
112111
}
@@ -118,11 +117,19 @@ ContainmentItem {
118117
anchors.fill: parent
119118
keys: ["text/x-dde-dock-dnd-appid"]
120119
property string launcherDndDesktopId: ""
120+
property string launcherDndDragSource: ""
121+
122+
function resetDndState() {
123+
launcherDndDesktopId = ""
124+
launcherDndDragSource = ""
125+
}
126+
121127
onEntered: function(drag) {
122128
let desktopId = drag.getDataAsString("text/x-dde-dock-dnd-appid")
123-
launcherDndDesktopId = taskmanager.Applet.desktopIdToAppId(desktopId)
129+
launcherDndDragSource = drag.getDataAsString("text/x-dde-dock-dnd-source")
130+
launcherDndDesktopId = desktopId
124131
if (taskmanager.Applet.requestDockByDesktopId(desktopId) === false) {
125-
launcherDndDesktopId = ""
132+
resetDndState()
126133
}
127134
}
128135

@@ -133,7 +140,8 @@ ContainmentItem {
133140
let cellWidth = Panel.rootObject.dockItemMaxSize
134141
let curCell = curX / cellWidth
135142
let left = (curX % cellWidth) < (cellWidth / 2)
136-
taskmanager.Applet.dataModel.moveTo(launcherDndDesktopId, curCell)
143+
let appId = taskmanager.Applet.desktopIdToAppId(launcherDndDesktopId)
144+
taskmanager.Applet.dataModel.moveTo(appId, curCell)
137145
}
138146

139147
onDropped: function(drop) {
@@ -143,12 +151,16 @@ ContainmentItem {
143151
let cellWidth = Panel.rootObject.dockItemMaxSize
144152
let curCell = curX / cellWidth
145153
let left = (curX % cellWidth) < (cellWidth / 2)
146-
taskmanager.Applet.dataModel.moveTo(launcherDndDesktopId, curCell)
147-
launcherDndDesktopId = ""
154+
let appId = taskmanager.Applet.desktopIdToAppId(launcherDndDesktopId)
155+
taskmanager.Applet.dataModel.moveTo(appId, curCell)
156+
resetDndState()
148157
}
149158

150159
onExited: function() {
151-
launcherDndDesktopId = ""
160+
if (launcherDndDesktopId !== "" && launcherDndDragSource !== "taskbar") {
161+
taskmanager.Applet.requestUndockByDesktopId(launcherDndDesktopId)
162+
}
163+
resetDndState()
152164
}
153165
}
154166
}

panels/dock/taskmanager/taskmanager.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,16 @@ QString TaskManager::desktopIdToAppId(const QString& desktopId)
241241
return Q_LIKELY(desktopId.endsWith(".desktop")) ? desktopId.chopped(8) : desktopId;
242242
}
243243

244-
bool TaskManager::requestDockByDesktopId(const QString& appID)
244+
bool TaskManager::requestDockByDesktopId(const QString& desktopID)
245245
{
246-
if (appID.startsWith("internal/")) return false;
247-
return RequestDock(desktopIdToAppId(appID));
246+
if (desktopID.startsWith("internal/")) return false;
247+
return RequestDock(desktopIdToAppId(desktopID));
248+
}
249+
250+
bool TaskManager::requestUndockByDesktopId(const QString& desktopID)
251+
{
252+
if (desktopID.startsWith("internal/")) return false;
253+
return RequestUndock(desktopIdToAppId(desktopID));
248254
}
249255

250256
bool TaskManager::RequestDock(QString appID)

panels/dock/taskmanager/taskmanager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class TaskManager : public DS_NAMESPACE::DContainment
3737
bool allowForceQuit();
3838

3939
Q_INVOKABLE QString desktopIdToAppId(const QString& desktopId);
40-
Q_INVOKABLE bool requestDockByDesktopId(const QString& appID);
40+
Q_INVOKABLE bool requestDockByDesktopId(const QString& desktopID);
41+
Q_INVOKABLE bool requestUndockByDesktopId(const QString& desktopID);
4142
Q_INVOKABLE bool RequestDock(QString appID);
4243
Q_INVOKABLE bool IsDocked(QString appID);
4344
Q_INVOKABLE bool RequestUndock(QString appID);

0 commit comments

Comments
 (0)