Move fullscreen window bookkeeping to a lower level

This commit is contained in:
Chris Thrasher 2023-12-26 17:16:06 -06:00
parent 51b8b44e14
commit 7556d1be78
5 changed files with 48 additions and 56 deletions

View File

@ -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
////////////////////////////////////////////////////////////

View File

@ -63,10 +63,7 @@ Window::Window(WindowHandle handle, const ContextSettings& settings)
////////////////////////////////////////////////////////////
Window::~Window()
{
close();
}
Window::~Window() = default;
////////////////////////////////////////////////////////////

View File

@ -46,16 +46,6 @@
#include <cstdlib>
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

View File

@ -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<JoystickStatesI
////////////////////////////////////////////////////////////
WindowImpl::~WindowImpl() = default;
WindowImpl::~WindowImpl()
{
if (WindowImplImpl::fullscreenWindow == this)
WindowImplImpl::fullscreenWindow = nullptr;
}
////////////////////////////////////////////////////////////
@ -348,4 +362,18 @@ bool WindowImpl::createVulkanSurface([[maybe_unused]] const VkInstance&
#endif
}
////////////////////////////////////////////////////////////
const WindowImpl* WindowImpl::getFullscreenWindow() const
{
return WindowImplImpl::fullscreenWindow;
}
////////////////////////////////////////////////////////////
void WindowImpl::setFullscreenWindow() const
{
WindowImplImpl::fullscreenWindow = this;
}
} // namespace sf::priv

View File

@ -305,6 +305,20 @@ public:
////////////////////////////////////////////////////////////
bool createVulkanSurface(const VkInstance& instance, VkSurfaceKHR& surface, const VkAllocationCallbacks* allocator) const;
////////////////////////////////////////////////////////////
/// \brief Get the fullscreen window
///
/// \return The fullscreen window or a null pointer if there is none
///
////////////////////////////////////////////////////////////
[[nodiscard]] const WindowImpl* getFullscreenWindow() const;
////////////////////////////////////////////////////////////
/// \brief Set a window as the fullscreen window
///
////////////////////////////////////////////////////////////
void setFullscreenWindow() const;
protected:
////////////////////////////////////////////////////////////
/// \brief Default constructor