Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Add obs_frontend_close_main_window() #8889

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BenJuan26
Copy link
Contributor

@BenJuan26 BenJuan26 commented May 11, 2023

Description

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.

Motivation and Context

This is useful for scripting, where OBS is mainly run from the system tray and controlled through the script, i.e. through obs-websocket. Currently, the only way to close OBS from a script is to have the OS terminate the process. This is obviously not ideal: the program doesn't get the chance to properly free up resources, and in the case of Windows, the icon hangs around the system tray until it is moused-over.

Link to feature suggestion: https://ideas.obsproject.com/posts/2225/allow-clean-shutdown-via-api

How Has This Been Tested?

OS: Windows
CPU: Intel i7 12700K
GPU: Gigabyte Nvidia GeForce RTX 3070 Ti 8 GB
RAM: 32GB

For the sake of simplicity, I hijacked the StartStream handler of obs-websocket to instead call obs_frontend_close_main_window(), then used OBS-web to trigger the handler. The OBS Studio window closed, and the log indicated that the shutdown process completed nominally, just as it would have if the Exit button was clicked.

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Documentation (a change to documentation pages)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@PatTheMav
Copy link
Member

Is this supposed to end the application? Because on macOS an application is not automatically terminated just because it has no active windows - that’s an opt-in behaviour. It could be that Qt behaves this way in our case, but that needs to be verified.

@BenJuan26
Copy link
Contributor Author

For the use case that I'm targeting, yes, the intention is to end the application.

I just tested the release version of OBS on macOS, and indeed, clicking the Exit button and closing the window both end the application.

@derrod
Copy link
Member

derrod commented May 11, 2023

Is this supposed to end the application? Because on macOS an application is not automatically terminated just because it has no active windows - that’s an opt-in behaviour. It could be that Qt behaves this way in our case, but that needs to be verified.

Our main window's close event handler does some cleanup and ultimately calls qApplication::quit()

QMetaObject::invokeMethod(App(), "quit", Qt::QueuedConnection);

@RytoEX RytoEX added the New Feature New feature or plugin label May 11, 2023
Copy link
Contributor

@CodeYan01 CodeYan01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Warchamp7
Copy link
Member

Warchamp7 commented Apr 7, 2024

I'd like us to include a log line indicating when something has closed OBS this way.

How does this interact with things that prevent closing the window such as running outputs?

@asoulliereHT
Copy link

I'd like us to include a log line indicating when something has closed OBS this way.

How does this interact with things that prevent closing the window such as running outputs?

"Closes the main window. If there are active outputs, the user will be prompted to confirm before closing."

@BenJuan26 BenJuan26 force-pushed the close_main_window branch 2 times, most recently from 3cc2020 to b3316e2 Compare July 26, 2024 03:36
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.
@BenJuan26 BenJuan26 force-pushed the close_main_window branch from b3316e2 to a841c9f Compare July 26, 2024 04:31
@BenJuan26
Copy link
Contributor Author

@Warchamp7 Log line added.

How does this interact with things that prevent closing the window such as running outputs?

This was answered in the next comment. Let me know if you have any more questions/issues.

Copy link
Member

@Warchamp7 Warchamp7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine from my end with the log line added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Feature New feature or plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants