Skip to content

Commit

Permalink
Request fullscreen via state instead of style
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Dec 10, 2023
1 parent e3c33de commit 3460db4
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 36 deletions.
13 changes: 6 additions & 7 deletions include/SFML/Window/WindowStyle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand All @@ -54,10 +53,10 @@ enum
////////////////////////////////////////////////////////////
enum class State
{
Windowed, //!<
Windowed, //!<
Fullscreen, //!<
// Minimized, //!<
// Maximized, //!<
// Fullscreen, //!<
// Hidden //!<
};

Expand Down
6 changes: 5 additions & 1 deletion src/SFML/Window/DRM/WindowImplDRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/SFML/Window/DRM/WindowImplDRM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/SFML/Window/Unix/WindowImplX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/SFML/Window/Unix/WindowImplX11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/SFML/Window/Win32/WindowImplWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/SFML/Window/Win32/WindowImplWin32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/SFML/Window/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint32_t>(Style::Fullscreen);
state = State::Windowed;
}
else
{
Expand All @@ -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<std::uint32_t>(Style::Titlebar);
else
style |= Style::Titlebar;
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/SFML/Window/WindowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint32_t>(Style::Fullscreen);
state = State::Windowed;
}
else
{
Expand All @@ -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<std::uint32_t>(Style::Titlebar);
else
style |= Style::Titlebar;
Expand All @@ -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();
Expand Down
9 changes: 7 additions & 2 deletions src/SFML/Window/WindowImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ struct WindowImpl::JoystickStatesImpl
};

////////////////////////////////////////////////////////////
std::unique_ptr<WindowImpl> WindowImpl::create(VideoMode mode, const String& title, std::uint32_t style, const ContextSettings& settings)
std::unique_ptr<WindowImpl> WindowImpl::create(
VideoMode mode,
const String& title,
std::uint32_t style,
State state,
const ContextSettings& settings)
{
return std::make_unique<WindowImplType>(mode, title, style, settings);
return std::make_unique<WindowImplType>(mode, title, style, state, settings);
}


Expand Down
3 changes: 3 additions & 0 deletions src/SFML/Window/WindowImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <SFML/Window/VideoMode.hpp>
#include <SFML/Window/Vulkan.hpp>
#include <SFML/Window/WindowHandle.hpp>
#include <SFML/Window/WindowStyle.hpp>

#include <memory>
#include <optional>
Expand All @@ -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
Expand All @@ -72,6 +74,7 @@ class WindowImpl
static std::unique_ptr<WindowImpl> create(VideoMode mode,
const String& title,
std::uint32_t style,
State state,
const ContextSettings& settings);

////////////////////////////////////////////////////////////
Expand Down
4 changes: 3 additions & 1 deletion src/SFML/Window/macOS/SFWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/VideoMode.hpp>
#include <SFML/Window/WindowStyle.hpp>
#import <SFML/Window/macOS/WindowImplDelegateProtocol.h>

////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/SFML/Window/macOS/SFWindowController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions src/SFML/Window/macOS/WindowImplCocoa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Window/Event.hpp>
#include <SFML/Window/WindowImpl.hpp>
#include <SFML/Window/WindowStyle.hpp>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/SFML/Window/macOS/WindowImplCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit 3460db4

Please sign in to comment.