mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
"Ignore Window Names" option added
This commit is contained in:
parent
04ffb09db9
commit
63946020b8
24
settings.cpp
24
settings.cpp
|
|
@ -23,6 +23,7 @@ void Settings::load() {
|
|||
settings = map<string, Data>();
|
||||
sceneRoundTrip = vector<string>();
|
||||
pauseScenes = vector<string>();
|
||||
ignoreNames = vector<string>();
|
||||
//read the settings file
|
||||
vector<string> settingsElements;
|
||||
ifstream infile(settingsFilePath);
|
||||
|
|
@ -65,10 +66,12 @@ void Settings::load() {
|
|||
if (sceneRoundTrip.size() > 0) {
|
||||
sceneRoundTrip.back().pop_back();
|
||||
}
|
||||
//add missing values
|
||||
if (sceneRoundTrip.size() == 0 || sceneRoundTrip.size() % 2 != 0) {
|
||||
sceneRoundTrip.push_back("");
|
||||
}
|
||||
}
|
||||
//find Pause Scene Names
|
||||
if (temp.find("Pause Scene Names") != temp.npos) {
|
||||
//discard the first value ("Pause Scene Names")
|
||||
getline(lineStream, value, ',');
|
||||
|
|
@ -82,8 +85,22 @@ void Settings::load() {
|
|||
pauseScenes.back().pop_back();
|
||||
}
|
||||
}
|
||||
//find window names to ignroe
|
||||
if (temp.find("Ignore Window Names") != temp.npos) {
|
||||
//discard the first value "Ignore Window Names"
|
||||
getline(lineStream, value, ',');
|
||||
while (lineStream.good()) {
|
||||
//Ignore Window Names,windowName1,windowName2,...
|
||||
getline(lineStream, value, ',');
|
||||
ignoreNames.push_back(value);
|
||||
}
|
||||
//remove trailing /" of last value
|
||||
if (ignoreNames.size() > 0) {
|
||||
ignoreNames.back().pop_back();
|
||||
}
|
||||
}
|
||||
//find values for Scene switching
|
||||
if (temp.find("Pause Scene Names") == temp.npos && temp.find("Scene Round Trip") == temp.npos)
|
||||
if (temp.find("Pause Scene Names") == temp.npos && temp.find("Scene Round Trip") == temp.npos && temp.find("Ignore Window Names") == temp.npos)
|
||||
{
|
||||
//windowTitle,sceneName,isFullscreenValue
|
||||
while (lineStream.good()) {
|
||||
|
|
@ -138,3 +155,8 @@ vector<string> Settings::getPauseScenes() {
|
|||
return pauseScenes;
|
||||
}
|
||||
|
||||
vector<string> Settings::getIgnoreNames()
|
||||
{
|
||||
return ignoreNames;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@ public:
|
|||
map<string, Data> getMap();
|
||||
vector<string> getSceneRoundTrip();
|
||||
vector<string> getPauseScenes();
|
||||
vector<string> getIgnoreNames();
|
||||
string getSettingsFilePath();
|
||||
void setSettingsFilePath(string path);
|
||||
private:
|
||||
string settingsFilePath = "";
|
||||
map<string, Data> settings;
|
||||
vector<string> sceneRoundTrip;
|
||||
vector<string>pauseScenes;
|
||||
vector<string> pauseScenes;
|
||||
vector<string> ignoreNames;
|
||||
bool startMessageDisable = false;
|
||||
};
|
||||
|
|
|
|||
91
switcher.cpp
91
switcher.cpp
|
|
@ -78,51 +78,55 @@ void Switcher::switcherThreadFunc() {
|
|||
else {
|
||||
//get active window title and reset values
|
||||
windowname = GetActiveWindowTitle();
|
||||
match = false;
|
||||
sceneName = "";
|
||||
checkFullscreen = false;
|
||||
//first check if there is a direct match
|
||||
map<string, Data>::iterator it = settingsMap.find(windowname);
|
||||
if (it != settingsMap.end()) {
|
||||
sceneName = it->second.sceneName;
|
||||
checkFullscreen = it->second.isFullscreen;
|
||||
match = true;
|
||||
}
|
||||
else {
|
||||
//maybe there is a regular expression match
|
||||
for (map<string, Data>::iterator iter = settingsMap.begin(); iter != settingsMap.end(); ++iter)
|
||||
{
|
||||
try {
|
||||
regex e = regex(iter->first);
|
||||
match = regex_match(windowname, e);
|
||||
if (match) {
|
||||
sceneName = iter->second.sceneName;
|
||||
checkFullscreen = iter->second.isFullscreen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (...) {}
|
||||
//should we ignore this window name?
|
||||
if (find(ignoreNames.begin(), ignoreNames.end(), windowname) == ignoreNames.end()) {
|
||||
//reset values
|
||||
match = false;
|
||||
sceneName = "";
|
||||
checkFullscreen = false;
|
||||
//first check if there is a direct match
|
||||
map<string, Data>::iterator it = settingsMap.find(windowname);
|
||||
if (it != settingsMap.end()) {
|
||||
sceneName = it->second.sceneName;
|
||||
checkFullscreen = it->second.isFullscreen;
|
||||
match = true;
|
||||
}
|
||||
}
|
||||
//do we only switch if window is also fullscreen?
|
||||
if (!checkFullscreen || (checkFullscreen && isWindowFullscreen())) {
|
||||
//do we know the window title or is a fullscreen/backup Scene set?
|
||||
if (!(settingsMap.find("Backup Scene Name") == settingsMap.end()) || match) {
|
||||
if (!match && !(settingsMap.find("Backup Scene Name") == settingsMap.end())) {
|
||||
sceneName = settingsMap.find("Backup Scene Name")->second.sceneName;
|
||||
}
|
||||
//check if current scene is already the desired scene
|
||||
if ((sceneUsedName) && strcmp(sceneUsedName, sceneName.c_str()) != 0) {
|
||||
//switch scene
|
||||
obs_source_t *source = obs_get_source_by_name(sceneName.c_str());
|
||||
if (source != NULL) {
|
||||
//create transition to new scene (otherwise UI wont work anymore)
|
||||
obs_transition_start(transitionUsed, OBS_TRANSITION_MODE_AUTO, 300, source); //OBS_TRANSITION_MODE_AUTO uses the obs user settings for transitions
|
||||
else {
|
||||
//maybe there is a regular expression match
|
||||
for (map<string, Data>::iterator iter = settingsMap.begin(); iter != settingsMap.end(); ++iter)
|
||||
{
|
||||
try {
|
||||
regex e = regex(iter->first);
|
||||
match = regex_match(windowname, e);
|
||||
if (match) {
|
||||
sceneName = iter->second.sceneName;
|
||||
checkFullscreen = iter->second.isFullscreen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
obs_source_release(source);
|
||||
catch (...) {}
|
||||
}
|
||||
}
|
||||
//do we only switch if window is also fullscreen?
|
||||
if (!checkFullscreen || (checkFullscreen && isWindowFullscreen())) {
|
||||
//do we know the window title or is a fullscreen/backup Scene set?
|
||||
if (!(settingsMap.find("Backup Scene Name") == settingsMap.end()) || match) {
|
||||
if (!match && !(settingsMap.find("Backup Scene Name") == settingsMap.end())) {
|
||||
sceneName = settingsMap.find("Backup Scene Name")->second.sceneName;
|
||||
}
|
||||
//check if current scene is already the desired scene
|
||||
if ((sceneUsedName) && strcmp(sceneUsedName, sceneName.c_str()) != 0) {
|
||||
//switch scene
|
||||
obs_source_t *source = obs_get_source_by_name(sceneName.c_str());
|
||||
if (source != NULL) {
|
||||
//create transition to new scene (otherwise UI wont work anymore)
|
||||
obs_transition_start(transitionUsed, OBS_TRANSITION_MODE_AUTO, 300, source); //OBS_TRANSITION_MODE_AUTO uses the obs user settings for transitions
|
||||
}
|
||||
obs_source_release(source);
|
||||
}
|
||||
obs_source_release(sceneUsed);
|
||||
obs_source_release(transitionUsed);
|
||||
}
|
||||
obs_source_release(sceneUsed);
|
||||
obs_source_release(transitionUsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -138,6 +142,7 @@ void Switcher::firstLoad() {
|
|||
settingsMap = settings.getMap();
|
||||
sceneRoundTrip = settings.getSceneRoundTrip();
|
||||
pauseScenes = settings.getPauseScenes();
|
||||
ignoreNames = settings.getIgnoreNames();
|
||||
if (!settings.getStartMessageDisable()) {
|
||||
string message = "The following settings were found for Scene Switcher:\n";
|
||||
for (auto it = settingsMap.cbegin(); it != settingsMap.cend(); ++it)
|
||||
|
|
@ -156,6 +161,7 @@ void Switcher::firstLoad() {
|
|||
settingsMap = settings.getMap();
|
||||
sceneRoundTrip = settings.getSceneRoundTrip();
|
||||
pauseScenes = settings.getPauseScenes();
|
||||
ignoreNames = settings.getIgnoreNames();
|
||||
if (!settings.getStartMessageDisable()) {
|
||||
string message = "The following settings were found for Scene Switcher:\n";
|
||||
for (auto it = settingsMap.cbegin(); it != settingsMap.cend(); ++it)
|
||||
|
|
@ -191,6 +197,7 @@ void Switcher::load() {
|
|||
settingsMap = settings.getMap();
|
||||
sceneRoundTrip = settings.getSceneRoundTrip();
|
||||
pauseScenes = settings.getPauseScenes();
|
||||
ignoreNames = settings.getIgnoreNames();
|
||||
}
|
||||
|
||||
//start thread
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ private:
|
|||
map<string, Data> settingsMap;
|
||||
vector<string> sceneRoundTrip;
|
||||
vector<string> pauseScenes;
|
||||
vector<string> ignoreNames;
|
||||
void switcherThreadFunc();
|
||||
bool isWindowFullscreen();
|
||||
string GetActiveWindowTitle();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user