diff --git a/UI/api-interface.cpp b/UI/api-interface.cpp index 8fb3bea3a3816d..697a8fc2766c47 100644 --- a/UI/api-interface.cpp +++ b/UI/api-interface.cpp @@ -58,6 +58,13 @@ struct OBSStudioAPI : obs_frontend_callbacks { inline OBSStudioAPI(OBSBasic *main_) : main(main_) {} + void obs_frontend_close_main_window(void) override + { + blog(LOG_INFO, + "Closing main window via the API..."); + QMetaObject::invokeMethod(main, "close"); + } + void *obs_frontend_get_main_window(void) override { return (void *)main; diff --git a/UI/obs-frontend-api/obs-frontend-api.cpp b/UI/obs-frontend-api/obs-frontend-api.cpp index 34747fc07b5ab1..fc35082829b3a3 100644 --- a/UI/obs-frontend-api/obs-frontend-api.cpp +++ b/UI/obs-frontend-api/obs-frontend-api.cpp @@ -57,6 +57,12 @@ static char **convert_string_list(vector &strings) /* ------------------------------------------------------------------------- */ +void obs_frontend_close_main_window(void) +{ + if (callbacks_valid()) + c->obs_frontend_close_main_window(); +} + void *obs_frontend_get_main_window(void) { return !!callbacks_valid() ? c->obs_frontend_get_main_window() diff --git a/UI/obs-frontend-api/obs-frontend-api.h b/UI/obs-frontend-api/obs-frontend-api.h index a0913e683359f1..d01bcbae398c19 100644 --- a/UI/obs-frontend-api/obs-frontend-api.h +++ b/UI/obs-frontend-api/obs-frontend-api.h @@ -98,6 +98,7 @@ obs_frontend_source_list_free(struct obs_frontend_source_list *source_list) #ifndef SWIG +EXPORT void obs_frontend_close_main_window(void); EXPORT void *obs_frontend_get_main_window(void); EXPORT void *obs_frontend_get_main_window_handle(void); EXPORT void *obs_frontend_get_system_tray(void); diff --git a/UI/obs-frontend-api/obs-frontend-internal.hpp b/UI/obs-frontend-api/obs-frontend-internal.hpp index 90a0e06ea9dd5b..d178847b5aaa38 100644 --- a/UI/obs-frontend-api/obs-frontend-internal.hpp +++ b/UI/obs-frontend-api/obs-frontend-internal.hpp @@ -7,6 +7,7 @@ struct obs_frontend_callbacks { virtual ~obs_frontend_callbacks() {} + virtual void obs_frontend_close_main_window(void) = 0; virtual void *obs_frontend_get_main_window(void) = 0; virtual void *obs_frontend_get_main_window_handle(void) = 0; virtual void *obs_frontend_get_system_tray(void) = 0; diff --git a/docs/sphinx/reference-frontend-api.rst b/docs/sphinx/reference-frontend-api.rst index a5ee4ec03fa18b..8e0fa1af85cd2a 100644 --- a/docs/sphinx/reference-frontend-api.rst +++ b/docs/sphinx/reference-frontend-api.rst @@ -242,6 +242,13 @@ Functions --------------------------------------- +.. function:: void obs_frontend_close_main_window(void) + + Closes the main window. If there are active outputs, the user will be + prompted to confirm before closing. + +--------------------------------------- + .. function:: void *obs_frontend_get_main_window(void) :return: The QMainWindow pointer to the OBS Studio window