Skip to content

Commit

Permalink
UI: Add obs_frontend_close_main_window()
Browse files Browse the repository at this point in the history
Adds the ability to close the main window from the frontend API.
The behaviour is the same as clicking the Exit button in OBS Studio.
  • Loading branch information
BenJuan26 committed Jul 26, 2024
1 parent f2f4582 commit 3cc2020
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions UI/api-interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions UI/obs-frontend-api/obs-frontend-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ static char **convert_string_list(vector<string> &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()
Expand Down
1 change: 1 addition & 0 deletions UI/obs-frontend-api/obs-frontend-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions UI/obs-frontend-api/obs-frontend-internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions docs/sphinx/reference-frontend-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3cc2020

Please sign in to comment.