From 7556d1be78113defd4ef69f32d24fe583bf2692d Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Tue, 26 Dec 2023 17:16:06 -0600 Subject: [PATCH] Move fullscreen window bookkeeping to a lower level --- include/SFML/Window/WindowBase.hpp | 16 ------------- src/SFML/Window/Window.cpp | 5 +--- src/SFML/Window/WindowBase.cpp | 37 +++--------------------------- src/SFML/Window/WindowImpl.cpp | 32 ++++++++++++++++++++++++-- src/SFML/Window/WindowImpl.hpp | 14 +++++++++++ 5 files changed, 48 insertions(+), 56 deletions(-) diff --git a/include/SFML/Window/WindowBase.hpp b/include/SFML/Window/WindowBase.hpp index 6955f8bba..a015b1374 100644 --- a/include/SFML/Window/WindowBase.hpp +++ b/include/SFML/Window/WindowBase.hpp @@ -512,22 +512,6 @@ private: //////////////////////////////////////////////////////////// void initialize(); - //////////////////////////////////////////////////////////// - /// \brief Get the fullscreen window - /// - /// \return The fullscreen window or a null pointer if there is none - /// - //////////////////////////////////////////////////////////// - const WindowBase* getFullscreenWindow(); - - //////////////////////////////////////////////////////////// - /// \brief Set a window as the fullscreen window - /// - /// \param window Window to set as fullscreen window - /// - //////////////////////////////////////////////////////////// - void setFullscreenWindow(const WindowBase* window); - //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 8ee5979eb..b8ee1ded1 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -63,10 +63,7 @@ Window::Window(WindowHandle handle, const ContextSettings& settings) //////////////////////////////////////////////////////////// -Window::~Window() -{ - close(); -} +Window::~Window() = default; //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/WindowBase.cpp b/src/SFML/Window/WindowBase.cpp index a522b0cd3..e3872d183 100644 --- a/src/SFML/Window/WindowBase.cpp +++ b/src/SFML/Window/WindowBase.cpp @@ -46,16 +46,6 @@ #include -namespace -{ -// A nested named namespace is used here to allow unity builds of SFML. -namespace WindowsBaseImpl -{ -const sf::WindowBase* fullscreenWindow = nullptr; -} // namespace WindowsBaseImpl -} // namespace - - namespace sf { //////////////////////////////////////////////////////////// @@ -84,10 +74,7 @@ WindowBase::WindowBase(WindowHandle handle) //////////////////////////////////////////////////////////// -WindowBase::~WindowBase() -{ - WindowBase::close(); -} +WindowBase::~WindowBase() = default; //////////////////////////////////////////////////////////// @@ -132,10 +119,6 @@ void WindowBase::close() { // Delete the window implementation m_impl.reset(); - - // Update the fullscreen window - if (this == getFullscreenWindow()) - setFullscreenWindow(nullptr); } @@ -385,7 +368,7 @@ void WindowBase::create(VideoMode mode, std::uint32_t& style, State& state) if (state == State::Fullscreen) { // Make sure there's not already a fullscreen window (only one is allowed) - if (getFullscreenWindow()) + if (m_impl->getFullscreenWindow()) { err() << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl; state = State::Windowed; @@ -403,7 +386,7 @@ void WindowBase::create(VideoMode mode, std::uint32_t& style, State& state) } // Update the fullscreen window - setFullscreenWindow(this); + m_impl->setFullscreenWindow(); } } @@ -450,18 +433,4 @@ void WindowBase::initialize() onCreate(); } - -//////////////////////////////////////////////////////////// -const WindowBase* WindowBase::getFullscreenWindow() -{ - return WindowsBaseImpl::fullscreenWindow; -} - - -//////////////////////////////////////////////////////////// -void WindowBase::setFullscreenWindow(const WindowBase* window) -{ - WindowsBaseImpl::fullscreenWindow = window; -} - } // namespace sf diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index f13e541b6..208e71343 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -90,9 +90,19 @@ using WindowImplType = sf::priv::WindowImplAndroid; #endif +namespace +{ +// A nested named namespace is used here to allow unity builds of SFML. +// Yes, this is a rather weird namespace. +namespace WindowImplImpl +{ +const sf::priv::WindowImpl* fullscreenWindow = nullptr; +} // namespace WindowImplImpl +} // namespace + + namespace sf::priv { - //////////////////////////////////////////////////////////// struct WindowImpl::JoystickStatesImpl { @@ -137,7 +147,11 @@ WindowImpl::WindowImpl() : m_joystickStatesImpl(std::make_unique