From b95370c1fbb7cf83d9bdee98c6994ce91ed1f2a2 Mon Sep 17 00:00:00 2001
From: Zachary Lund <zachary.lund@streamlabs.com>
Date: Fri, 10 Aug 2018 11:28:39 -0700
Subject: [PATCH 1/3] Change options to be easier to use with config

This removes the "_ENABLED" suffix on options. The advantage of this
is it makes more sense and it's easier to work with from CMake. The
script will now check to see if that EXPERIMENTAL_SHARED_TEXTURE_SUPPORT
is true. If it is, it sets the enabled variable which can then be used
in code correctly with the need to define macros that hope to catch the
value of that option. This way, any false or true value that cmake knows
will correctly work. If one is given to cmake that it doesn't understand
it will correctly tell the user.
---
 CMakeLists.txt      | 10 +++++++---
 browser-config.h.in |  5 +----
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4a991b0b6..174ef7f56 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,8 +15,12 @@ if(NOT CEF_FOUND)
 	return()
 endif()
 
-option(EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED "Enable shared texture support for the browser plugin (Win32)" ON)
-option(BROWSER_PANEL_SUPPORT_ENABLED "Enables Qt web browser panel support" ON)
+option(EXPERIMENTAL_SHARED_TEXTURE_SUPPORT "Enable shared texture support for the browser plugin (Win32)" ON)
+option(BROWSER_PANEL_SUPPORT "Enables Qt web browser panel support" ON)
+
+if (EXPERIMENTAL_SHARED_TEXTURE_SUPPORT)
+	set(EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED)
+endif()
 
 configure_file(
 	"${CMAKE_CURRENT_SOURCE_DIR}/browser-config.h.in"
@@ -84,7 +88,7 @@ set(obs-browser_HEADERS
 
 # only allow browser panels on win32 for now -- other operating systems
 # need more testing
-if(WIN32 AND BROWSER_PANEL_SUPPORT_ENABLED)
+if(WIN32 AND BROWSER_PANEL_SUPPORT)
 	if(DEFINED QTDIR${_lib_suffix})
 		list(APPEND CMAKE_PREFIX_PATH "${QTDIR${_lib_suffix}}")
 	elseif(DEFINED QTDIR)
diff --git a/browser-config.h.in b/browser-config.h.in
index ef4e7ed59..3dbf867c7 100644
--- a/browser-config.h.in
+++ b/browser-config.h.in
@@ -17,8 +17,5 @@
 #endif
 
 #ifdef _WIN32
-#define EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED \
-	@EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED@
-#else
-#define EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED false
+#cmakedefine01 EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED
 #endif

From bd705e9f4184df103e054c6e94ebdc5053b6577e Mon Sep 17 00:00:00 2001
From: Zachary Lund <zachary.lund@streamlabs.com>
Date: Fri, 10 Aug 2018 11:36:57 -0700
Subject: [PATCH 2/3] Remove unused macros in config.h.in

---
 browser-config.h.in | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/browser-config.h.in b/browser-config.h.in
index 3dbf867c7..51efd09a2 100644
--- a/browser-config.h.in
+++ b/browser-config.h.in
@@ -1,21 +1,5 @@
 #pragma once
 
-#ifndef ON
-#define ON true
-#endif
-
-#ifndef OFF
-#define OFF false
-#endif
-
-#ifndef TRUE
-#define TRUE true
-#endif
-
-#ifndef FALSE
-#define FALSE false
-#endif
-
 #ifdef _WIN32
 #cmakedefine01 EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED
 #endif

From e7b870becf43ddc7b4bac82779592370f577d5f3 Mon Sep 17 00:00:00 2001
From: Zachary Lund <zachary.lund@streamlabs.com>
Date: Fri, 10 Aug 2018 12:43:53 -0700
Subject: [PATCH 3/3] Add option for obs-frontend-api support

---
 CMakeLists.txt         |  7 ++++++-
 browser-client.cpp     | 11 +++++++++--
 browser-config.h.in    |  2 ++
 obs-browser-plugin.cpp | 11 ++++++++++-
 4 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 174ef7f56..aca109f88 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,11 +17,16 @@ endif()
 
 option(EXPERIMENTAL_SHARED_TEXTURE_SUPPORT "Enable shared texture support for the browser plugin (Win32)" ON)
 option(BROWSER_PANEL_SUPPORT "Enables Qt web browser panel support" ON)
+option(BROWSER_FRONTEND_API_SUPPORT "Enables integration with obs-frontend-api library" ON)
 
 if (EXPERIMENTAL_SHARED_TEXTURE_SUPPORT)
 	set(EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED)
 endif()
 
+if (BROWSER_FRONTEND_API_SUPPORT)
+	set(BROWSER_FRONTEND_API_SUPPORT_ENABLED)
+endif()
+
 configure_file(
 	"${CMAKE_CURRENT_SOURCE_DIR}/browser-config.h.in"
 	"${CMAKE_CURRENT_BINARY_DIR}/browser-config.h")
@@ -88,7 +93,7 @@ set(obs-browser_HEADERS
 
 # only allow browser panels on win32 for now -- other operating systems
 # need more testing
-if(WIN32 AND BROWSER_PANEL_SUPPORT)
+if(WIN32 AND BROWSER_PANEL_SUPPORT AND BROWSER_FRONTEND_API_SUPPORT)
 	if(DEFINED QTDIR${_lib_suffix})
 		list(APPEND CMAKE_PREFIX_PATH "${QTDIR${_lib_suffix}}")
 	elseif(DEFINED QTDIR)
diff --git a/browser-client.cpp b/browser-client.cpp
index 5d6691e33..5577e2874 100644
--- a/browser-client.cpp
+++ b/browser-client.cpp
@@ -20,7 +20,10 @@
 #include "obs-browser-source.hpp"
 #include "base64/base64.hpp"
 #include "json11/json11.hpp"
+
+#if BROWSER_FRONTEND_API_SUPPORT_ENABLED
 #include <obs-frontend-api.h>
+#endif
 
 using namespace json11;
 
@@ -106,14 +109,18 @@ bool BrowserClient::OnProcessMessageReceived(
 			{"height", (int)obs_source_get_height(bs->source)}
 		};
 
-	} else if (name == "getStatus") {
+	}
+#if BROWSER_FRONTEND_API_SUPPORT_ENABLED
+	else if (name == "getStatus") {
 		json = Json::object {
 			{"recording", obs_frontend_recording_active()},
 			{"streaming", obs_frontend_streaming_active()},
 			{"replaybuffer", obs_frontend_replay_buffer_active()}
 		};
 
-	} else {
+	}
+#endif
+	else {
 		return false;
 	}
 
diff --git a/browser-config.h.in b/browser-config.h.in
index 51efd09a2..5970763a3 100644
--- a/browser-config.h.in
+++ b/browser-config.h.in
@@ -3,3 +3,5 @@
 #ifdef _WIN32
 #cmakedefine01 EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED
 #endif
+
+#cmakedefine01 BROWSER_FRONTEND_API_SUPPORT_ENABLED
\ No newline at end of file
diff --git a/obs-browser-plugin.cpp b/obs-browser-plugin.cpp
index 7cefea434..5cd5c0dcf 100644
--- a/obs-browser-plugin.cpp
+++ b/obs-browser-plugin.cpp
@@ -16,7 +16,6 @@
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  ******************************************************************************/
 
-#include <obs-frontend-api.h>
 #include <util/threading.h>
 #include <util/platform.h>
 #include <util/util.hpp>
@@ -40,6 +39,10 @@
 #include <d3d11.h>
 #endif
 
+#if BROWSER_FRONTEND_API_SUPPORT_ENABLED
+#include <obs-frontend-api.h>
+#endif
+
 OBS_DECLARE_MODULE()
 OBS_MODULE_USE_DEFAULT_LOCALE("obs-browser", "en-US")
 
@@ -315,6 +318,7 @@ void RegisterBrowserSource()
 
 extern void DispatchJSEvent(const char *eventName, const char *jsonString);
 
+#if BROWSER_FRONTEND_API_SUPPORT_ENABLED
 static void handle_obs_frontend_event(enum obs_frontend_event event, void *)
 {
 	switch (event) {
@@ -363,6 +367,7 @@ static void handle_obs_frontend_event(enum obs_frontend_event event, void *)
 	default:;
 	}
 }
+#endif
 
 #ifdef _WIN32
 static inline void EnumAdapterCount()
@@ -401,7 +406,11 @@ bool obs_module_load(void)
 	EnumAdapterCount();
 #endif
 	RegisterBrowserSource();
+
+#if BROWSER_FRONTEND_API_SUPPORT_ENABLED
 	obs_frontend_add_event_callback(handle_obs_frontend_event, nullptr);
+#endif
+
 
 #if EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED
 	obs_data_t *private_data = obs_get_private_data();