Skip to content

Add Event::Minimized and Event::Maximized for win32, X11, and MacOS platforms#3650

Open
raustin9 wants to merge 15 commits into
SFML:masterfrom
raustin9:feature/window-min-max-events
Open

Add Event::Minimized and Event::Maximized for win32, X11, and MacOS platforms#3650
raustin9 wants to merge 15 commits into
SFML:masterfrom
raustin9:feature/window-min-max-events

Conversation

@raustin9
Copy link
Copy Markdown

@raustin9 raustin9 commented Jan 25, 2026

  • Has this change been discussed on the forum or in an issue before?
  • Does the code follow the SFML Code Style Guide?
  • Have you provided some example/test code for your changes?

Description

Add events to trigger on window minimization and maximization for Windows, MacOS, and Linux platforms.
Event::Minimize triggers when the window is minimized, and Event::Maximized triggers on window maximization.

This PR is related to the issue #3294

Tasks

  • Tested on Linux: This needs a bit further verification. The window manager on WSL does not comply with the typical Linux, ones, so there should be some further testing to see if the events (particularly Minimized) trigger properly.
  • Tested on Windows
  • Tested on macOS
  • Tested on iOS
  • Tested on Android

How to test this PR?

Open a window on the supported platforms, and detect whether the minimized and maximized events are triggering. This is easiest done through an example similar to the one below. The minimize event should trigger when the minimize button is clicked on the window, and the maximized event should trigger when the maximize button is clicked.

Minimal example:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode({1280, 720}), "Minimal, complete and verifiable example");
    window.setFramerateLimit(60);

    while (window.isOpen())
    {
        while (const std::optional event = window.pollEvent())
        {
            if (event->is<sf::Event::Closed>())
                window.close();
            if (event->is<sf::Event::Minimized>()) std::cout << "Minimized\n";
            if (event->is<sf::Event::Maximized>()) std::cout << "Maximized\n";
        }

        window.clear();
        window.display();
    }
}


return false;
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Was not sure if the similar behavior of isMinimized and isMaximized should be abstracted into a separate function to check values of atoms

@JonnyPtn
Copy link
Copy Markdown
Contributor

Could you also add them to the events_example for easier testing please?

@eXpl0it3r
Copy link
Copy Markdown
Member

How do you determine when a window is restored, i.e. un-minimized or un-maximized?

@raustin9
Copy link
Copy Markdown
Author

raustin9 commented Jan 26, 2026

How do you determine when a window is restored, i.e. un-minimized or un-maximized?

On win32 I check for the SIZE_RESTORED case.
On X11, on max/unmax it triggers a resize event which fires the standard sf::Event::Resized{...} with the correct size.
Similar behavior occurs on MacOS where the resize is triggered on min/max which corrects to proper size.

Should the Maximized and Minimized events hold a value like this

struct Minimized
{
  bool restored;
};

that can be checked?

@raustin9
Copy link
Copy Markdown
Author

Could you also add them to the events_example for easier testing please?

Done!

@JonnyPtn
Copy link
Copy Markdown
Contributor

JonnyPtn commented Feb 9, 2026

I plan to test this on mac at some point, but curious in your tests if you tested what happens when you use the system spaces fullscreen (pushing the fullscreen titlebar button, fn+f shortcut or view -> fullscreen menu option)?

Currently that is a separate fullscreen mode to the one used by SFML code which #3662 aims to address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants