From 9a86ecac42fed2bc0f463a41949c8ca83d06250f Mon Sep 17 00:00:00 2001
From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com>
Date: Sat, 24 May 2025 00:56:13 +0200
Subject: [PATCH] Add option to disable widget caching
---
data/locale/en-US.ini | 1 +
forms/advanced-scene-switcher.ui | 14 ++++++++++++--
lib/advanced-scene-switcher.hpp | 1 +
lib/general.cpp | 17 +++++++++++++++++
lib/macro/macro-segment-list.cpp | 17 +++++++++++++++++
lib/macro/macro-segment-list.hpp | 2 ++
lib/switcher-data.hpp | 1 +
7 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini
index ecae944c..33a49dd1 100644
--- a/data/locale/en-US.ini
+++ b/data/locale/en-US.ini
@@ -42,6 +42,7 @@ AdvSceneSwitcher.generalTab.generalBehavior.warnPluginLoadFailure="Display warni
AdvSceneSwitcher.generalTab.generalBehavior.warnPluginLoadFailureMessage="
Loading of the following plugin libraries was unsuccessful, which could result in some Advanced Scene Switcher functions not being available:%1Check the OBS logs for details.
This message can be disabled on the General tab."
AdvSceneSwitcher.generalTab.generalBehavior.warnCorruptedInstallMessage="The plugin installation seems to be corrupted and might crash!\nPlease make sure the plugin was installed correctly!"
AdvSceneSwitcher.generalTab.generalBehavior.hideLegacyTabs="Hide tabs which can be represented via macros"
+AdvSceneSwitcher.generalTab.generalBehavior.disableMacroWidgetCache="Disable macro widget caching"
AdvSceneSwitcher.generalTab.matchBehavior="Match behavior"
AdvSceneSwitcher.generalTab.priority="Priority"
AdvSceneSwitcher.generalTab.priority.description="Switching methods priority (Highest priority is at the top)"
diff --git a/forms/advanced-scene-switcher.ui b/forms/advanced-scene-switcher.ui
index 050257f8..276bad52 100644
--- a/forms/advanced-scene-switcher.ui
+++ b/forms/advanced-scene-switcher.ui
@@ -181,8 +181,7 @@
-
-
-
+
-
@@ -295,6 +294,17 @@
+ -
+
+
-
+
+
+ AdvSceneSwitcher.generalTab.generalBehavior.disableMacroWidgetCache
+
+
+
+
+
-
-
diff --git a/lib/advanced-scene-switcher.hpp b/lib/advanced-scene-switcher.hpp
index 25604a4e..51158b5e 100644
--- a/lib/advanced-scene-switcher.hpp
+++ b/lib/advanced-scene-switcher.hpp
@@ -66,6 +66,7 @@ public slots:
void on_showTrayNotifications_stateChanged(int state);
void on_uiHintsDisable_stateChanged(int state);
void on_disableComboBoxFilter_stateChanged(int state);
+ void on_disableMacroWidgetCache_stateChanged(int state);
void on_warnPluginLoadFailure_stateChanged(int state);
void on_hideLegacyTabs_stateChanged(int state);
void on_priorityUp_clicked();
diff --git a/lib/general.cpp b/lib/general.cpp
index a29261fa..10961c27 100644
--- a/lib/general.cpp
+++ b/lib/general.cpp
@@ -205,6 +205,16 @@ void AdvSceneSwitcher::on_disableComboBoxFilter_stateChanged(int state)
FilterComboBox::SetFilterBehaviourEnabled(!state);
}
+void AdvSceneSwitcher::on_disableMacroWidgetCache_stateChanged(int state)
+{
+ if (loading) {
+ return;
+ }
+
+ switcher->disableMacroWidgetCache = state;
+ MacroSegmentList::SetCachingEnabled(!state);
+}
+
void AdvSceneSwitcher::on_warnPluginLoadFailure_stateChanged(int state)
{
if (loading) {
@@ -540,6 +550,8 @@ void SwitcherData::SaveGeneralSettings(obs_data_t *obj)
obs_data_set_bool(obj, "disableHints", disableHints);
obs_data_set_bool(obj, "disableFilterComboboxFilter",
disableFilterComboboxFilter);
+ obs_data_set_bool(obj, "disableMacroWidgetCache",
+ disableMacroWidgetCache);
obs_data_set_bool(obj, "warnPluginLoadFailure", warnPluginLoadFailure);
obs_data_set_bool(obj, "hideLegacyTabs", hideLegacyTabs);
@@ -597,6 +609,8 @@ void SwitcherData::LoadGeneralSettings(obs_data_t *obj)
disableHints = obs_data_get_bool(obj, "disableHints");
disableFilterComboboxFilter =
obs_data_get_bool(obj, "disableFilterComboboxFilter");
+ disableMacroWidgetCache =
+ obs_data_get_bool(obj, "disableMacroWidgetCache");
obs_data_set_default_bool(obj, "warnPluginLoadFailure", true);
warnPluginLoadFailure = obs_data_get_bool(obj, "warnPluginLoadFailure");
obs_data_set_default_bool(obj, "hideLegacyTabs", true);
@@ -892,6 +906,9 @@ void AdvSceneSwitcher::SetupGeneralTab()
switcher->disableFilterComboboxFilter);
FilterComboBox::SetFilterBehaviourEnabled(
!switcher->disableFilterComboboxFilter);
+ ui->disableMacroWidgetCache->setChecked(
+ switcher->disableMacroWidgetCache);
+ MacroSegmentList::SetCachingEnabled(!switcher->disableMacroWidgetCache);
ui->warnPluginLoadFailure->setChecked(switcher->warnPluginLoadFailure);
ui->hideLegacyTabs->setChecked(switcher->hideLegacyTabs);
diff --git a/lib/macro/macro-segment-list.cpp b/lib/macro/macro-segment-list.cpp
index 993f2fe9..85991cce 100644
--- a/lib/macro/macro-segment-list.cpp
+++ b/lib/macro/macro-segment-list.cpp
@@ -13,6 +13,8 @@
namespace advss {
+bool MacroSegmentList::_useCache = true;
+
MacroSegmentList::MacroSegmentList(QWidget *parent)
: QScrollArea(parent),
_layout(new QVBoxLayout),
@@ -136,8 +138,18 @@ void MacroSegmentList::Clear(int idx) const
ClearLayout(_contentLayout, idx);
}
+void MacroSegmentList::SetCachingEnabled(bool enable)
+{
+ _useCache = enable;
+}
+
void MacroSegmentList::CacheCurrentWidgetsFor(const Macro *macro)
{
+ if (!_useCache) {
+ _widgetCache.clear();
+ return;
+ }
+
std::vector result;
int idx = 0;
QLayoutItem *item;
@@ -155,6 +167,11 @@ void MacroSegmentList::CacheCurrentWidgetsFor(const Macro *macro)
bool MacroSegmentList::PopulateWidgetsFromCache(const Macro *macro)
{
+ if (!_useCache) {
+ _widgetCache.clear();
+ return false;
+ }
+
auto it = _widgetCache.find(macro);
if (it == _widgetCache.end()) {
return false;
diff --git a/lib/macro/macro-segment-list.hpp b/lib/macro/macro-segment-list.hpp
index 46773c45..6d0552cd 100644
--- a/lib/macro/macro-segment-list.hpp
+++ b/lib/macro/macro-segment-list.hpp
@@ -26,6 +26,7 @@ public:
void Add(QWidget *widget);
void Remove(int idx) const;
void Clear(int idx = 0) const; // Clear all elements >= idx
+ static void SetCachingEnabled(bool enable);
void CacheCurrentWidgetsFor(const Macro *);
bool PopulateWidgetsFromCache(const Macro *);
void Highlight(int idx, QColor color = QColor(Qt::green));
@@ -72,6 +73,7 @@ private:
bool _checkVisibility = true;
+ static bool _useCache;
std::unordered_map> _widgetCache;
};
diff --git a/lib/switcher-data.hpp b/lib/switcher-data.hpp
index 528e2034..333c2a28 100644
--- a/lib/switcher-data.hpp
+++ b/lib/switcher-data.hpp
@@ -164,6 +164,7 @@ public:
bool warnPluginLoadFailure = true;
bool disableHints = false;
bool disableFilterComboboxFilter = false;
+ bool disableMacroWidgetCache = false;
bool hideLegacyTabs = true;
bool saveWindowGeo = false;
QPoint windowPos = {};