From 3460db4b34dd6e2735ae594b251f5859de7bcb85 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sat, 9 Dec 2023 11:40:05 -0700 Subject: [PATCH] Request fullscreen via state instead of style --- include/SFML/Window/WindowStyle.hpp | 13 ++++++------- src/SFML/Window/DRM/WindowImplDRM.cpp | 6 +++++- src/SFML/Window/DRM/WindowImplDRM.hpp | 5 +++-- src/SFML/Window/Unix/WindowImplX11.cpp | 4 ++-- src/SFML/Window/Unix/WindowImplX11.hpp | 5 +++-- src/SFML/Window/Win32/WindowImplWin32.cpp | 4 ++-- src/SFML/Window/Win32/WindowImplWin32.hpp | 3 ++- src/SFML/Window/Window.cpp | 10 +++++----- src/SFML/Window/WindowBase.cpp | 10 +++++----- src/SFML/Window/WindowImpl.cpp | 9 +++++++-- src/SFML/Window/WindowImpl.hpp | 3 +++ src/SFML/Window/macOS/SFWindowController.h | 4 +++- src/SFML/Window/macOS/SFWindowController.mm | 4 ++-- src/SFML/Window/macOS/WindowImplCocoa.hpp | 6 ++++-- src/SFML/Window/macOS/WindowImplCocoa.mm | 4 ++-- 15 files changed, 54 insertions(+), 36 deletions(-) diff --git a/include/SFML/Window/WindowStyle.hpp b/include/SFML/Window/WindowStyle.hpp index 0ed86e7c90..acee94b0d4 100644 --- a/include/SFML/Window/WindowStyle.hpp +++ b/include/SFML/Window/WindowStyle.hpp @@ -36,11 +36,10 @@ namespace Style //////////////////////////////////////////////////////////// enum { - None = 0, //!< No border / title bar (this flag and all others are mutually exclusive) - Titlebar = 1 << 0, //!< Title bar + fixed border - Resize = 1 << 1, //!< Title bar + resizable border + maximize button - Close = 1 << 2, //!< Title bar + close button - Fullscreen = 1 << 3, //!< Fullscreen mode (this flag and all others are mutually exclusive) + None = 0, //!< No border / title bar (this flag and all others are mutually exclusive) + Titlebar = 1 << 0, //!< Title bar + fixed border + Resize = 1 << 1, //!< Title bar + resizable border + maximize button + Close = 1 << 2, //!< Title bar + close button Default = Titlebar | Resize | Close //!< Default window style }; @@ -54,10 +53,10 @@ enum //////////////////////////////////////////////////////////// enum class State { - Windowed, //!< + Windowed, //!< + Fullscreen, //!< // Minimized, //!< // Maximized, //!< - // Fullscreen, //!< // Hidden //!< }; diff --git a/src/SFML/Window/DRM/WindowImplDRM.cpp b/src/SFML/Window/DRM/WindowImplDRM.cpp index b0c0c9cd7d..c0e8a89d0b 100644 --- a/src/SFML/Window/DRM/WindowImplDRM.cpp +++ b/src/SFML/Window/DRM/WindowImplDRM.cpp @@ -70,7 +70,11 @@ WindowImplDRM::WindowImplDRM(WindowHandle /*handle*/) //////////////////////////////////////////////////////////// -WindowImplDRM::WindowImplDRM(VideoMode mode, const String& /*title*/, unsigned long /*style*/, const ContextSettings& /*settings*/) : +WindowImplDRM::WindowImplDRM(VideoMode mode, + const String& /*title*/, + unsigned long /*style*/, + State /*state*/, + const ContextSettings& /*settings*/) : m_size(mode.size) { sf::priv::InputImpl::setTerminalConfig(); diff --git a/src/SFML/Window/DRM/WindowImplDRM.hpp b/src/SFML/Window/DRM/WindowImplDRM.hpp index 4b83e3ab35..b685bfc1a6 100644 --- a/src/SFML/Window/DRM/WindowImplDRM.hpp +++ b/src/SFML/Window/DRM/WindowImplDRM.hpp @@ -52,11 +52,12 @@ class WindowImplDRM : public WindowImpl /// /// \param mode Video mode to use /// \param title Title of the window - /// \param style Window style (resizable, fixed, or fullscreen) + /// \param style Window style (resizable or fixed) + /// \param state Window state /// \param settings Additional settings for the underlying OpenGL context /// //////////////////////////////////////////////////////////// - WindowImplDRM(VideoMode mode, const String& title, unsigned long style, const ContextSettings& settings); + WindowImplDRM(VideoMode mode, const String& title, unsigned long style, State state, const ContextSettings& settings); //////////////////////////////////////////////////////////// /// \brief Destructor diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 81a60cc79c..b8c1cd93ad 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -465,9 +465,9 @@ WindowImplX11::WindowImplX11(WindowHandle handle) : m_isExternal(true) //////////////////////////////////////////////////////////// -WindowImplX11::WindowImplX11(VideoMode mode, const String& title, unsigned long style, const ContextSettings& settings) : +WindowImplX11::WindowImplX11(VideoMode mode, const String& title, unsigned long style, State state, const ContextSettings& settings) : m_isExternal(false), -m_fullscreen((style & Style::Fullscreen) != 0), +m_fullscreen(state == State::Fullscreen), m_cursorGrabbed(m_fullscreen) { using namespace WindowImplX11Impl; diff --git a/src/SFML/Window/Unix/WindowImplX11.hpp b/src/SFML/Window/Unix/WindowImplX11.hpp index 59281046e2..e73f9f9db0 100644 --- a/src/SFML/Window/Unix/WindowImplX11.hpp +++ b/src/SFML/Window/Unix/WindowImplX11.hpp @@ -59,11 +59,12 @@ class WindowImplX11 : public WindowImpl /// /// \param mode Video mode to use /// \param title Title of the window - /// \param style Window style (resizable, fixed, or fullscreen) + /// \param style Window style (resizable or fixed) + /// \param state Window state /// \param settings Additional settings for the underlying OpenGL context /// //////////////////////////////////////////////////////////// - WindowImplX11(VideoMode mode, const String& title, unsigned long style, const ContextSettings& settings); + WindowImplX11(VideoMode mode, const String& title, unsigned long style, State state, const ContextSettings& settings); //////////////////////////////////////////////////////////// /// \brief Destructor diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 57a0fe0214..4fe491727c 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -150,9 +150,9 @@ WindowImplWin32::WindowImplWin32(WindowHandle handle) : m_handle(handle) //////////////////////////////////////////////////////////// -WindowImplWin32::WindowImplWin32(VideoMode mode, const String& title, std::uint32_t style, const ContextSettings& /*settings*/) : +WindowImplWin32::WindowImplWin32(VideoMode mode, const String& title, std::uint32_t style, State state, const ContextSettings& /*settings*/) : m_lastSize(mode.size), -m_fullscreen((style & Style::Fullscreen) != 0), +m_fullscreen(state == State::Fullscreen), m_cursorGrabbed(m_fullscreen) { // Set that this process is DPI aware and can handle DPI scaling diff --git a/src/SFML/Window/Win32/WindowImplWin32.hpp b/src/SFML/Window/Win32/WindowImplWin32.hpp index 32da119603..3c0afa464b 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.hpp +++ b/src/SFML/Window/Win32/WindowImplWin32.hpp @@ -60,10 +60,11 @@ class WindowImplWin32 : public WindowImpl /// \param mode Video mode to use /// \param title Title of the window /// \param style Window style + /// \param state Window state /// \param settings Additional settings for the underlying OpenGL context /// //////////////////////////////////////////////////////////// - WindowImplWin32(VideoMode mode, const String& title, std::uint32_t style, const ContextSettings& settings); + WindowImplWin32(VideoMode mode, const String& title, std::uint32_t style, State state, const ContextSettings& settings); //////////////////////////////////////////////////////////// /// \brief Destructor diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index b3b43f9953..d731ad521e 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -72,19 +72,19 @@ void Window::create(VideoMode mode, const String& title, std::uint32_t style, St //////////////////////////////////////////////////////////// -void Window::create(VideoMode mode, const String& title, std::uint32_t style, State /* state */, const ContextSettings& settings) +void Window::create(VideoMode mode, const String& title, std::uint32_t style, State state, const ContextSettings& settings) { // Destroy the previous window implementation close(); // Fullscreen style requires some tests - if (style & Style::Fullscreen) + if (state == State::Fullscreen) { // Make sure there's not already a fullscreen window (only one is allowed) if (getFullscreenWindow()) { err() << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl; - style &= ~static_cast(Style::Fullscreen); + state = State::Windowed; } else { @@ -103,7 +103,7 @@ void Window::create(VideoMode mode, const String& title, std::uint32_t style, St // Check validity of style according to the underlying platform #if defined(SFML_SYSTEM_IOS) || defined(SFML_SYSTEM_ANDROID) - if (style & Style::Fullscreen) + if (state == State::Fullscreen) style &= ~static_cast(Style::Titlebar); else style |= Style::Titlebar; @@ -113,7 +113,7 @@ void Window::create(VideoMode mode, const String& title, std::uint32_t style, St #endif // Recreate the window implementation - m_impl = priv::WindowImpl::create(mode, title, style, settings); + m_impl = priv::WindowImpl::create(mode, title, style, state, settings); // Recreate the context m_context = priv::GlContext::create(settings, *m_impl, mode.bitsPerPixel); diff --git a/src/SFML/Window/WindowBase.cpp b/src/SFML/Window/WindowBase.cpp index 15cae97805..bcbd2c6505 100644 --- a/src/SFML/Window/WindowBase.cpp +++ b/src/SFML/Window/WindowBase.cpp @@ -76,19 +76,19 @@ WindowBase::~WindowBase() //////////////////////////////////////////////////////////// -void WindowBase::create(VideoMode mode, const String& title, std::uint32_t style, State /* state */) +void WindowBase::create(VideoMode mode, const String& title, std::uint32_t style, State state) { // Destroy the previous window implementation close(); // Fullscreen style requires some tests - if (style & Style::Fullscreen) + if (state == State::Fullscreen) { // Make sure there's not already a fullscreen window (only one is allowed) if (getFullscreenWindow()) { err() << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl; - style &= ~static_cast(Style::Fullscreen); + state = State::Windowed; } else { @@ -106,7 +106,7 @@ void WindowBase::create(VideoMode mode, const String& title, std::uint32_t style // Check validity of style according to the underlying platform #if defined(SFML_SYSTEM_IOS) || defined(SFML_SYSTEM_ANDROID) - if (style & Style::Fullscreen) + if (state == State::Fullscreen) style &= ~static_cast(Style::Titlebar); else style |= Style::Titlebar; @@ -116,7 +116,7 @@ void WindowBase::create(VideoMode mode, const String& title, std::uint32_t style #endif // Recreate the window implementation - m_impl = priv::WindowImpl::create(mode, title, style, ContextSettings(0, 0, 0, 0, 0, 0xFFFFFFFF, false)); + m_impl = priv::WindowImpl::create(mode, title, style, state, ContextSettings(0, 0, 0, 0, 0, 0xFFFFFFFF, false)); // Perform common initializations initialize(); diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index 0f0a00eec8..9a6ebcbf5e 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -101,9 +101,14 @@ struct WindowImpl::JoystickStatesImpl }; //////////////////////////////////////////////////////////// -std::unique_ptr WindowImpl::create(VideoMode mode, const String& title, std::uint32_t style, const ContextSettings& settings) +std::unique_ptr WindowImpl::create( + VideoMode mode, + const String& title, + std::uint32_t style, + State state, + const ContextSettings& settings) { - return std::make_unique(mode, title, style, settings); + return std::make_unique(mode, title, style, state, settings); } diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index 1cf6ddf114..eb102553f9 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -64,6 +65,7 @@ class WindowImpl /// \param mode Video mode to use /// \param title Title of the window /// \param style Window style + /// \param state Window state /// \param settings Additional settings for the underlying OpenGL context /// /// \return Pointer to the created window @@ -72,6 +74,7 @@ class WindowImpl static std::unique_ptr create(VideoMode mode, const String& title, std::uint32_t style, + State state, const ContextSettings& settings); //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/macOS/SFWindowController.h b/src/SFML/Window/macOS/SFWindowController.h index 02f1147b75..d232dc81d2 100644 --- a/src/SFML/Window/macOS/SFWindowController.h +++ b/src/SFML/Window/macOS/SFWindowController.h @@ -27,6 +27,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #import //////////////////////////////////////////////////////////// @@ -80,10 +81,11 @@ class WindowImplCocoa; /// /// \param mode Video mode /// \param style Window's style, as described by sf::Style +/// \param state Window's state /// /// \return an initialized controller /// //////////////////////////////////////////////////////////// -- (id)initWithMode:(const sf::VideoMode&)mode andStyle:(unsigned long)style; +- (id)initWithMode:(const sf::VideoMode&)mode andStyle:(unsigned long)style andState:(sf::State)state; @end diff --git a/src/SFML/Window/macOS/SFWindowController.mm b/src/SFML/Window/macOS/SFWindowController.mm index 17f8d58849..1b9fdb969e 100644 --- a/src/SFML/Window/macOS/SFWindowController.mm +++ b/src/SFML/Window/macOS/SFWindowController.mm @@ -135,7 +135,7 @@ - (id)initWithWindow:(NSWindow*)window //////////////////////////////////////////////////////// -- (id)initWithMode:(const sf::VideoMode&)mode andStyle:(unsigned long)style +- (id)initWithMode:(const sf::VideoMode&)mode andStyle:(unsigned long)style andState:(sf::State)state { // If we are not on the main thread we stop here and advice the user. if ([NSThread currentThread] != [NSThread mainThread]) @@ -154,7 +154,7 @@ - (id)initWithMode:(const sf::VideoMode&)mode andStyle:(unsigned long)style m_window = nil; m_oglView = nil; m_requester = nil; - m_fullscreen = ((style & sf::Style::Fullscreen) != 0) ? YES : NO; + m_fullscreen = (state == sf::State::Fullscreen) ? YES : NO; m_restoreResize = NO; m_highDpi = NO; diff --git a/src/SFML/Window/macOS/WindowImplCocoa.hpp b/src/SFML/Window/macOS/WindowImplCocoa.hpp index 03f9043b1b..605e85fa78 100644 --- a/src/SFML/Window/macOS/WindowImplCocoa.hpp +++ b/src/SFML/Window/macOS/WindowImplCocoa.hpp @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -80,11 +81,12 @@ class WindowImplCocoa : public WindowImpl /// /// \param mode Video mode to use /// \param title Title of the window - /// \param style Window style (resizeable, fixed, or fullscreen) + /// \param style Window style (resizeable or fixed) + /// \param state Window state /// \param settings Additional settings for the underlying OpenGL context /// //////////////////////////////////////////////////////////// - WindowImplCocoa(VideoMode mode, const String& title, unsigned long style, const ContextSettings& settings); + WindowImplCocoa(VideoMode mode, const String& title, unsigned long style, State state, const ContextSettings& settings); //////////////////////////////////////////////////////////// /// \brief Destructor diff --git a/src/SFML/Window/macOS/WindowImplCocoa.mm b/src/SFML/Window/macOS/WindowImplCocoa.mm index 36876b8944..f0b5739516 100644 --- a/src/SFML/Window/macOS/WindowImplCocoa.mm +++ b/src/SFML/Window/macOS/WindowImplCocoa.mm @@ -118,13 +118,13 @@ void showMouseCursor() //////////////////////////////////////////////////////////// -WindowImplCocoa::WindowImplCocoa(VideoMode mode, const String& title, unsigned long style, const ContextSettings& /*settings*/) +WindowImplCocoa::WindowImplCocoa(VideoMode mode, const String& title, unsigned long style, State state, const ContextSettings& /*settings*/) { const AutoreleasePool pool; // Transform the app process. setUpProcess(); - m_delegate = [[SFWindowController alloc] initWithMode:mode andStyle:style]; + m_delegate = [[SFWindowController alloc] initWithMode:mode andStyle:style andState:state]; [m_delegate changeTitle:sfStringToNSString(title)]; [m_delegate setRequesterTo:this];