add option to set startup behavior

This commit is contained in:
WarmUpTill 2020-08-02 18:45:44 +02:00
parent 91831a1075
commit 3c1e240722
4 changed files with 102 additions and 38 deletions

View File

@ -65,6 +65,42 @@
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="2">
<widget class="Line" name="line_13">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="10">
<spacer name="horizontalSpacer_47">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="5">
<spacer name="horizontalSpacer_52">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0"> <item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="1"> <item row="2" column="1">
@ -119,22 +155,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="4"> <item row="0" column="4">
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="2"> <item row="0" column="2">
@ -220,13 +240,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="0" column="2">
<widget class="Line" name="line_13">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="3"> <item row="0" column="3">
<spacer name="horizontalSpacer_46"> <spacer name="horizontalSpacer_46">
<property name="orientation"> <property name="orientation">
@ -243,19 +256,55 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="5"> <item row="0" column="9">
<spacer name="horizontalSpacer_47"> <widget class="QComboBox" name="startupBehavior"/>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>10</width>
<height>20</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="7">
<spacer name="horizontalSpacer_53">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="6">
<widget class="Line" name="line_18">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="8">
<widget class="QLabel" name="label_64">
<property name="text">
<string>On startup:</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>

View File

@ -10,15 +10,6 @@ void SceneSwitcher::on_close_clicked()
done(0); done(0);
} }
void SceneSwitcher::on_startAtLaunch_toggled(bool value)
{
if (loading)
return;
std::lock_guard<std::mutex> lock(switcher->m);
switcher->startAtLaunch = value;
}
void SceneSwitcher::UpdateNonMatchingScene(const QString &name) void SceneSwitcher::UpdateNonMatchingScene(const QString &name)
{ {
obs_source_t *scene = obs_get_source_by_name(name.toUtf8().constData()); obs_source_t *scene = obs_get_source_by_name(name.toUtf8().constData());
@ -61,6 +52,15 @@ void SceneSwitcher::on_noMatchRandomSwitch_clicked()
ui->noMatchSwitchScene->setEnabled(false); ui->noMatchSwitchScene->setEnabled(false);
} }
void SceneSwitcher::on_startupBehavior_currentIndexChanged(int index)
{
if (loading)
return;
std::lock_guard<std::mutex> lock(switcher->m);
switcher->startupBehavior = (StartupBehavior)index;
}
void SceneSwitcher::on_noMatchSwitchScene_currentTextChanged(const QString &text) void SceneSwitcher::on_noMatchSwitchScene_currentTextChanged(const QString &text)
{ {
if (loading) if (loading)
@ -337,6 +337,7 @@ void SwitcherData::saveGeneralSettings(obs_data_t *obj)
switcher->switchIfNotMatching); switcher->switchIfNotMatching);
obs_data_set_bool(obj, "active", !switcher->stop); obs_data_set_bool(obj, "active", !switcher->stop);
obs_data_set_int(obj, "startup_behavior", switcher->startupBehavior);
std::string autoStopSceneName = std::string autoStopSceneName =
GetWeakSourceName(switcher->autoStopScene); GetWeakSourceName(switcher->autoStopScene);
@ -393,6 +394,12 @@ void SwitcherData::loadGeneralSettings(obs_data_t *obj)
GetWeakSourceByName(nonMatchingScene.c_str()); GetWeakSourceByName(nonMatchingScene.c_str());
switcher->stop = !obs_data_get_bool(obj, "active"); switcher->stop = !obs_data_get_bool(obj, "active");
switcher->startupBehavior =
(StartupBehavior)obs_data_get_int(obj, "startup_behavior");
if (switcher->startupBehavior == START)
switcher->stop = false;
if (switcher->startupBehavior == STOP)
switcher->stop = true;
std::string autoStopScene = std::string autoStopScene =
obs_data_get_string(obj, "autoStopSceneName"); obs_data_get_string(obj, "autoStopSceneName");
@ -558,6 +565,13 @@ void SceneSwitcher::setupGeneralTab()
} }
} }
ui->startupBehavior->addItem(
"Start the scene switcher if it was running");
ui->startupBehavior->addItem("Always start the scene switcher");
ui->startupBehavior->addItem("Do not start the scene switcher");
ui->startupBehavior->setCurrentIndex(switcher->startupBehavior);
if (switcher->th && switcher->th->isRunning()) if (switcher->th && switcher->th->isRunning())
SetStarted(); SetStarted();
else else

View File

@ -76,7 +76,7 @@ public slots:
void on_noMatchDontSwitch_clicked(); void on_noMatchDontSwitch_clicked();
void on_noMatchSwitch_clicked(); void on_noMatchSwitch_clicked();
void on_noMatchRandomSwitch_clicked(); void on_noMatchRandomSwitch_clicked();
void on_startAtLaunch_toggled(bool value); void on_startupBehavior_currentIndexChanged(int index);
void on_noMatchSwitchScene_currentTextChanged(const QString &text); void on_noMatchSwitchScene_currentTextChanged(const QString &text);
void on_checkInterval_valueChanged(int value); void on_checkInterval_valueChanged(int value);
void on_toggleStartButton_clicked(); void on_toggleStartButton_clicked();

View File

@ -253,6 +253,7 @@ struct TimeSwitch {
}; };
typedef enum { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 } NoMatch; typedef enum { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 } NoMatch;
typedef enum { PERSIST = 0, START = 1, STOP = 2 } StartupBehavior;
class SwitcherThread; class SwitcherThread;
@ -267,7 +268,6 @@ struct SwitcherData {
bool transitionActive = false; bool transitionActive = false;
bool waitForTransition = false; bool waitForTransition = false;
std::condition_variable transitionCv; std::condition_variable transitionCv;
bool startAtLaunch = false;
bool stop = false; bool stop = false;
bool verbose = false; bool verbose = false;
bool tansitionOverrideOverride = false; bool tansitionOverrideOverride = false;
@ -280,6 +280,7 @@ struct SwitcherData {
OBSWeakSource lastRandomScene; OBSWeakSource lastRandomScene;
OBSWeakSource nonMatchingScene; OBSWeakSource nonMatchingScene;
NoMatch switchIfNotMatching = NO_SWITCH; NoMatch switchIfNotMatching = NO_SWITCH;
StartupBehavior startupBehavior = PERSIST;
std::vector<WindowSceneSwitch> windowSwitches; std::vector<WindowSceneSwitch> windowSwitches;
std::vector<std::string> ignoreIdleWindows; std::vector<std::string> ignoreIdleWindows;