Skip to content
Open
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
21 changes: 20 additions & 1 deletion panels/dock/dockpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ DockPanel::DockPanel(QObject *parent)
, m_launcherShown(false)
, m_contextDragging(false)
, m_isResizing(false)
, m_pendingPosition(Bottom)
, m_hasPendingPosition(false)
{
connect(this, &DockPanel::compositorReadyChanged, this, [this] {
if (!m_compositorReady) return;
Expand Down Expand Up @@ -262,7 +264,14 @@ Position DockPanel::position()

void DockPanel::setPosition(const Position& position)
{
SETTINGS->setPosition(position);
if (position == SETTINGS->position()) return;

m_pendingPosition = position;
m_hasPendingPosition = true;

// Emit beforePositionChanged to let QML play hide animation
Position oldPosition = SETTINGS->position();
Q_EMIT beforePositionChanged(oldPosition, position);
}

ItemAlignment DockPanel::itemAlignment()
Expand Down Expand Up @@ -350,6 +359,16 @@ void DockPanel::notifyDockPositionChanged(int offsetX, int offsetY)
Q_EMIT frontendWindowRectChanged(frontendWindowRect(offsetX, offsetY));
}

void DockPanel::commitPositionChange()
{
if (!m_hasPendingPosition) {
return;
}

m_hasPendingPosition = false;
SETTINGS->setPosition(m_pendingPosition);
}

void DockPanel::launcherVisibleChanged(bool visible)
{
if (visible == m_launcherShown) return;
Expand Down
5 changes: 5 additions & 0 deletions panels/dock/dockpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class DockPanel : public DS_NAMESPACE::DPanel, public QDBusContext

Q_INVOKABLE void notifyDockPositionChanged(int offsetX, int offsetY);

Q_INVOKABLE void commitPositionChange();

bool showInPrimary() const;
void setShowInPrimary(bool newShowInPrimary);

Expand Down Expand Up @@ -119,6 +121,7 @@ private Q_SLOTS:

void dockSizeChanged(uint size);
void hideModeChanged(HideMode mode);
void beforePositionChanged(Position oldPosition, Position newPosition);
void positionChanged(Position position);
void itemAlignmentChanged(ItemAlignment alignment);
void indicatorStyleChanged(IndicatorStyle style);
Expand All @@ -142,6 +145,8 @@ private Q_SLOTS:
bool m_launcherShown;
bool m_contextDragging;
bool m_isResizing;
Position m_pendingPosition;
bool m_hasPendingPosition;
};

}
1 change: 1 addition & 0 deletions panels/dock/docksettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class DockSettings : public QObject
Q_SIGNALS:
void dockSizeChanged(uint size);
void hideModeChanged(HideMode mode);
void beforePositionChanged(Position oldPosition, Position newPosition);
void positionChanged(Position position);
void itemAlignmentChanged(ItemAlignment alignment);
void indicatorStyleChanged(IndicatorStyle style);
Expand Down
108 changes: 83 additions & 25 deletions panels/dock/package/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,22 @@ Window {
}
}

Timer {
Copy link
Contributor

Choose a reason for hiding this comment

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

这个定时器能否去掉,如果真需要,dde-shell有个DS.singleshot定时执行一次的接口,
c++里数据被调用了setPosition之后,不应该依赖界面来驱动这个流程,不管有没有动画,它都应该执行下去,我们能不能将隐藏显示的动画,补充到另一个流程里,而不是直接嵌入到setPosition,影响这个流程,
如果真需要beforePosition这个值,可以在panel里加一个,类似张坤提的禁用动画的pr,

id: positionChangeFallbackTimer
interval: 1000
running: false
repeat: false
onTriggered: {
Panel.commitPositionChange();
}
}

SequentialAnimation {
id: dockAnimation
property bool useTransformBasedAnimation: Qt.platform.pluginName === "xcb"
property bool isShowing: false
property bool isPositionChanging: false
property int positionForAnimation: Panel.position
property var target: useTransformBasedAnimation ? dockTransform : dock
property string animProperty: {
if (useTransformBasedAnimation) return dock.useColumnLayout ? "x" : "y";
Expand All @@ -185,7 +197,7 @@ Window {
from: {
if (dockAnimation.isShowing) {
if (dockAnimation.useTransformBasedAnimation) {
return (Panel.position === Dock.Left || Panel.position === Dock.Top) ? -Panel.dockSize : Panel.dockSize;
return (dockAnimation.positionForAnimation === Dock.Left || dockAnimation.positionForAnimation === Dock.Top) ? -Panel.dockSize : Panel.dockSize;
}
return 1;
}
Expand All @@ -196,7 +208,7 @@ Window {
return 0;
} else {
if (dockAnimation.useTransformBasedAnimation) {
return (Panel.position === Dock.Left || Panel.position === Dock.Top) ? -Panel.dockSize : Panel.dockSize;
return (dockAnimation.positionForAnimation === Dock.Left || dockAnimation.positionForAnimation === Dock.Top) ? -Panel.dockSize : Panel.dockSize;
}
return 1;
}
Expand All @@ -215,6 +227,21 @@ Window {
} else {
dock.visible = ((dock.useColumnLayout ? dock.width : dock.height) !== 1);
}

// If this was a hide animation during position change, commit the position change
if (isPositionChanging && !isShowing) {
isPositionChanging = false;
Panel.commitPositionChange();
} else if (isShowing) {
// After show animation completes, check if we need to auto-hide
// For KeepHidden and SmartHide modes, trigger hide check immediately
if (Panel.hideMode === Dock.KeepHidden || Panel.hideMode === Dock.SmartHide) {
hideTimer.running = true;
} else if (Panel.hideState === Dock.Hide) {
// For other cases, if hideState is already Hide, trigger hide animation
hideTimer.running = true;
}
}
}
}

Expand All @@ -224,31 +251,9 @@ Window {
required property int value
text: name

property var positionChangeCallback: function() {
// Disconnect any existing callback first
dockAnimation.onStopped.disconnect(positionChangeCallback);
// Stop any running animations first --fix bug with do not show dock
dockAnimation.stop();
// Reset transform before starting new animation--fix bug with change position,will have a blank area
dockTransform.x = 0;
dockTransform.y = 0;

Applet[prop] = value;
checked = Qt.binding(function() {
return Applet[prop] === value;
});
dockAnimation.startAnimation(true);
}
onTriggered: {
if (prop === "position") {
// Connect the callback and start the hide animation
dockAnimation.onStopped.connect(positionChangeCallback);
dockAnimation.startAnimation(false);
} else {
if (Applet[prop] !== value) {
Applet[prop] = value
checked = Qt.binding(function() {
return Applet[prop] === value
})
}
}
checked: Applet[prop] === value
Expand Down Expand Up @@ -669,9 +674,62 @@ Window {
}

Connections {
function onBeforePositionChanged(oldPosition, newPosition) {
// Stop any running animations first
dockAnimation.stop();
hideShowAnimation.stop();

// Set the position for animation to old position for hide animation
dockAnimation.positionForAnimation = oldPosition;

// Mark that we're changing position
dockAnimation.isPositionChanging = true;

// Check if dock is currently hidden
if (Panel.hideState === Dock.Hide && !dock.visible) {
// Dock is already hidden, no need for hide animation
dockAnimation.isPositionChanging = false;
Panel.commitPositionChange();
// No need for fallback timer since we committed immediately
} else {
// Start hide animation at old position
dockAnimation.startAnimation(false);
// Start fallback timer to ensure position change is committed
positionChangeFallbackTimer.restart();
}
}

function onPositionChanged() {
// Stop fallback timer since position has been committed
positionChangeFallbackTimer.stop();

changeDragAreaAnchor()
Panel.requestClosePopup()

// Start show animation at new position
handlePositionChangeAfterHide();
}

function handlePositionChangeAfterHide() {
// Update position for animation to new position for show animation
dockAnimation.positionForAnimation = Panel.position;

// Set transform to hidden position before showing
if (dockAnimation.useTransformBasedAnimation) {
var hideOffset = (Applet.position === Dock.Left || Applet.position === Dock.Top) ? -Panel.dockSize : Panel.dockSize;
if (dock.useColumnLayout) {
dockTransform.x = hideOffset;
dockTransform.y = 0;
} else {
dockTransform.x = 0;
dockTransform.y = hideOffset;
}
} else {
dockTransform.x = 0;
dockTransform.y = 0;
}

dockAnimation.startAnimation(true);
}
function onDockSizeChanged() {
dock.dockSize = Panel.dockSize
Expand Down