mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Fullscreen check implemented
This commit is contained in:
parent
689546ef0f
commit
7727567cab
46
settings.cpp
46
settings.cpp
|
|
@ -18,23 +18,21 @@ void Settings::setSettingsFilePath(string path)
|
|||
settingsFilePath = path.append("settings.txt");
|
||||
}
|
||||
|
||||
|
||||
void Settings::load() {
|
||||
//clear settings map
|
||||
settings = map<string, string> ();
|
||||
settings = map<string, Data> ();
|
||||
//read the settings file
|
||||
std::vector<std::string> settingsElements;
|
||||
int numValues = 0;
|
||||
vector<string> settingsElements;
|
||||
ifstream infile(settingsFilePath);
|
||||
string value;
|
||||
string line;
|
||||
size_t pos = string::npos;
|
||||
int valueCheck;
|
||||
int numValues;
|
||||
bool startMessageDisableFound = false;
|
||||
infile.seekg(0);
|
||||
while (infile.good())
|
||||
{
|
||||
valueCheck = 0;
|
||||
numValues = 0;
|
||||
//read json file
|
||||
getline(infile, line);
|
||||
//disable the start message?
|
||||
|
|
@ -51,36 +49,36 @@ void Settings::load() {
|
|||
string temp = line.substr(pos + 10, string::npos - 1);
|
||||
temp.pop_back();
|
||||
stringstream lineStream = stringstream(temp);
|
||||
numValues = 0;
|
||||
while (lineStream.good()) {
|
||||
getline(lineStream, value, ',');
|
||||
settingsElements.push_back(value);
|
||||
valueCheck++;
|
||||
numValues++;
|
||||
}
|
||||
//two values per line are expected
|
||||
//add missing value
|
||||
if(valueCheck < 2) {
|
||||
if(numValues < 3) {
|
||||
settingsElements.push_back("");
|
||||
}
|
||||
//discard additional values
|
||||
for (valueCheck; valueCheck > 2; valueCheck--) {
|
||||
for (numValues; numValues > 3; numValues--) {
|
||||
settingsElements.pop_back();
|
||||
numValues--;
|
||||
}
|
||||
|
||||
//assing to data
|
||||
Data d = Data();
|
||||
string isFullscreen = settingsElements.back();
|
||||
d.isFullscreen = (isFullscreen.find("isFullscreen") == string::npos) ? false : true;
|
||||
settingsElements.pop_back();
|
||||
string sceneName = settingsElements.back();
|
||||
d.sceneName = sceneName;
|
||||
settingsElements.pop_back();
|
||||
string windowName = settingsElements.back();
|
||||
Settings::addToMap(windowName,d);
|
||||
settingsElements.pop_back();
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
//create settings map containing windowname and desired scene
|
||||
for (int i = 0; i < numValues; ) {
|
||||
string s2 = settingsElements.back();
|
||||
settingsElements.pop_back();
|
||||
i++;
|
||||
string s1 = settingsElements.back();
|
||||
settingsElements.pop_back();
|
||||
i++;
|
||||
//window name,scene
|
||||
Settings::addToMap(s1, s2);
|
||||
}
|
||||
}
|
||||
|
||||
bool Settings::getStartMessageDisable()
|
||||
|
|
@ -88,11 +86,11 @@ bool Settings::getStartMessageDisable()
|
|||
return startMessageDisable;
|
||||
}
|
||||
|
||||
void Settings::addToMap(string s1, string s2) {
|
||||
settings.insert(pair<string, string>(s1, s2));
|
||||
void Settings::addToMap(string s1, Data s2) {
|
||||
settings.insert(pair<string, Data>(s1, s2));
|
||||
}
|
||||
|
||||
map<string, string> Settings::getMap() {
|
||||
map<string, Data> Settings::getMap() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
|
|
|||
12
settings.h
12
settings.h
|
|
@ -4,16 +4,22 @@
|
|||
#include <obs-module.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct Data {
|
||||
string sceneName = "";
|
||||
bool isFullscreen = false;
|
||||
};
|
||||
|
||||
class Settings {
|
||||
map<string, string> settings;
|
||||
map<string, Data> settings;
|
||||
bool startMessageDisable = false;
|
||||
public:
|
||||
void load();
|
||||
bool getStartMessageDisable();
|
||||
map<string, string> getMap();
|
||||
map<string, Data> getMap();
|
||||
string getSettingsFilePath();
|
||||
void setSettingsFilePath(string path);
|
||||
private:
|
||||
string settingsFilePath = "";
|
||||
void addToMap(string, string);
|
||||
void addToMap(string, Data);
|
||||
};
|
||||
|
|
|
|||
27
switcher.cpp
27
switcher.cpp
|
|
@ -22,14 +22,16 @@ void Switcher::switcherThreadFunc() {
|
|||
string windowname = GetActiveWindowTitle();
|
||||
bool match = false;
|
||||
string name = "";
|
||||
for (std::map<string, string>::iterator iter = settingsMap.begin(); iter != settingsMap.end(); ++iter)
|
||||
bool checkFullscreen = false;
|
||||
for (std::map<string, Data>::iterator iter = settingsMap.begin(); iter != settingsMap.end(); ++iter)
|
||||
{
|
||||
try
|
||||
{
|
||||
regex e = regex(iter->first);
|
||||
match = regex_match(windowname, e);
|
||||
if (match) {
|
||||
name = iter->second;
|
||||
name = iter->second.sceneName;
|
||||
checkFullscreen = iter->second.isFullscreen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -38,15 +40,13 @@ void Switcher::switcherThreadFunc() {
|
|||
|
||||
}
|
||||
}
|
||||
//do we know the window title or is a fullscreen/backup Scene set?
|
||||
if (!(settingsMap.find("Fullscreen Scene Name") == settingsMap.end()) || !(settingsMap.find("Backup Scene Name") == settingsMap.end())||match){
|
||||
|
||||
if (!match && !(settingsMap.find("Fullscreen Scene Name") == settingsMap.end()) && isWindowFullscreen()) {
|
||||
name = settingsMap.find("Fullscreen Scene Name")->second;
|
||||
}
|
||||
else if (!match && !(settingsMap.find("Backup Scene Name") == settingsMap.end())) {
|
||||
name = settingsMap.find("Backup Scene Name")->second;
|
||||
}
|
||||
//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())) {
|
||||
name = settingsMap.find("Backup Scene Name")->second.sceneName;
|
||||
}
|
||||
obs_source_t * transitionUsed = obs_get_output_source(0);
|
||||
obs_source_t * sceneUsed = obs_transition_get_active_source(transitionUsed);
|
||||
const char *sceneUsedName = obs_source_get_name(sceneUsed);
|
||||
|
|
@ -73,6 +73,7 @@ void Switcher::switcherThreadFunc() {
|
|||
}
|
||||
obs_source_release(sceneUsed);
|
||||
obs_source_release(transitionUsed);
|
||||
}
|
||||
}
|
||||
//sleep for a bit
|
||||
this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
|
|
@ -87,7 +88,7 @@ void Switcher::firstLoad() {
|
|||
string message = "The following settings were found for Scene Switcher:\n";
|
||||
for (auto it = settingsMap.cbegin(); it != settingsMap.cend(); ++it)
|
||||
{
|
||||
message += (it->first) + " -> " + it->second + "\n";
|
||||
message += (it->first) + " -> " + it->second.sceneName + "\n";
|
||||
}
|
||||
message += "\n(settings file located at: " + settings.getSettingsFilePath() + ")";
|
||||
MessageBoxA(0, message.c_str(), "Scene Switcher", 0);
|
||||
|
|
@ -103,7 +104,7 @@ void Switcher::firstLoad() {
|
|||
string message = "The following settings were found for Scene Switcher:\n";
|
||||
for (auto it = settingsMap.cbegin(); it != settingsMap.cend(); ++it)
|
||||
{
|
||||
message += (it->first) + " -> " + it->second + "\n";
|
||||
message += (it->first) + " -> " + it->second.sceneName + "\n";
|
||||
}
|
||||
message += "\n(settings file located at: " + settings.getSettingsFilePath() + ")";
|
||||
SInt32 nRes = 0;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public:
|
|||
private:
|
||||
bool isRunning = true;
|
||||
Settings settings;
|
||||
map<string, string> settingsMap;
|
||||
map<string, Data> settingsMap;
|
||||
void switcherThreadFunc();
|
||||
bool isWindowFullscreen();
|
||||
string GetActiveWindowTitle();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user