From 328454b85a19df080eba20e4952c2f6772e33fa1 Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Tue, 16 Jan 2024 15:45:47 +0800 Subject: [PATCH] fix: use timer to avoid window hide caused by switching mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 复用了现有的 timer 来避免在无混成时切换 launchpad 模式时失去焦点 导致的窗口隐藏。 Issue: https://github.com/linuxdeepin/developer-center/issues/6818 Log: --- launchercontroller.cpp | 6 ++++++ launchercontroller.h | 1 + qml/Main.qml | 8 +++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/launchercontroller.cpp b/launchercontroller.cpp index a6ad273a..52e9bf86 100644 --- a/launchercontroller.cpp +++ b/launchercontroller.cpp @@ -127,6 +127,7 @@ void LauncherController::setCurrentFrame(const QString &frame) settings.setValue("current_frame", frame); m_currentFrame = frame; + m_timer->start(); emit currentFrameChanged(); } @@ -141,3 +142,8 @@ void LauncherController::hideWithTimer() setVisible(false); } } + +bool LauncherController::shouldAvoidHideOrActive() +{ + return m_timer->isActive(); +} diff --git a/launchercontroller.h b/launchercontroller.h index c3c6dace..9835a119 100644 --- a/launchercontroller.h +++ b/launchercontroller.h @@ -35,6 +35,7 @@ class LauncherController : public QObject void setCurrentFrame(const QString & frame); Q_INVOKABLE void hideWithTimer(); + Q_INVOKABLE bool shouldAvoidHideOrActive(); signals: void currentFrameChanged(); diff --git a/qml/Main.qml b/qml/Main.qml index 16c8c145..83edbb17 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -137,7 +137,13 @@ QtObject { onActiveChanged: { if (!active && !DebugHelper.avoidHideWindow && (LauncherController.currentFrame === "WindowedFrame")) { - LauncherController.hideWithTimer() + // When composting is disabled, switching mode from fullscreen to windowed mode will cause window + // activeChanged signal get emitted. We reused the delay timer here to avoid the window get hide + // caused by that. + // Issue: https://github.com/linuxdeepin/developer-center/issues/6818 + if (!LauncherController.shouldAvoidHideOrActive()) { + LauncherController.hideWithTimer() + } } }