From 173794ce15620aa0c673464f532cfd67f55ab278 Mon Sep 17 00:00:00 2001 From: Sergey Katunin Date: Fri, 24 Apr 2026 22:24:47 +0300 Subject: Restore session if this is the first instance 1. Restore session if this is the first instance even with "new-window" option. Otherwise, if Dolphin has not been opened before, and a program (such as browsers or Kate) that launch Dolphin with "new-window" option will start Dolphin, it opens only with one tab and closes the user's previous session. With this patch, the behavior is similar to how the first instance of browsers opens with setting for tab recovery enabled. Also restore sessions if this is restoring multiple instances with session restoration after reboot enabled. 2. Dolphin should not restore all tabs for additional instances. This is especially noticeable if the "Keep a single Dolphin window, opening new folders in tabs" checkbox is turned off, and when the Dolphin window is already open (with several tabs), folders from the desktop (plasmashell) are opened by double-clicking. Desktop opens a new Dolphin window with the tabs restored and an open folder at the end. BUG: 464693 CCBUG: 448707 CCBUG: 469271 --- src/main.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index eeb01854b..1ef608193 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -232,14 +232,16 @@ int main(int argc, char **argv) } // Only restore session if: - // 1. Not explicitly opening a new instance - // 2. The "remember state" setting is enabled or session restoration after + // 1. The "remember state" setting is enabled or session restoration after // reboot is in use + // 2. This is the first instance or restoring multiple instances with + // session restoration after reboot enabled // 3. There is a session available to restore - if (!parser.isSet(QStringLiteral("new-window")) && (app.isSessionRestored() || GeneralSettings::rememberOpenedTabs())) { + if (app.isSessionRestored() || GeneralSettings::rememberOpenedTabs()) { // Get saved state data for the last-closed Dolphin instance const QString serviceName = QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid()); - if (Dolphin::dolphinGuiInstances(serviceName).size() > 0) { + const auto instancesCount = Dolphin::dolphinGuiInstances(serviceName).size(); + if (instancesCount == 1 || (app.isSessionRestored() && instancesCount > 0)) { const QString className = KXmlGuiWindow::classNameOfToplevel(1); if (className == QLatin1String("DolphinMainWindow")) { mainWindow->restore(1); -- cgit v1.3