diff --git a/src/server/src/config/config.hpp b/src/server/src/config/config.hpp index e5f1171504..f80c05cac7 100644 --- a/src/server/src/config/config.hpp +++ b/src/server/src/config/config.hpp @@ -274,6 +274,8 @@ struct ConfigValue { bool closeOnFocusLoss = false; bool considerPreedit = false; bool popToRootOnClose = false; + // seconds; with popToRootOnClose, reopening within this window keeps the query/view stack + int popToRootOnCloseDelay = 0; bool popOnBackspace = true; bool activateOnSingleClick = false; #ifdef Q_OS_LINUX @@ -331,6 +333,7 @@ template <> struct Partial { std::optional closeOnFocusLoss; std::optional considerPreedit; std::optional popToRootOnClose; + std::optional popToRootOnCloseDelay; std::optional popOnBackspace; std::optional activateOnSingleClick; std::optional encryptSensitiveData; diff --git a/src/server/src/navigation-controller.cpp b/src/server/src/navigation-controller.cpp index 9f01cbe7d2..dcd18f4219 100644 --- a/src/server/src/navigation-controller.cpp +++ b/src/server/src/navigation-controller.cpp @@ -90,9 +90,16 @@ void NavigationController::showHud(const QString &title, const std::optional 0 && m_closedAt.isValid() && + m_closedAt.elapsed() < qint64(m_popToRootOnCloseDelay) * 1000; + auto resolveApplicablePopToRoot = [&]() { - if (settings.type == PopToRootType::Default) + if (settings.type == PopToRootType::Default) { + if (closedRecently) return PopToRootType::Suspended; return m_popToRootOnClose ? PopToRootType::Immediate : PopToRootType::Suspended; + } return settings.type; }; @@ -106,7 +113,7 @@ void NavigationController::applyPopToRoot(const PendingPopToRoot &settings) { break; } - if (isRootSearch() && settings.clearSearch) clearSearchText(); + if (isRootSearch() && settings.clearSearch && !closedRecently) clearSearchText(); } void NavigationController::setDialog(DialogContentWidget *widget) { @@ -312,6 +319,8 @@ QString NavigationController::navigationTitle(const BaseView *caller) const { void NavigationController::setPopToRootOnClose(bool value) { m_popToRootOnClose = value; } +void NavigationController::setPopToRootOnCloseDelay(int seconds) { m_popToRootOnCloseDelay = seconds; } + void NavigationController::closeWindow(const CloseWindowOptions &settings, std::chrono::milliseconds delay) { QTimer::singleShot(delay, [this, settings]() { closeWindow(settings); }); } @@ -328,6 +337,7 @@ void NavigationController::closeWindow(const CloseWindowOptions &settings) { } m_pendingPopToRoot = PendingPopToRoot{.type = type, .clearSearch = settings.clearRootSearch}; + m_closedAt.start(); m_windowOpened = false; emit windowVisiblityChanged(false); } diff --git a/src/server/src/navigation-controller.hpp b/src/server/src/navigation-controller.hpp index 9bf9f514c2..a9723014ac 100644 --- a/src/server/src/navigation-controller.hpp +++ b/src/server/src/navigation-controller.hpp @@ -9,6 +9,7 @@ #include "ui/action-pannel/action-panel-state.hpp" #include "ui/dialog/dialog.hpp" #include "ui/image/url.hpp" +#include #include #include #include @@ -144,6 +145,7 @@ class NavigationController : public QObject, NonCopyable { QWindow *window() const { return m_window; } void setPopToRootOnClose(bool value); + void setPopToRootOnCloseDelay(int seconds); bool hasCompleter() const; @@ -272,6 +274,8 @@ class NavigationController : public QObject, NonCopyable { bool m_windowActivated = false; bool m_isPanelOpened = false; bool m_popToRootOnClose = false; + int m_popToRootOnCloseDelay = 0; // seconds; > 0 keeps state when reopened within the delay + QElapsedTimer m_closedAt; bool m_instantDismiss = false; bool m_closeOnFocusLoss = false; QWindow *m_window = nullptr; diff --git a/src/server/src/server.cpp b/src/server/src/server.cpp index 2fe6a6a8a7..5cef033ab0 100644 --- a/src/server/src/server.cpp +++ b/src/server/src/server.cpp @@ -444,6 +444,7 @@ int startServer(const ServerLaunchOptions &launchOpts) { } ctx.navigation->setPopToRootOnClose(next.popToRootOnClose); + ctx.navigation->setPopToRootOnCloseDelay(next.popToRootOnCloseDelay); ctx.navigation->setCloseOnFocusLoss(next.closeOnFocusLoss); #ifdef Q_OS_LINUX ctx.services->inputServer()->setEnabled(next.inputServer.enabled);