Skip to content

Commit

Permalink
fix: wrong position when screen changed
Browse files Browse the repository at this point in the history
  We add listening to refresh dde-widgets when screen changed.

Issue: linuxdeepin/developer-center#6867
  • Loading branch information
18202781743 committed Jan 17, 2024
1 parent fd042d4 commit 0cf4fc5
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
15 changes: 15 additions & 0 deletions app/mainview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void MainView::init()
m_displayModeView->init();

connect(m_animationContainer, &AnimationViewContainer::outsideAreaReleased, this, &MainView::hideView);
QObject::connect(m_geometryHandler, &GeometryHandler::geometryChanged, this, &MainView::refreshShownView);
}

MainView::Mode MainView::displayMode() const
Expand Down Expand Up @@ -182,4 +183,18 @@ int MainView::expectedWidth() const
{
return m_mode == Edit ? UI::EditMode::width : UI::DisMode::width;
}

void MainView::refreshShownView()
{
if (!isVisible())
return;

if (m_mode == Display) {
switchToDisplayMode();
} else {
switchToEditMode();
}
m_animationContainer->refreshView();
}

WIDGETS_FRAME_END_NAMESPACE
2 changes: 2 additions & 0 deletions app/mainview.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public Q_SLOTS:

private:
int expectedWidth() const;
private Q_SLOTS:
void refreshShownView();
private:
WidgetManager *m_manager = nullptr;
WidgetStore *m_storeView;
Expand Down
15 changes: 13 additions & 2 deletions app/utils/animationviewcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,22 @@ void AnimationViewContainer::hideView()
connect(m_currentXAni, &QPropertyAnimation::finished, this, &AnimationViewContainer::hide, Qt::UniqueConnection);
}

void AnimationViewContainer::refreshView()
{
if (m_currentXAni && m_currentXAni->state() == QAbstractAnimation::Running) {
m_currentXAni->stop();
}
if (isVisible()) {
showView();
} else {
hideView();
}
}

void AnimationViewContainer::updateGeometry(const QRect &rect)
{
m_currRect = geometry();
m_targetRect = rect;
qDebug() << "updateGeometry:" << m_currRect << m_targetRect;
qDebug() << "updateGeometry:" << geometry() << m_targetRect;
}

int AnimationViewContainer::currentX() const
Expand Down
2 changes: 1 addition & 1 deletion app/utils/animationviewcontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AnimationViewContainer : public DBlurEffectWidget

void showView();
void hideView();
void refreshView();
void updateGeometry(const QRect &rect);

Q_SIGNALS:
Expand All @@ -38,7 +39,6 @@ private Q_SLOTS:
void unRegisterRegion();

private:
QRect m_currRect;
QRect m_targetRect;
QPropertyAnimation *m_currentXAni = nullptr;
DRegionMonitor *m_regionMonitor = nullptr;
Expand Down
4 changes: 4 additions & 0 deletions app/utils/geometryhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ GeometryHandler::GeometryHandler(QObject *parent)
QDBusConnection::sessionBus(), this);
m_dockDeamonInter = new DockInter(DockDaemonDBusServie, DockDaemonDBusPath,
QDBusConnection::sessionBus(), this);
QObject::connect(m_displayInter, &DisplayInter::PrimaryRectChanged, this, &GeometryHandler::geometryChanged, Qt::UniqueConnection);
}

GeometryHandler::~GeometryHandler()
Expand Down Expand Up @@ -112,6 +113,9 @@ QRect GeometryHandler::calcDisplayRect(const QRect &dockRect)
{
qreal ratio = qApp->primaryScreen()->devicePixelRatio();
QRect displayRect = m_displayInter->primaryRect();
displayRect = QRect(displayRect.x(), displayRect.y(),
displayRect.width() / ratio, displayRect.height() / ratio);

QList<QDBusObjectPath> screenList = m_displayInter->monitors();

for (const auto &screen : screenList) {
Expand Down
3 changes: 3 additions & 0 deletions app/utils/geometryhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class GeometryHandler : public QObject {
QRect getGeometry(const int expectedWidth, const bool reduceDockHeight = false);

QRect calcDisplayRect(const QRect &dockRect);

Q_SIGNALS:
void geometryChanged();
private:
DisplayInter *m_displayInter = nullptr;
DockInter *m_dockDeamonInter = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion app/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool releaseMode()
{
static bool on = qEnvironmentVariableIsSet("DDE_WIDGETS_DBUG_MODE");
if (on)
return true;
return qEnvironmentVariableIntValue("DDE_WIDGETS_DBUG_MODE") <= 0;

#if (defined QT_DEBUG)
return false;
Expand Down

0 comments on commit 0cf4fc5

Please sign in to comment.