Skip to content

Instantly share code, notes, and snippets.

@dtcooper
Last active June 27, 2018 05:11
Show Gist options
  • Save dtcooper/1aaa48b779ca4c5181fe46bba874a032 to your computer and use it in GitHub Desktop.
Save dtcooper/1aaa48b779ca4c5181fe46bba874a032 to your computer and use it in GitHub Desktop.
diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp
index 2db37b58..b4f90c72 100644
--- a/UI/obs-app.cpp
+++ b/UI/obs-app.cpp
@@ -1981,6 +1981,8 @@ int main(int argc, char *argv[])
move_to_xdg();
#endif
+ obs_set_cmdline_args(argc, argv);
+
for (int i = 1; i < argc; i++) {
if (arg_is(argv[i], "--portable", "-p")) {
portable_mode = true;
diff --git a/libobs/obs.c b/libobs/obs.c
index c324ef78..e2dd5cfe 100644
--- a/libobs/obs.c
+++ b/libobs/obs.c
@@ -935,6 +935,43 @@ const char *obs_get_version_string(void)
return OBS_VERSION;
}
+static struct obs_cmdline_args cmdline_args = {0, NULL};
+void obs_set_cmdline_args(int argc, char **argv)
+{
+
+ char *data;
+ size_t len;
+ int i;
+
+ /* Once argc is set (non-zero) we shouldn't call again */
+ if (cmdline_args.argc)
+ return;
+
+ cmdline_args.argc = argc;
+
+ /* Safely copy over argv */
+ len = 0;
+ for (i = 0; i < argc; i++)
+ len += strlen(argv[i]) + 1;
+
+ cmdline_args.argv = bmalloc(sizeof(char *) * (argc + 1) + len);
+ data = (char *) cmdline_args.argv + sizeof(char *) * (argc + 1);
+
+ for (i = 0; i < argc; i++) {
+ cmdline_args.argv[i] = data;
+ len = strlen(argv[i]) + 1;
+ memcpy(data, argv[i], len);
+ data += len;
+ }
+
+ cmdline_args.argv[argc] = NULL;
+}
+
+struct obs_cmdline_args obs_get_cmdline_args(void)
+{
+ return cmdline_args;
+}
+
void obs_set_locale(const char *locale)
{
struct obs_module *module;
diff --git a/libobs/obs.h b/libobs/obs.h
index afb8d3e3..a38693ed 100644
--- a/libobs/obs.h
+++ b/libobs/obs.h
@@ -239,6 +239,12 @@ struct obs_source_frame {
bool prev_frame;
};
+/** Access to the argc/argv used to start OBS. What you see is what you get. */
+struct obs_cmdline_args {
+ int argc;
+ char **argv;
+};
+
/* ------------------------------------------------------------------------- */
/* OBS context */
@@ -291,6 +297,16 @@ EXPORT uint32_t obs_get_version(void);
/** @return The current core version string */
EXPORT const char *obs_get_version_string(void);
+/** Sets things up for calls to obs_get_cmdline_args. Called once at startup. */
+EXPORT void obs_set_cmdline_args(int argc, char **argv);
+
+/**
+ * Get the argc/argv used to start OBS
+ * @returns A obs_cmdline_args struct with the argc/argv used to start OBS.
+ * Don't modify this or you'll mess things up for other callers.
+ */
+EXPORT struct obs_cmdline_args obs_get_cmdline_args(void);
+
/**
* Sets a new locale to use for modules. This will call obs_module_set_locale
* for each module with the new locale.
Submodule plugins/obs-browser contains modified content
diff --git a/plugins/obs-browser/obs-browser-plugin.cpp b/plugins/obs-browser/obs-browser-plugin.cpp
index 5f33b19..2bc7836 100644
--- a/plugins/obs-browser/obs-browser-plugin.cpp
+++ b/plugins/obs-browser/obs-browser-plugin.cpp
@@ -147,9 +147,13 @@ static void BrowserManagerThread(void)
path += "//cef-bootstrap";
#ifdef _WIN32
path += ".exe";
+ CefMainArgs args;
+#else
+ /* On non-windows platforms, ie macOS, we'll want to pass thru flags to CEF */
+ struct obs_cmdline_args cmdline_args = obs_get_cmdline_args();
+ CefMainArgs args(cmdline_args.argc, cmdline_args.argv);
#endif
- CefMainArgs args;
CefSettings settings;
settings.log_severity = LOGSEVERITY_VERBOSE;
settings.windowless_rendering_enabled = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment