mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-11 11:06:03 -05:00
Refactor QueueUITask helper
This commit is contained in:
@@ -420,11 +420,10 @@ static bool queueWithNameExists(const std::string &name)
|
|||||||
return !GetWeakActionQueueByName(name).expired();
|
return !GetWeakActionQueueByName(name).expired();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void signalImportedQueues(void *varsPtr)
|
static void
|
||||||
|
signalImportedQueues(const std::vector<std::shared_ptr<Item>> &queues)
|
||||||
{
|
{
|
||||||
auto queues = std::unique_ptr<std::vector<std::shared_ptr<Item>>>(
|
for (const auto &queue : queues) {
|
||||||
static_cast<std::vector<std::shared_ptr<Item>> *>(varsPtr));
|
|
||||||
for (const auto &queue : *queues) {
|
|
||||||
ActionQueueSignalManager::Instance()->Add(
|
ActionQueueSignalManager::Instance()->Add(
|
||||||
QString::fromStdString(queue->Name()));
|
QString::fromStdString(queue->Name()));
|
||||||
}
|
}
|
||||||
@@ -436,7 +435,7 @@ void ImportQueues(obs_data_t *data)
|
|||||||
obs_data_get_array(data, "actionQueues");
|
obs_data_get_array(data, "actionQueues");
|
||||||
size_t count = obs_data_array_count(array);
|
size_t count = obs_data_array_count(array);
|
||||||
|
|
||||||
auto importedQueues = new std::vector<std::shared_ptr<Item>>;
|
std::vector<std::shared_ptr<Item>> importedQueues;
|
||||||
|
|
||||||
for (size_t i = 0; i < count; i++) {
|
for (size_t i = 0; i < count; i++) {
|
||||||
OBSDataAutoRelease arrayElement = obs_data_array_item(array, i);
|
OBSDataAutoRelease arrayElement = obs_data_array_item(array, i);
|
||||||
@@ -446,10 +445,11 @@ void ImportQueues(obs_data_t *data)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
queues.emplace_back(queue);
|
queues.emplace_back(queue);
|
||||||
importedQueues->emplace_back(queue);
|
importedQueues.emplace_back(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueUITask(signalImportedQueues, importedQueues);
|
QueueUITask(
|
||||||
|
[importedQueues]() { signalImportedQueues(importedQueues); });
|
||||||
}
|
}
|
||||||
|
|
||||||
std::weak_ptr<ActionQueue> GetWeakActionQueueByName(const std::string &name)
|
std::weak_ptr<ActionQueue> GetWeakActionQueueByName(const std::string &name)
|
||||||
|
|||||||
@@ -734,12 +734,10 @@ TempVarSignalManager *TempVarSignalManager::Instance()
|
|||||||
void NotifyUIAboutTempVarChange(MacroSegment *segment)
|
void NotifyUIAboutTempVarChange(MacroSegment *segment)
|
||||||
{
|
{
|
||||||
IncrementTempVarInUseGeneration();
|
IncrementTempVarInUseGeneration();
|
||||||
QueueUITask(
|
QueueUITask([segment]() {
|
||||||
[](void *segment) {
|
TempVarSignalManager::Instance()->SegmentTempVarsChanged(
|
||||||
TempVarSignalManager::Instance()->SegmentTempVarsChanged(
|
segment);
|
||||||
(MacroSegment *)segment);
|
});
|
||||||
},
|
|
||||||
segment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TempVarOutputMappingsWidget::TempVarOutputMappingsWidget(QWidget *parent)
|
TempVarOutputMappingsWidget::TempVarOutputMappingsWidget(QWidget *parent)
|
||||||
|
|||||||
@@ -184,9 +184,9 @@ std::string GetThemeTypeName()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueueUITask(void (*task)(void *param), void *param)
|
void QueueUITaskRaw(void (*task)(void *param), void *param, bool wait)
|
||||||
{
|
{
|
||||||
obs_queue_task(OBS_TASK_UI, task, param, false);
|
obs_queue_task(OBS_TASK_UI, task, param, wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsCursorInWidgetArea(QWidget *widget)
|
bool IsCursorInWidgetArea(QWidget *widget)
|
||||||
|
|||||||
@@ -6,7 +6,10 @@
|
|||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
class QAbstractButton;
|
class QAbstractButton;
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
@@ -38,7 +41,23 @@ EXPORT void DisplayTrayMessage(const QString &title, const QString &msg,
|
|||||||
EXPORT std::string GetThemeTypeName();
|
EXPORT std::string GetThemeTypeName();
|
||||||
EXPORT QWidget *GetSettingsWindow();
|
EXPORT QWidget *GetSettingsWindow();
|
||||||
|
|
||||||
EXPORT void QueueUITask(void (*task)(void *param), void *param);
|
EXPORT void QueueUITaskRaw(void (*task)(void *param), void *param,
|
||||||
|
bool wait = false);
|
||||||
|
|
||||||
|
// Runs func on the main/UI thread; blocks if wait is true.
|
||||||
|
template<typename F> void QueueUITask(F &&func, bool wait = false)
|
||||||
|
{
|
||||||
|
using FnType = std::decay_t<F>;
|
||||||
|
auto *heapFunc = new FnType(std::forward<F>(func));
|
||||||
|
|
||||||
|
QueueUITaskRaw(
|
||||||
|
[](void *param) {
|
||||||
|
std::unique_ptr<FnType> fn(
|
||||||
|
static_cast<FnType *>(param));
|
||||||
|
(*fn)();
|
||||||
|
},
|
||||||
|
heapFunc, wait);
|
||||||
|
}
|
||||||
|
|
||||||
bool IsCursorInWidgetArea(QWidget *widget);
|
bool IsCursorInWidgetArea(QWidget *widget);
|
||||||
|
|
||||||
|
|||||||
@@ -504,11 +504,10 @@ void LoadVariables(obs_data_t *obj)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void signalImportedVariables(void *varsPtr)
|
static void
|
||||||
|
signalImportedVariables(const std::vector<std::shared_ptr<Item>> &vars)
|
||||||
{
|
{
|
||||||
auto vars = std::unique_ptr<std::vector<std::shared_ptr<Item>>>(
|
for (const auto &var : vars) {
|
||||||
static_cast<std::vector<std::shared_ptr<Item>> *>(varsPtr));
|
|
||||||
for (const auto &var : *vars) {
|
|
||||||
VariableSignalManager::Instance()->Add(
|
VariableSignalManager::Instance()->Add(
|
||||||
QString::fromStdString(var->Name()));
|
QString::fromStdString(var->Name()));
|
||||||
}
|
}
|
||||||
@@ -519,7 +518,7 @@ void ImportVariables(obs_data_t *data)
|
|||||||
OBSDataArrayAutoRelease array = obs_data_get_array(data, "variables");
|
OBSDataArrayAutoRelease array = obs_data_get_array(data, "variables");
|
||||||
size_t count = obs_data_array_count(array);
|
size_t count = obs_data_array_count(array);
|
||||||
|
|
||||||
auto importedVars = new std::vector<std::shared_ptr<Item>>;
|
std::vector<std::shared_ptr<Item>> importedVars;
|
||||||
|
|
||||||
for (size_t i = 0; i < count; i++) {
|
for (size_t i = 0; i < count; i++) {
|
||||||
OBSDataAutoRelease arrayElement = obs_data_array_item(array, i);
|
OBSDataAutoRelease arrayElement = obs_data_array_item(array, i);
|
||||||
@@ -531,10 +530,11 @@ void ImportVariables(obs_data_t *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GetVariables().emplace_back(var);
|
GetVariables().emplace_back(var);
|
||||||
importedVars->emplace_back(var);
|
importedVars.emplace_back(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueUITask(signalImportedVariables, importedVars);
|
QueueUITask(
|
||||||
|
[importedVars]() { signalImportedVariables(importedVars); });
|
||||||
}
|
}
|
||||||
|
|
||||||
std::chrono::high_resolution_clock::time_point GetLastVariableChangeTime()
|
std::chrono::high_resolution_clock::time_point GetLastVariableChangeTime()
|
||||||
|
|||||||
@@ -17,20 +17,6 @@ bool MacroActionSceneCollection::_registered = MacroActionFactory::Register(
|
|||||||
MacroActionSceneCollectionEdit::Create,
|
MacroActionSceneCollectionEdit::Create,
|
||||||
"AdvSceneSwitcher.action.sceneCollection"});
|
"AdvSceneSwitcher.action.sceneCollection"});
|
||||||
|
|
||||||
template<typename F> void QueueUITaskLambda(F &&func)
|
|
||||||
{
|
|
||||||
using FnType = std::decay_t<F>;
|
|
||||||
auto *heapFunc = new FnType(std::forward<F>(func));
|
|
||||||
|
|
||||||
QueueUITask(
|
|
||||||
[](void *param) {
|
|
||||||
std::unique_ptr<FnType> fn(
|
|
||||||
static_cast<FnType *>(param));
|
|
||||||
(*fn)();
|
|
||||||
},
|
|
||||||
heapFunc);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MacroActionSceneCollection::PerformAction()
|
bool MacroActionSceneCollection::PerformAction()
|
||||||
{
|
{
|
||||||
// Changing the scene collection will also reload the settings of the
|
// Changing the scene collection will also reload the settings of the
|
||||||
@@ -41,7 +27,7 @@ bool MacroActionSceneCollection::PerformAction()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto collectionName = _sceneCollection;
|
const auto collectionName = _sceneCollection;
|
||||||
QueueUITaskLambda([collectionName]() {
|
QueueUITask([collectionName]() {
|
||||||
obs_frontend_set_current_scene_collection(
|
obs_frontend_set_current_scene_collection(
|
||||||
collectionName.c_str());
|
collectionName.c_str());
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -185,20 +185,6 @@ static void closeSourceDialog(obs_source_t *source, bool accept,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F> void QueueUITaskLambda(F &&func)
|
|
||||||
{
|
|
||||||
using FnType = std::decay_t<F>;
|
|
||||||
auto *heapFunc = new FnType(std::forward<F>(func));
|
|
||||||
|
|
||||||
QueueUITask(
|
|
||||||
[](void *param) {
|
|
||||||
std::unique_ptr<FnType> fn(
|
|
||||||
static_cast<FnType *>(param));
|
|
||||||
(*fn)();
|
|
||||||
},
|
|
||||||
heapFunc);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MacroActionSource::PerformAction()
|
bool MacroActionSource::PerformAction()
|
||||||
{
|
{
|
||||||
OBSSource s = obs_weak_source_get_source(_source.GetSource());
|
OBSSource s = obs_weak_source_get_source(_source.GetSource());
|
||||||
@@ -271,17 +257,17 @@ bool MacroActionSource::PerformAction()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueUITaskLambda([&]() {
|
QueueUITask([&]() {
|
||||||
closeSourceDialog(s, true, "OBSBasicInteraction");
|
closeSourceDialog(s, true, "OBSBasicInteraction");
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case Action::CLOSE_FILTER_DIALOG:
|
case Action::CLOSE_FILTER_DIALOG:
|
||||||
QueueUITaskLambda([&]() {
|
QueueUITask([&]() {
|
||||||
closeSourceDialog(s, _acceptDialog, "OBSBasicFilters");
|
closeSourceDialog(s, _acceptDialog, "OBSBasicFilters");
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case Action::CLOSE_PROPERTIES_DIALOG:
|
case Action::CLOSE_PROPERTIES_DIALOG:
|
||||||
QueueUITaskLambda([&]() {
|
QueueUITask([&]() {
|
||||||
closeSourceDialog(s, _acceptDialog,
|
closeSourceDialog(s, _acceptDialog,
|
||||||
"OBSBasicProperties");
|
"OBSBasicProperties");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -31,14 +31,9 @@ static bool setup()
|
|||||||
static const auto showInvalidWarnings = [](void *) {
|
static const auto showInvalidWarnings = [](void *) {
|
||||||
const auto invalidTokens = getInvalidTokens();
|
const auto invalidTokens = getInvalidTokens();
|
||||||
for (const auto &token : invalidTokens) {
|
for (const auto &token : invalidTokens) {
|
||||||
QueueUITask(
|
QueueUITask([token]() {
|
||||||
[](void *tokenPtr) {
|
InvalidTokenDialog::ShowWarning(token);
|
||||||
auto tokenName = static_cast<QString *>(
|
});
|
||||||
tokenPtr);
|
|
||||||
InvalidTokenDialog::ShowWarning(
|
|
||||||
*tokenName);
|
|
||||||
},
|
|
||||||
(void *)&token);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ std::string GetThemeTypeName()
|
|||||||
return "Dark";
|
return "Dark";
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueueUITask(void (*task)(void *param), void *) {}
|
void QueueUITaskRaw(void (*task)(void *param), void *, bool) {}
|
||||||
|
|
||||||
QWidget *GetSettingsWindow()
|
QWidget *GetSettingsWindow()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user