Skip to content

Commit

Permalink
fix: position jitter between two presentations
Browse files Browse the repository at this point in the history
In first presentation, there is no distance to dock. But the second
presentation will bring a spacing to Dock. Always add a spacing to
Dock.

Log: fix position jitter between two presentations
Issue: linuxdeepin/developer-center#6733
Depends: linuxdeepin/dde-dock#956
  • Loading branch information
asterwyx committed Jan 12, 2024
1 parent eaab8be commit cc4cd2e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
6 changes: 6 additions & 0 deletions desktopintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ QRect DesktopIntegration::dockGeometry() const
return m_dockIntegration->geometry();
}

uint DesktopIntegration::dockSpacing() const
{
return m_dockIntegration->windowMargin();
}

QString DesktopIntegration::backgroundUrl() const
{
return QString("image://blurhash/%1").arg(m_appearanceIntegration->wallpaperBlurhash());
Expand Down Expand Up @@ -219,5 +224,6 @@ DesktopIntegration::DesktopIntegration(QObject *parent)
{
connect(m_dockIntegration, &DdeDock::directionChanged, this, &DesktopIntegration::dockPositionChanged);
connect(m_dockIntegration, &DdeDock::geometryChanged, this, &DesktopIntegration::dockGeometryChanged);
connect(m_dockIntegration, &DdeDock::windowMarginChanged, this, &DesktopIntegration::dockSpacingChanged);
connect(m_appearanceIntegration, &Appearance::wallpaperBlurhashChanged, this, &DesktopIntegration::backgroundUrlChanged);
}
3 changes: 3 additions & 0 deletions desktopintegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class DesktopIntegration : public QObject

Q_PROPERTY(Qt::ArrowType dockPosition READ dockPosition NOTIFY dockPositionChanged)
Q_PROPERTY(QRect dockGeometry READ dockGeometry NOTIFY dockGeometryChanged)
Q_PROPERTY(uint dockSpacing READ dockSpacing NOTIFY dockSpacingChanged)
Q_PROPERTY(QString backgroundUrl READ backgroundUrl NOTIFY backgroundUrlChanged)

public:
Expand All @@ -34,6 +35,7 @@ class DesktopIntegration : public QObject

Qt::ArrowType dockPosition() const;
QRect dockGeometry() const;
uint dockSpacing() const;
QString backgroundUrl() const;

Q_INVOKABLE bool isDockedApp(const QString & desktopId) const;
Expand All @@ -49,6 +51,7 @@ class DesktopIntegration : public QObject
signals:
void dockPositionChanged();
void dockGeometryChanged();
void dockSpacingChanged();
void backgroundUrlChanged();

private:
Expand Down
8 changes: 4 additions & 4 deletions qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ QtObject {
switch (DesktopIntegration.dockPosition) {
case Qt.DownArrow:
x = dockGeometry.left
y = (dockGeometry.top >= 0 ? dockGeometry.top : (Screen.height - dockGeometry.height)) - height
y = (dockGeometry.top >= 0 ? dockGeometry.top : (Screen.height - dockGeometry.height)) - height - DesktopIntegration.dockSpacing
break
case Qt.LeftArrow:
x = dockGeometry.width
x = dockGeometry.right + DesktopIntegration.dockSpacing
y = (dockGeometry.top >= 0 ? dockGeometry.top : 0)
break
case Qt.UpArrow:
x = dockGeometry.left
y = dockGeometry.height
y = dockGeometry.bottom + DesktopIntegration.dockSpacing
break
case Qt.RightArrow:
x = (dockGeometry.left >= 0 ? dockGeometry.left : (Screen.width - dockGeometry.width)) - width
x = (dockGeometry.left >= 0 ? dockGeometry.left : (Screen.width - dockGeometry.width)) - width - DesktopIntegration.dockSpacing
y = dockGeometry.top
break
}
Expand Down
14 changes: 14 additions & 0 deletions src/ddeintegration/ddedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ DdeDock::DdeDock(QObject *parent)
QDBusConnection::sessionBus(), this))
, m_direction(Qt::DownArrow)
, m_rect(QRect(-1, -1, 0, 0))
, m_windowMargin(0)
{
QTimer::singleShot(0, this, &DdeDock::updateDockRectAndPositionFromDBus);
QMetaObject::invokeMethod(this, &DdeDock::updateDockWindowMarginFromDBus, Qt::QueuedConnection);

// Due to current dde-dock bug, we need to do both since position changed signal might not got emit in some case.
connect(m_dbusDaemonDockIface, &Dock1::PositionChanged, this, &DdeDock::updateDockRectAndPositionFromDBus);
connect(m_dbusDaemonDockIface, &Dock1::FrontendWindowRectChanged, this, &DdeDock::updateDockRectAndPositionFromDBus);
connect(m_dbusDaemonDockIface, &Dock1::WindowMarginChanged, this, &DdeDock::updateDockWindowMarginFromDBus);
}

DdeDock::~DdeDock()
Expand All @@ -39,6 +42,11 @@ QRect DdeDock::geometry() const
return m_rect;
}

uint DdeDock::windowMargin() const
{
return m_windowMargin;
}

bool DdeDock::isDocked(const QString &desktop) const
{
QDBusPendingReply<bool> reply(m_dbusDaemonDockIface->IsDocked(desktop));
Expand Down Expand Up @@ -99,6 +107,12 @@ void DdeDock::updateDockPositionFromDBus()
}
}

void DdeDock::updateDockWindowMarginFromDBus()
{
m_windowMargin = m_dbusDaemonDockIface->windowMargin();
emit windowMarginChanged();
}

void DdeDock::updateDockRectFromDBus()
{
m_rect = m_dbusDaemonDockIface->frontendWindowRect();
Expand Down
5 changes: 5 additions & 0 deletions src/ddeintegration/ddedock.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class DdeDock : public QObject

Q_PROPERTY(Qt::ArrowType direction READ direction NOTIFY directionChanged)
Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged)
Q_PROPERTY(uint windowMargin READ windowMargin NOTIFY windowMarginChanged)

public:
explicit DdeDock(QObject *parent = nullptr);
~DdeDock();

Qt::ArrowType direction() const;
QRect geometry() const;
uint windowMargin() const;

bool isDocked(const QString & desktop) const;
void sendToDock(const QString & desktop, int idx = -1);
Expand All @@ -29,14 +31,17 @@ class DdeDock : public QObject
signals:
void directionChanged();
void geometryChanged();
void windowMarginChanged();

private:
void updateDockRectAndPositionFromDBus();
void updateDockPositionFromDBus();
void updateDockWindowMarginFromDBus();
void updateDockRectFromDBus();

__Dock1 * m_dbusDaemonDockIface;

Qt::ArrowType m_direction;
QRect m_rect;
uint m_windowMargin;
};
1 change: 1 addition & 0 deletions src/ddeintegration/xml/org.deepin.dde.daemon.Dock1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<property name="WindowSize" type="u" access="readwrite"/>
<property name="WindowSizeEfficient" type="u" access="readwrite"/>
<property name="WindowSizeFashion" type="u" access="readwrite"/>
<property name="WindowMargin" type="u" access="read"/>
<property name="ShowTimeout" type="u" access="readwrite"/>
<property name="HideTimeout" type="u" access="readwrite"/>
<property name="DockedApps" type="as" access="read"/>
Expand Down

0 comments on commit cc4cd2e

Please sign in to comment.