From 65545d85ba08ce613d2bd37c7e4527b5337c642f Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Mon, 29 May 2023 15:33:48 +0200 Subject: [PATCH] Let OBS handle dock restoration on first startup and cleanup on shutdown The "manual" attempt at restoring the docks should only be performed on scene collection change as OBS will already take care of this on starutp. Do not delete the macro dock widgets on shutdown so OBS is able to save their location and size properly. --- src/general.cpp | 1 + src/macro-core/macro.cpp | 23 +++++++++++++++-------- src/switcher-data.hpp | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/general.cpp b/src/general.cpp index ac78fdfc..6beb274b 100644 --- a/src/general.cpp +++ b/src/general.cpp @@ -516,6 +516,7 @@ void SwitcherData::LoadSettings(obs_data_t *obj) // Reset on startup and scene collection change switcher->lastOpenedTab = -1; + startupLoadDone = true; } void SwitcherData::SaveSettings(obs_data_t *obj) diff --git a/src/macro-core/macro.cpp b/src/macro-core/macro.cpp index 3892f6ba..76314ae7 100644 --- a/src/macro-core/macro.cpp +++ b/src/macro-core/macro.cpp @@ -30,7 +30,12 @@ Macro::~Macro() _die = true; Stop(); ClearHotkeys(); - RemoveDock(); + + // Keep the dock widgets in case of shutdown so they can be rostored by + // OBS on startup + if (!switcher->obsIsShuttingDown) { + RemoveDock(); + } } std::shared_ptr @@ -705,14 +710,16 @@ void Macro::EnableDock(bool value) // geometry set here. // The function calls here are only intended to attempt to restore the // dock status when switching scene collections. - _dock->setVisible(_dockIsVisible); - if (window->dockWidgetArea(_dock) != _dockArea) { - window->addDockWidget(_dockArea, _dock); + if (switcher->startupLoadDone) { + _dock->setVisible(_dockIsVisible); + if (window->dockWidgetArea(_dock) != _dockArea) { + window->addDockWidget(_dockArea, _dock); + } + if (_dock->isFloating() != _dockIsFloating) { + _dock->setFloating(_dockIsFloating); + } + _dock->restoreGeometry(_dockGeo); } - if (_dock->isFloating() != _dockIsFloating) { - _dock->setFloating(_dockIsFloating); - } - _dock->restoreGeometry(_dockGeo); _registerDock = value; } diff --git a/src/switcher-data.hpp b/src/switcher-data.hpp index 7b68d3ff..32987c81 100644 --- a/src/switcher-data.hpp +++ b/src/switcher-data.hpp @@ -124,6 +124,7 @@ public: bool firstInterval = true; bool firstIntervalAfterStop = true; int shutdownConditionCount = 0; + bool startupLoadDone = false; obs_source_t *waitScene = nullptr; OBSWeakSource currentScene = nullptr;