Skip to content

Commit 8683387

Browse files
Ivy233BLumia
authored andcommitted
fix: refactor dock position management and decouple from animation flow
1. Lift positionForAnimation from dockAnimation to dock Window level - Move property from SequentialAnimation to Window scope - Update all references from dockAnimation.positionForAnimation to dock.positionForAnimation - Improve code organization and semantic clarity 2. Remove m_beforePosition member variable and beforePosition() getter - Directly emit beforePositionChanged(SETTINGS->position()) in setPosition() - Eliminate unnecessary intermediate storage - Simplify code and reduce memory footprint 3. Position change flow improvements - C++ directly commits position changes via SETTINGS->setPosition() - Animation logic triggered by beforePositionChanged signal - No dependency on QML animation callbacks 修复:重构任务栏位置管理并与动画流程解耦 1. 将 positionForAnimation 从 dockAnimation 提升到 dock Window 级别 - 将属性从 SequentialAnimation 移至 Window 作用域 - 更新所有引用从 dockAnimation.positionForAnimation 改为 dock.positionForAnimation - 改善代码组织和语义清晰度 2. 移除 m_beforePosition 成员变量和 beforePosition() getter 函数 - 在 setPosition() 中直接发送 beforePositionChanged(SETTINGS->position()) - 消除不必要的中间存储 - 简化代码并减少内存占用 3. 位置变更流程改进 - C++ 直接通过 SETTINGS->setPosition() 提交位置变更 - 动画逻辑由 beforePositionChanged 信号触发 - 不依赖 QML 动画回调 PMS: BUG-346777
1 parent eacd145 commit 8683387

File tree

5 files changed

+96
-35
lines changed

5 files changed

+96
-35
lines changed

panels/dock/dockpanel.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ Position DockPanel::position()
262262

263263
void DockPanel::setPosition(const Position& position)
264264
{
265+
if (position == SETTINGS->position()) return;
266+
267+
// Emit signal with old position before updating
268+
Q_EMIT beforePositionChanged(SETTINGS->position());
269+
270+
// Directly commit the position change
265271
SETTINGS->setPosition(position);
266272
}
267273

panels/dock/dockpanel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ private Q_SLOTS:
119119

120120
void dockSizeChanged(uint size);
121121
void hideModeChanged(HideMode mode);
122+
void beforePositionChanged(Position beforePosition);
122123
void positionChanged(Position position);
123124
void itemAlignmentChanged(ItemAlignment alignment);
124125
void indicatorStyleChanged(IndicatorStyle style);

panels/dock/package/main.qml

Lines changed: 87 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import org.deepin.dtk.style 1.0 as DStyle
1717

1818
Window {
1919
id: dock
20-
property bool useColumnLayout: Applet.position % 2
20+
property int positionForAnimation: Panel.position
21+
property bool useColumnLayout: positionForAnimation % 2
2122
// TODO: 临时溢出逻辑,待后面修改
2223
property int dockLeftSpaceForCenter: useColumnLayout ?
2324
(Screen.height - dockLeftPart.implicitHeight - dockRightPart.implicitHeight) :
@@ -43,8 +44,8 @@ Window {
4344
property real dockItemIconSize: dockItemMaxSize * 9 / 14
4445

4546
// NOTE: -1 means not set its size, follow the platform size
46-
width: Panel.position === Dock.Top || Panel.position === Dock.Bottom ? -1 : dockSize
47-
height: Panel.position === Dock.Left || Panel.position === Dock.Right ? -1 : dockSize
47+
width: positionForAnimation === Dock.Top || positionForAnimation === Dock.Bottom ? -1 : dockSize
48+
height: positionForAnimation === Dock.Left || positionForAnimation === Dock.Right ? -1 : dockSize
4849
color: "transparent"
4950
flags: Qt.WindowDoesNotAcceptFocus
5051

@@ -55,7 +56,7 @@ Window {
5556
return appearance.opacity
5657
}
5758

58-
DLayerShellWindow.anchors: position2Anchors(Applet.position)
59+
DLayerShellWindow.anchors: position2Anchors(positionForAnimation)
5960
DLayerShellWindow.layer: DLayerShellWindow.LayerTop
6061
DLayerShellWindow.exclusionZone: Panel.hideMode === Dock.KeepShowing ? Applet.dockSize : 0
6162
DLayerShellWindow.scope: "dde-shell/dock"
@@ -102,7 +103,7 @@ Window {
102103
return dock.useColumnLayout ? "width" : "height";
103104
}
104105
to: {
105-
if (useTransformBasedAnimation) return Panel.hideState !== Dock.Hide ? 0 : ((Panel.position === Dock.Left || Panel.position === Dock.Top) ? -Panel.dockSize : Panel.dockSize);
106+
if (useTransformBasedAnimation) return Panel.hideState !== Dock.Hide ? 0 : ((dock.positionForAnimation === Dock.Left || dock.positionForAnimation === Dock.Top) ? -Panel.dockSize : Panel.dockSize);
106107
return Panel.hideState !== Dock.Hide ? Panel.dockSize : 1;
107108
}
108109
duration: 500
@@ -168,6 +169,7 @@ Window {
168169
id: dockAnimation
169170
property bool useTransformBasedAnimation: Qt.platform.pluginName === "xcb"
170171
property bool isShowing: false
172+
property bool isPositionChanging: false
171173
property var target: useTransformBasedAnimation ? dockTransform : dock
172174
property string animProperty: {
173175
if (useTransformBasedAnimation) return dock.useColumnLayout ? "x" : "y";
@@ -179,13 +181,29 @@ Window {
179181
start();
180182
}
181183

184+
function setTransformToHiddenPosition() {
185+
if (useTransformBasedAnimation) {
186+
var hideOffset = (Panel.position === Dock.Left || Panel.position === Dock.Top) ? -Panel.dockSize : Panel.dockSize;
187+
if (dock.useColumnLayout) {
188+
dockTransform.x = hideOffset;
189+
dockTransform.y = 0;
190+
} else {
191+
dockTransform.x = 0;
192+
dockTransform.y = hideOffset;
193+
}
194+
} else {
195+
dockTransform.x = 0;
196+
dockTransform.y = 0;
197+
}
198+
}
199+
182200
PropertyAnimation {
183201
target: dockAnimation.target
184202
property: dockAnimation.animProperty
185203
from: {
186204
if (dockAnimation.isShowing) {
187205
if (dockAnimation.useTransformBasedAnimation) {
188-
return (Panel.position === Dock.Left || Panel.position === Dock.Top) ? -Panel.dockSize : Panel.dockSize;
206+
return (dock.positionForAnimation === Dock.Left || dock.positionForAnimation === Dock.Top) ? -Panel.dockSize : Panel.dockSize;
189207
}
190208
return 1;
191209
}
@@ -196,7 +214,7 @@ Window {
196214
return 0;
197215
} else {
198216
if (dockAnimation.useTransformBasedAnimation) {
199-
return (Panel.position === Dock.Left || Panel.position === Dock.Top) ? -Panel.dockSize : Panel.dockSize;
217+
return (dock.positionForAnimation === Dock.Left || dock.positionForAnimation === Dock.Top) ? -Panel.dockSize : Panel.dockSize;
200218
}
201219
return 1;
202220
}
@@ -215,6 +233,28 @@ Window {
215233
} else {
216234
dock.visible = ((dock.useColumnLayout ? dock.width : dock.height) !== 1);
217235
}
236+
237+
// If this was a hide animation during position change, prepare for show animation
238+
if (isPositionChanging && !isShowing) {
239+
isPositionChanging = false;
240+
241+
// Update position for animation to new position for show animation
242+
dock.positionForAnimation = Panel.position;
243+
244+
// Set transform to hidden position before showing
245+
setTransformToHiddenPosition();
246+
247+
startAnimation(true);
248+
} else if (isShowing) {
249+
// After show animation completes, check if we need to auto-hide
250+
// For KeepHidden and SmartHide modes, trigger hide check immediately
251+
if (Panel.hideMode === Dock.KeepHidden || Panel.hideMode === Dock.SmartHide) {
252+
hideTimer.running = true;
253+
} else if (Panel.hideState === Dock.Hide) {
254+
// For other cases, if hideState is already Hide, trigger hide animation
255+
hideTimer.running = true;
256+
}
257+
}
218258
}
219259
}
220260

@@ -224,31 +264,9 @@ Window {
224264
required property int value
225265
text: name
226266

227-
property var positionChangeCallback: function() {
228-
// Disconnect any existing callback first
229-
dockAnimation.onStopped.disconnect(positionChangeCallback);
230-
// Stop any running animations first --fix bug with do not show dock
231-
dockAnimation.stop();
232-
// Reset transform before starting new animation--fix bug with change position,will have a blank area
233-
dockTransform.x = 0;
234-
dockTransform.y = 0;
235-
236-
Applet[prop] = value;
237-
checked = Qt.binding(function() {
238-
return Applet[prop] === value;
239-
});
240-
dockAnimation.startAnimation(true);
241-
}
242267
onTriggered: {
243-
if (prop === "position") {
244-
// Connect the callback and start the hide animation
245-
dockAnimation.onStopped.connect(positionChangeCallback);
246-
dockAnimation.startAnimation(false);
247-
} else {
268+
if (Applet[prop] !== value) {
248269
Applet[prop] = value
249-
checked = Qt.binding(function() {
250-
return Applet[prop] === value
251-
})
252270
}
253271
}
254272
checked: Applet[prop] === value
@@ -648,7 +666,7 @@ Window {
648666
}
649667

650668
function changeDragAreaAnchor() {
651-
switch(Panel.position) {
669+
switch(dock.positionForAnimation) {
652670
case Dock.Top: {
653671
dragArea.anchorToTop()
654672
return
@@ -669,9 +687,42 @@ Window {
669687
}
670688

671689
Connections {
690+
function onBeforePositionChanged(beforePosition) {
691+
// Stop any running animations first
692+
dockAnimation.stop();
693+
hideShowAnimation.stop();
694+
695+
// Set the position for animation to old position for hide animation
696+
dock.positionForAnimation = beforePosition;
697+
698+
// Mark that we're changing position
699+
dockAnimation.isPositionChanging = true;
700+
701+
// Check if dock is currently hidden
702+
if (Panel.hideState === Dock.Hide && !dock.visible) {
703+
// Dock is already hidden, no need for hide animation
704+
// Wait for onPositionChanged to get the new position, then show
705+
dockAnimation.isPositionChanging = false;
706+
} else {
707+
// Start hide animation at old position
708+
// When animation completes, onStopped will handle show animation
709+
dockAnimation.startAnimation(false);
710+
}
711+
}
712+
672713
function onPositionChanged() {
673714
changeDragAreaAnchor()
674715
Panel.requestClosePopup()
716+
717+
// If dock was hidden when position change started, show it now at new position
718+
if (!dockAnimation.isPositionChanging && !dock.visible) {
719+
dock.positionForAnimation = Panel.position;
720+
721+
// Set transform to hidden position before showing
722+
dockAnimation.setTransformToHiddenPosition();
723+
724+
dockAnimation.startAnimation(true);
725+
}
675726
}
676727
function onDockSizeChanged() {
677728
dock.dockSize = Panel.dockSize
@@ -681,7 +732,10 @@ Window {
681732
if (Panel.hideState === Dock.Hide) {
682733
hideTimer.running = true
683734
} else {
684-
hideShowAnimation.restart()
735+
// Only restart animation if not already running or if visible state doesn't match
736+
if (!hideShowAnimation.running || !dock.visible) {
737+
hideShowAnimation.restart()
738+
}
685739
}
686740
}
687741
function onRequestClosePopup() {
@@ -734,7 +788,7 @@ Window {
734788
})
735789

736790
DockCompositor.dockPosition = Qt.binding(function(){
737-
return Panel.position
791+
return dock.positionForAnimation
738792
})
739793

740794
DockCompositor.dockSize = Qt.binding(function(){

panels/dock/taskmanager/package/AppItem.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Item {
3737
Drag.dragType: Drag.Automatic
3838
Drag.mimeData: { "text/x-dde-dock-dnd-appid": itemId, "text/x-dde-dock-dnd-source": "taskbar", "text/x-dde-dock-dnd-winid": windows.length > 0 ? windows[0] : ""}
3939

40-
property bool useColumnLayout: Panel.position % 2
40+
property bool useColumnLayout: Panel.rootObject.useColumnLayout
4141
property int statusIndicatorSize: useColumnLayout ? root.width * 0.72 : root.height * 0.72
4242
property int iconSize: Panel.rootObject.dockItemMaxSize * 9 / 14
4343
property bool enableTitle: false

panels/dock/taskmanager/package/TaskManager.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.deepin.dtk 1.0 as D
1212

1313
ContainmentItem {
1414
id: taskmanager
15-
property bool useColumnLayout: Panel.position % 2
15+
property bool useColumnLayout: Panel.rootObject.useColumnLayout
1616
property int dockOrder: 16
1717
property real remainingSpacesForTaskManager: Panel.itemAlignment === Dock.LeftAlignment ? Panel.rootObject.dockLeftSpaceForCenter : Panel.rootObject.dockRemainingSpaceForCenter
1818

0 commit comments

Comments
 (0)