Skip to content

Add support for getting and setting window states#3496

Draft
eXpl0it3r wants to merge 2 commits into
masterfrom
feature/set_states
Draft

Add support for getting and setting window states#3496
eXpl0it3r wants to merge 2 commits into
masterfrom
feature/set_states

Conversation

@eXpl0it3r
Copy link
Copy Markdown
Member

@eXpl0it3r eXpl0it3r commented Apr 24, 2025

Description

This is the first step in the larger feature set of handling window states in a new way:

  1. Implement Fullscreen/Windowed as a state rather than a style (see Add sf::State for specifying fullscreen or floating windows #2818)
  2. Implement a way to get and set window states separate from the constructor and create() function (this PR)
  3. Implement sf::State::Hidden and deprecate setVisible
  4. Implement sf::State::Minimized and sf::State::Maximized

This PR is related to the discussions in issue #744 and closely related to @Foaly's reference implementation. See also the solution design on states.

Tasks

  • Finalize API design
  • Finish implementation on Linux
  • Finish implementation on macOS
  • Finish implementation on iOS
  • Finish implementation on Android
  • Tested on Linux
  • Tested on Windows
  • Tested on macOS
  • Tested on iOS
  • Tested on Android

How to test this PR?

I've extended the window example, so you can try the fullscreen/windowed toggling with the F1 key.

Otherwise sf::WindowBase implements the following two functions:

  • setState(sf::State)
  • sf::State getState()

{
if (window.getState() == sf::State::Windowed)
{
window.setState(sf::State::Fullscreen);
Copy link
Copy Markdown
Member Author

@eXpl0it3r eXpl0it3r Apr 24, 2025

Choose a reason for hiding this comment

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

Going over the past discussions, I can't find a point where it was thoroughly discussed how to address the issue of changing state without being able to change the resolution/videomode. setState seems simple enough, but in most cases when switching from windowed to fullscreen, you actually want to pick a different window size, with the only exception if you were already using a borderless "fullscreen" window.
Additionally, the reverse is also true, when you start with a fullscreen window at a fullscreen resolution and you switch to a floating window, you usually don't want the same resolution.

One proposal would be to add a second overload setState(sf::State, sf::VideoMode) or setState(sf::State, sf::Vector2i). Then you define default behavior when there's no size provided (e.g. use the existing window size / use the default fullscreen video mode). Question then is, what you do once adding sf::State::Minimized and sf::State::Maximized, because those don't really work with different window sizes.

Laurent's comment from way back indicates, that he imagined, that users then would just start out with a hidden window and set the properties before showing it. This solves the potential issue of the initial creation, but leaves the question of toggling unanswered.

Comments and discussion are appreciated 😉

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've created an alternative/extended API design as a separate PR: #3501

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would say leave them separate - even if we expect many use cases will want to set the size at the same time as the state I don't think it's worth the extra ambiguity just to save them an extra function call

Also consider mobile/console platforms where these states mean other things (e.g. on iOS fullscreen may be used to indicate ignoring the safe areas) which may also trigger a window resize from the OS so the extra size parameter would become even more ambiguous

@eXpl0it3r eXpl0it3r force-pushed the feature/set_states branch from f043ec3 to d5a0e17 Compare May 3, 2025 10:47
@github-project-automation github-project-automation Bot moved this to Planned in SFML 3.2.0 Jun 19, 2025
@eXpl0it3r eXpl0it3r added this to the 3.2 milestone Aug 28, 2025
@eXpl0it3r eXpl0it3r force-pushed the feature/set_states branch 2 times, most recently from b2262de to b8751f6 Compare April 22, 2026 07:35
@eXpl0it3r eXpl0it3r force-pushed the feature/set_states branch 4 times, most recently from 2842665 to efcb4c9 Compare May 6, 2026 07:44
@eXpl0it3r eXpl0it3r force-pushed the feature/set_states branch from efcb4c9 to 86c6ba1 Compare May 8, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Planned

Development

Successfully merging this pull request may close these issues.

3 participants