mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Start message disable option, Hotkey bind fix
This commit is contained in:
parent
c49e9b0d58
commit
e42c2e1232
|
|
@ -4,11 +4,19 @@
|
|||
#include "switcher.h"
|
||||
#include <obs-module.h>
|
||||
#include <obs-ui.h>
|
||||
//#include <QtWidgets/QApplication>
|
||||
#include <obs-data.h>
|
||||
#include <fstream>
|
||||
|
||||
Switcher *switcher = new Switcher();
|
||||
using namespace std;
|
||||
|
||||
//Swicthing done in here
|
||||
Switcher *switcher = new Switcher();
|
||||
//Hotkey
|
||||
obs_hotkey_id hotkeyId;
|
||||
obs_data_array_t *hotkeyData;
|
||||
//path to config folder where to save the hotkeybinding (probably later the settings file)
|
||||
string configPath;
|
||||
|
||||
|
||||
OBS_DECLARE_MODULE()
|
||||
|
||||
|
|
@ -30,31 +38,64 @@ void SceneSwitcherHotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, boo
|
|||
switcher->start();
|
||||
}
|
||||
}
|
||||
//save the keybinding here since it is currently not possible in obs_module_unload
|
||||
hotkeyData = obs_hotkey_save(hotkeyId);
|
||||
}
|
||||
|
||||
|
||||
bool obs_module_load(void)
|
||||
{
|
||||
//modul UI not implemented yet
|
||||
//obs_modal_ui *uiInfo = new obs_modal_ui;
|
||||
//uiInfo->id = "SceneSwitcherUI";
|
||||
//uiInfo->task = "Modify settings for SceneSwitcher";
|
||||
//uiInfo->target = "qt";
|
||||
//uiInfo->exec = execute;
|
||||
//uiInfo->type_data = NULL; //<- sceneswitcher?? pause it? then reload settings?
|
||||
//uiInfo->free_type_data = NULL;
|
||||
//set config path
|
||||
configPath = obs_module_config_path("");
|
||||
|
||||
//obs_register_modal_ui(uiInfo);
|
||||
//register hotkey
|
||||
hotkeyId = obs_hotkey_register_frontend("Scene Switcher", "Toggle automatic scene switching", SceneSwitcherHotkey, switcher);
|
||||
//load hotkey binding if set already (ONLY WORKING FOR A SINGLE HOTKEY AT THE MOMENT! CAREFUL!)
|
||||
ifstream file(obs_module_config_path("hotkey.txt"));
|
||||
if (file.is_open())
|
||||
{
|
||||
string temp;
|
||||
file.seekg(0, std::ios::end);
|
||||
temp.reserve(file.tellg());
|
||||
file.seekg(0, std::ios::beg);
|
||||
temp.assign((std::istreambuf_iterator<char>(file)),std::istreambuf_iterator<char>());
|
||||
hotkeyData = obs_data_array_create();
|
||||
obs_data_array_insert(hotkeyData, 0,obs_data_create_from_json(temp.c_str()));
|
||||
obs_hotkey_load(hotkeyId, hotkeyData);
|
||||
}
|
||||
|
||||
//Hotkey
|
||||
obs_hotkey_register_frontend("Scene Switcher", "Toggle automatic scene switching", SceneSwitcherHotkey, switcher);
|
||||
//load settings file
|
||||
switcher->load();
|
||||
//start the switching thread
|
||||
switcher->start();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void obs_module_unload(void) {
|
||||
|
||||
//save settings (the only hotkey for now)
|
||||
wstring stemp = wstring(configPath.begin(), configPath.end());
|
||||
LPCWSTR sw = stemp.c_str();
|
||||
//check if config dir exists
|
||||
if (CreateDirectory(sw, NULL) ||
|
||||
ERROR_ALREADY_EXISTS == GetLastError())
|
||||
{
|
||||
//save hotkey data
|
||||
fstream file;
|
||||
file.open(obs_module_config_path("hotkey.txt"), fstream::out);
|
||||
//doesnt seem to work in obs_module_unload (hotkey data freed already (<- Jim))
|
||||
//hotkeyData = obs_hotkey_save(hotkeyId);
|
||||
int num = obs_data_array_count(hotkeyData);
|
||||
for (int i = 0; i < num; i++) {
|
||||
string temp = obs_data_get_json(obs_data_array_item(hotkeyData, i));
|
||||
file << temp;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const char *obs_module_author(void)
|
||||
{
|
||||
|
|
|
|||
43
switcher.cpp
43
switcher.cpp
|
|
@ -21,8 +21,6 @@ using namespace std;
|
|||
//scene switching is done in here
|
||||
void Switcher::switcherThreadFunc() {
|
||||
|
||||
|
||||
|
||||
while (isRunning) {
|
||||
|
||||
//get active window title
|
||||
|
|
@ -46,9 +44,7 @@ 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){
|
||||
|
||||
|
|
@ -58,7 +54,6 @@ void Switcher::switcherThreadFunc() {
|
|||
else if (!match && !(settingsMap.find("Backup Scene Name") == settingsMap.end())) {
|
||||
name = settingsMap.find("Backup Scene Name")->second;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
@ -85,46 +80,29 @@ void Switcher::switcherThreadFunc() {
|
|||
}
|
||||
obs_source_release(sceneUsed);
|
||||
obs_source_release(transitionUsed);
|
||||
|
||||
}
|
||||
//sleep for a bit
|
||||
this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// function that checks if two given strings match. The first string may contain wildcard characters
|
||||
bool wildcardMatch(char *first, char * second)
|
||||
{
|
||||
if (*first == '\0' && *second == '\0')
|
||||
return true;
|
||||
|
||||
if (*first == '*' && *(first + 1) != '\0' && *second == '\0')
|
||||
return false;
|
||||
|
||||
if (*first == '?' || *first == *second)
|
||||
return wildcardMatch(first + 1, second + 1);
|
||||
|
||||
if (*first == '*')
|
||||
return wildcardMatch(first + 1, second) || wildcardMatch(first, second + 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
//load the settings needed to start the thread
|
||||
void Switcher::load() {
|
||||
settings.load();
|
||||
settingsMap = settings.getMap();
|
||||
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";
|
||||
if (settingsMap.find("Disable Start Message") == settingsMap.end() || settingsMap.find("Disable Start Message")->second != "Yes") {
|
||||
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";
|
||||
}
|
||||
MessageBoxA(0, message.c_str(), "Scene Switcher", 0);
|
||||
}
|
||||
MessageBoxA(0, message.c_str(), "Scene Switcher", 0);
|
||||
}
|
||||
|
||||
//start thread
|
||||
void Switcher::start()
|
||||
{
|
||||
//start thread
|
||||
isRunning = true;
|
||||
switcherThread = thread(&Switcher::switcherThreadFunc, this);
|
||||
}
|
||||
|
|
@ -152,14 +130,15 @@ bool Switcher::isWindowFullscreen() {
|
|||
string Switcher::GetActiveWindowTitle()
|
||||
{
|
||||
char wnd_title[256];
|
||||
HWND hwnd = GetForegroundWindow(); // get handle of currently active window
|
||||
//get handle of currently active window
|
||||
HWND hwnd = GetForegroundWindow();
|
||||
GetWindowTextA(hwnd, wnd_title, sizeof(wnd_title));
|
||||
return wnd_title;
|
||||
}
|
||||
|
||||
//tell the thread to stop
|
||||
void Switcher::stop() {
|
||||
isRunning = false; //isRunning seems to be called randomly and disables the plugin (?)
|
||||
isRunning = false;
|
||||
switcherThread.join();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user