mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -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 <obs-module.h>
|
||||
#include <obs-ui.h>
|
||||
#include <obs-data.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
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)
|
||||
string configPath;
|
||||
|
||||
|
||||
//save settings (the only hotkey for now)
|
||||
void saveKeybinding(string name, obs_data_array_t *hotkeyData) {
|
||||
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
|
||||
if (CreateDirectory(sw, NULL) ||
|
||||
ERROR_ALREADY_EXISTS == GetLastError())
|
||||
{
|
||||
if (boost::filesystem::create_directories(configPath)){
|
||||
//save hotkey data
|
||||
fstream file;
|
||||
file.open(obs_module_config_path(name.c_str()), fstream::out);
|
||||
//doesnt seem to work in obs_module_unload (hotkey data freed already (<- Jim))
|
||||
//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++) {
|
||||
string temp = obs_data_get_json(obs_data_array_item(hotkeyData, i));
|
||||
file << temp;
|
||||
|
|
|
|||
|
|
@ -1,16 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <tchar.h>
|
||||
#include <shlwapi.h>
|
||||
#pragma comment(lib,"shlwapi.lib")
|
||||
#include "shlobj.h"
|
||||
#include "settings.h"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
class Settings {
|
||||
|
|
@ -9,6 +10,6 @@ public:
|
|||
map<string, string> getMap();
|
||||
string getSettingsFilePath();
|
||||
private:
|
||||
string settingsFilePath = "..\\..\\data\\obs-plugins\\SceneSwitcher\\settings.txt";
|
||||
string settingsFilePath = "/Users/Till/Desktop/SceneSwitcher/settings.txt";
|
||||
void addToMap(string, string);
|
||||
};
|
||||
|
|
|
|||
70
switcher.cpp
70
switcher.cpp
|
|
@ -1,15 +1,17 @@
|
|||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include "settings.h"
|
||||
#include <map>
|
||||
#include <windows.h>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <obs.h>
|
||||
#include <thread>
|
||||
#include <regex>
|
||||
#include "switcher.h"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
using namespace std;
|
||||
|
||||
//scene switching is done in here
|
||||
|
|
@ -76,6 +78,7 @@ void Switcher::switcherThreadFunc() {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
void Switcher::firstLoad() {
|
||||
settings.load();
|
||||
settingsMap = settings.getMap();
|
||||
|
|
@ -88,6 +91,39 @@ void Switcher::firstLoad() {
|
|||
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
|
||||
void Switcher::load() {
|
||||
|
|
@ -103,6 +139,7 @@ void Switcher::start()
|
|||
}
|
||||
|
||||
//checks if active window is in fullscreen
|
||||
#ifdef __WINDOWS__
|
||||
bool Switcher::isWindowFullscreen() {
|
||||
RECT appBounds;
|
||||
RECT rc;
|
||||
|
|
@ -120,8 +157,17 @@ bool Switcher::isWindowFullscreen() {
|
|||
}
|
||||
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
|
||||
#ifdef __WINDOWS__
|
||||
string Switcher::GetActiveWindowTitle()
|
||||
{
|
||||
char wnd_title[256];
|
||||
|
|
@ -130,6 +176,20 @@ string Switcher::GetActiveWindowTitle()
|
|||
GetWindowTextA(hwnd, wnd_title, sizeof(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
|
||||
void Switcher::stop() {
|
||||
|
|
@ -141,7 +201,7 @@ void Switcher::stop() {
|
|||
|
||||
string Switcher::getSettingsFilePath()
|
||||
{
|
||||
return settings.getSettingsFilePath();
|
||||
return settings.getSettingsFilePath();;
|
||||
}
|
||||
|
||||
bool Switcher::getIsRunning()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
#include "settings.h"
|
||||
#include <map>
|
||||
#include <windows.h>
|
||||
#include <thread>
|
||||
|
||||
using namespace std;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user