mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-26 08:10:08 -05:00
support for Mac partially added, more cleanup
This commit is contained in:
parent
f9634cf8e7
commit
843e3c9343
|
|
@ -1,12 +1,9 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
|
||||||
#include "switcher.h"
|
#include "switcher.h"
|
||||||
#include <obs-module.h>
|
#include <obs-module.h>
|
||||||
#include <obs-ui.h>
|
|
||||||
#include <obs-data.h>
|
#include <obs-data.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
@ -22,22 +19,18 @@ obs_data_array_t *optionsHotkeyData;
|
||||||
//path to config folder where to save the hotkeybinding (probably later the settings file)
|
//path to config folder where to save the hotkeybinding (probably later the settings file)
|
||||||
string configPath;
|
string configPath;
|
||||||
|
|
||||||
|
//save settings (the only hotkey for now)
|
||||||
void saveKeybinding(string name, obs_data_array_t *hotkeyData) {
|
void saveKeybinding(string name, obs_data_array_t *hotkeyData) {
|
||||||
name.append(".txt");
|
name.append(".txt");
|
||||||
//save settings (the only hotkey for now)
|
|
||||||
wstring stemp = wstring(configPath.begin(), configPath.end());
|
|
||||||
LPCWSTR sw = stemp.c_str();
|
|
||||||
//check if config dir exists
|
//check if config dir exists
|
||||||
if (CreateDirectory(sw, NULL) ||
|
if (boost::filesystem::create_directories(configPath)){
|
||||||
ERROR_ALREADY_EXISTS == GetLastError())
|
|
||||||
{
|
|
||||||
//save hotkey data
|
//save hotkey data
|
||||||
fstream file;
|
fstream file;
|
||||||
file.open(obs_module_config_path(name.c_str()), fstream::out);
|
file.open(obs_module_config_path(name.c_str()), fstream::out);
|
||||||
//doesnt seem to work in obs_module_unload (hotkey data freed already (<- Jim))
|
//doesnt seem to work in obs_module_unload (hotkey data freed already (<- Jim))
|
||||||
//hotkeyData = obs_hotkey_save(pauseHotkeyId);
|
//hotkeyData = obs_hotkey_save(pauseHotkeyId);
|
||||||
int num = obs_data_array_count(hotkeyData);
|
size_t num = obs_data_array_count(hotkeyData);
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
string temp = obs_data_get_json(obs_data_array_item(hotkeyData, i));
|
string temp = obs_data_get_json(obs_data_array_item(hotkeyData, i));
|
||||||
file << temp;
|
file << temp;
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,9 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <tchar.h>
|
|
||||||
#include <shlwapi.h>
|
|
||||||
#pragma comment(lib,"shlwapi.lib")
|
|
||||||
#include "shlobj.h"
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
class Settings {
|
class Settings {
|
||||||
|
|
@ -9,6 +10,6 @@ public:
|
||||||
map<string, string> getMap();
|
map<string, string> getMap();
|
||||||
string getSettingsFilePath();
|
string getSettingsFilePath();
|
||||||
private:
|
private:
|
||||||
string settingsFilePath = "..\\..\\data\\obs-plugins\\SceneSwitcher\\settings.txt";
|
string settingsFilePath = "/Users/Till/Desktop/SceneSwitcher/settings.txt";
|
||||||
void addToMap(string, string);
|
void addToMap(string, string);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
70
switcher.cpp
70
switcher.cpp
|
|
@ -1,15 +1,17 @@
|
||||||
#pragma once
|
|
||||||
#include "stdafx.h"
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <windows.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <obs.h>
|
#include <obs.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include "switcher.h"
|
#include "switcher.h"
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
|
#endif
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
//scene switching is done in here
|
//scene switching is done in here
|
||||||
|
|
@ -76,6 +78,7 @@ void Switcher::switcherThreadFunc() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __WINDOWS__
|
||||||
void Switcher::firstLoad() {
|
void Switcher::firstLoad() {
|
||||||
settings.load();
|
settings.load();
|
||||||
settingsMap = settings.getMap();
|
settingsMap = settings.getMap();
|
||||||
|
|
@ -88,6 +91,39 @@ void Switcher::firstLoad() {
|
||||||
MessageBoxA(0, message.c_str(), "Scene Switcher", 0);
|
MessageBoxA(0, message.c_str(), "Scene Switcher", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
void Switcher::firstLoad() {
|
||||||
|
settings.load();
|
||||||
|
settingsMap = settings.getMap();
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
SInt32 nRes = 0;
|
||||||
|
CFUserNotificationRef pDlg = NULL;
|
||||||
|
const void* keys[] = { kCFUserNotificationAlertHeaderKey,
|
||||||
|
kCFUserNotificationAlertMessageKey };
|
||||||
|
const void* vals[] = {
|
||||||
|
CFSTR("Test Foundation Message Box"),
|
||||||
|
CFStringCreateWithCString(kCFAllocatorDefault,message.c_str(),kCFStringEncodingMacRoman)
|
||||||
|
};
|
||||||
|
|
||||||
|
CFDictionaryRef dict = CFDictionaryCreate(0, keys, vals,
|
||||||
|
sizeof(keys)/sizeof(*keys),
|
||||||
|
&kCFTypeDictionaryKeyCallBacks,
|
||||||
|
&kCFTypeDictionaryValueCallBacks);
|
||||||
|
|
||||||
|
pDlg = CFUserNotificationCreate(kCFAllocatorDefault, 0,
|
||||||
|
kCFUserNotificationPlainAlertLevel,
|
||||||
|
&nRes, dict);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//load the settings needed to start the thread
|
//load the settings needed to start the thread
|
||||||
void Switcher::load() {
|
void Switcher::load() {
|
||||||
|
|
@ -103,6 +139,7 @@ void Switcher::start()
|
||||||
}
|
}
|
||||||
|
|
||||||
//checks if active window is in fullscreen
|
//checks if active window is in fullscreen
|
||||||
|
#ifdef __WINDOWS__
|
||||||
bool Switcher::isWindowFullscreen() {
|
bool Switcher::isWindowFullscreen() {
|
||||||
RECT appBounds;
|
RECT appBounds;
|
||||||
RECT rc;
|
RECT rc;
|
||||||
|
|
@ -120,8 +157,17 @@ bool Switcher::isWindowFullscreen() {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
bool Switcher::isWindowFullscreen() {
|
||||||
|
//TODO: implement the MAC OS version
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//reads the title of the currently active window
|
//reads the title of the currently active window
|
||||||
|
#ifdef __WINDOWS__
|
||||||
string Switcher::GetActiveWindowTitle()
|
string Switcher::GetActiveWindowTitle()
|
||||||
{
|
{
|
||||||
char wnd_title[256];
|
char wnd_title[256];
|
||||||
|
|
@ -130,6 +176,20 @@ string Switcher::GetActiveWindowTitle()
|
||||||
GetWindowTextA(hwnd, wnd_title, sizeof(wnd_title));
|
GetWindowTextA(hwnd, wnd_title, sizeof(wnd_title));
|
||||||
return wnd_title;
|
return wnd_title;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
string Switcher::GetActiveWindowTitle()
|
||||||
|
{
|
||||||
|
string cmd = "osascript -e 'tell application \"System Events\"' -e 'set frontApp to name of first application process whose frontmost is true' -e 'end tell'";
|
||||||
|
char buffer[256];
|
||||||
|
FILE * f = popen(cmd.c_str(), "r");
|
||||||
|
fgets(buffer, 255, f);
|
||||||
|
pclose(f);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//tell the thread to stop
|
//tell the thread to stop
|
||||||
void Switcher::stop() {
|
void Switcher::stop() {
|
||||||
|
|
@ -141,7 +201,7 @@ void Switcher::stop() {
|
||||||
|
|
||||||
string Switcher::getSettingsFilePath()
|
string Switcher::getSettingsFilePath()
|
||||||
{
|
{
|
||||||
return settings.getSettingsFilePath();
|
return settings.getSettingsFilePath();;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Switcher::getIsRunning()
|
bool Switcher::getIsRunning()
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <windows.h>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user