Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare API for multimonitor support #2980

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
faaab05
add a Monitor class
L0laapk3 May 6, 2024
1d5fdda
rename VideoImpl to MonitorImpl
L0laapk3 May 6, 2024
5f27a28
make Monitor a ptr object to MonitorImpl
L0laapk3 May 6, 2024
743a39e
Implement MonitorImplX11
L0laapk3 May 6, 2024
70d88e3
fix documentation and add MonitorImplWin32
L0laapk3 May 6, 2024
34e99d0
add placeholder implementations for the other platforms
L0laapk3 May 6, 2024
907364b
convert indent to spaces
L0laapk3 May 6, 2024
4aa3474
move unix monitor impl to another branch
L0laapk3 May 8, 2024
f194c1b
fix copy-pasted comments
L0laapk3 May 8, 2024
b4649e7
fix comments and style
L0laapk3 May 8, 2024
f6df6b6
minimize diff
L0laapk3 May 8, 2024
9633c1c
add placeholder class note to monitorX11
L0laapk3 May 8, 2024
23c45bb
update cmakelists
L0laapk3 May 8, 2024
de7b827
resolve conflict
L0laapk3 May 8, 2024
e0c0b83
replace VideoMode references
L0laapk3 May 8, 2024
ec5aaaa
convert added cmake lines to spaces
L0laapk3 May 8, 2024
8d12598
documentation
L0laapk3 May 8, 2024
ccc4175
move compilation unit of Monitor destr
L0laapk3 May 8, 2024
30aa166
MonitorImpl::getPrimaryMonitor->createPrimaryMonitor
L0laapk3 May 8, 2024
ee6144b
remove from gitignore
L0laapk3 May 8, 2024
29d52b5
minimize diff
L0laapk3 May 8, 2024
77712f6
alfabetic
L0laapk3 May 8, 2024
18067b1
add default constructors to make build pass
L0laapk3 May 8, 2024
43f928e
replace a tab with spaces
L0laapk3 May 8, 2024
0bcb822
fix mac import
L0laapk3 May 8, 2024
3695efa
run clang-format
L0laapk3 May 8, 2024
bc70eb2
modify comment
L0laapk3 May 8, 2024
2e0612a
I swear i already ran clang format
L0laapk3 May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
L0laapk3 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
build/
cmake-build-*/
CMakeUserPresets.json
compile_commands.json
2 changes: 1 addition & 1 deletion examples/android/app/src/main/jni/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int vibrate(sf::Time duration)
// ('vibrate()' in this example; undefine 'USE_JNI' above to disable it)
int main(int argc, char* argv[])
{
sf::VideoMode screen(sf::VideoMode::getDesktopMode());
sf::VideoMode screen(sf::Monitor::getPrimaryMonitor().getDesktopMode());

sf::RenderWindow window(screen, "");
window.setFramerateLimit(30);
Expand Down
1 change: 1 addition & 0 deletions include/SFML/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <SFML/Window/Joystick.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <SFML/Window/Mouse.hpp>
#include <SFML/Window/Monitor.hpp>
#include <SFML/Window/Sensor.hpp>
#include <SFML/Window/Touch.hpp>
#include <SFML/Window/VideoMode.hpp>
Expand Down
176 changes: 176 additions & 0 deletions include/SFML/Window/Monitor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////

#pragma once

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Export.hpp>

#include <SFML/System/Vector2.hpp>

#include <vector>
#include <memory>


namespace sf
{
class VideoMode;

namespace priv
{
class MonitorImpl;
}

////////////////////////////////////////////////////////////
/// \brief Monitor represents a monitor made available by the OS
///
////////////////////////////////////////////////////////////
class SFML_WINDOW_API Monitor
{
////////////////////////////////////////////////////////////
/// \brief Construct monitor with a MonitorImpl pointer
///
////////////////////////////////////////////////////////////
Monitor(std::unique_ptr<priv::MonitorImpl>&& impl);

public:
~Monitor();

////////////////////////////////////////////////////////////
/// \brief Get the primary monitor
///
/// \return Primary monitor
///
////////////////////////////////////////////////////////////
static Monitor getPrimaryMonitor();

////////////////////////////////////////////////////////////
/// \brief Retrieve all the fullscreen video modes this monitor supports
///
/// When creating a fullscreen window, the video mode is restricted
/// to be compatible with what the graphics driver and monitor
/// support. This function returns the complete list of all video
/// modes that can be used in fullscreen mode.
/// The returned array is sorted from best to worst, so that
/// the first element will always give the best mode (higher
/// width, height and bits-per-pixel).
///
/// \return Array containing all the fullscreen video modes this monitor supports
///
////////////////////////////////////////////////////////////
const std::vector<VideoMode>& getFullscreenModes();

////////////////////////////////////////////////////////////
/// \brief Get the current desktop video mode of this monitor
///
/// \return Current desktop video mode of this monitor
///
////////////////////////////////////////////////////////////
VideoMode getDesktopMode();

////////////////////////////////////////////////////////////
/// \brief Tell whether or not the video mode is valid on this monitor
///
/// The validity of video modes is only relevant when using
/// fullscreen windows; otherwise any video mode can be used
/// with no restriction.
///
/// \return True if the video mode is valid for fullscreen mode on this monitor
///
////////////////////////////////////////////////////////////
bool isValid(const VideoMode& mode);

private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
const std::unique_ptr<priv::MonitorImpl> m_impl; //!< Platform-specific implementation of the monitor
};

} // namespace sf


////////////////////////////////////////////////////////////
/// \class sf::Monitor
/// \ingroup window
///
/// A monitor is an abstraction to represent a display.
///
/// A monitor object of the primary can be obtained using
/// the static function getPrimaryMonitor().
///
/// sf::Monitor provides a function for retrieving the list of
/// all the video modes supported by that monitor and the system:
/// getFullscreenModes().
///
/// A custom video mode can also be checked directly for
/// fullscreen compatibility with its isValid(sf::VideoMode) function.
///
/// Additionally, sf::Monitor provides a function to get the mode
/// currently used by the desktop for that monitor: getDesktopMode().
/// This allows to build windows with the same size or pixel
/// depth as the current resolution.
///
/// Usage example:
/// \code
/// // Display the list of all the video modes available for fullscreen
/// std::vector<sf::VideoMode> modes = sf::Monitor::getPrimaryMonitor().getFullscreenModes();
/// for (std::size_t i = 0; i < modes.size(); ++i)
/// {
/// sf::VideoMode mode = modes[i];
/// std::cout << "Mode #" << i << ": "
/// << mode.width << "x" << mode.height << " - "
/// << mode.bitsPerPixel << " bpp" << std::endl;
/// }
///
/// // Create a window with the same pixel depth as the desktop
/// sf::VideoMode desktop = sf::Monitor::getPrimaryMonitor().getDesktopMode();
/// window.create(sf::VideoMode({1024, 768}, desktop.bitsPerPixel), "SFML window");
/// \endcode
///
////////////////////////////////////////////////////////////

///
/// Usage example:
/// \code
/// // Display the list of all the video modes available for fullscreen for the primary monitor
/// sf::Monitor monitor = sf::Monitor::getPrimaryMonitor();
///
/// std::vector<sf::VideoMode> modes = monitor.getFullscreenModes();
/// for (std::size_t i = 0; i < modes.size(); ++i)
/// {
/// sf::VideoMode mode = modes[i];
/// std::cout << "Mode #" << i << ": "
/// << mode.width << "x" << mode.height << " - "
/// << mode.bitsPerPixel << " bpp" << std::endl;
/// }
///
/// // Create a window with the same pixel depth as the desktop
/// sf::VideoMode desktopMode = monitor.getDesktopMode();
/// window.create(sf::VideoMode(desktopMode, "SFML window");
/// \endcode
///
////////////////////////////////////////////////////////////
65 changes: 1 addition & 64 deletions include/SFML/Window/VideoMode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,42 +60,6 @@ class SFML_WINDOW_API VideoMode
////////////////////////////////////////////////////////////
explicit VideoMode(const Vector2u& modeSize, unsigned int modeBitsPerPixel = 32);

////////////////////////////////////////////////////////////
/// \brief Get the current desktop video mode
///
/// \return Current desktop video mode
///
////////////////////////////////////////////////////////////
static VideoMode getDesktopMode();

////////////////////////////////////////////////////////////
/// \brief Retrieve all the video modes supported in fullscreen mode
///
/// When creating a fullscreen window, the video mode is restricted
/// to be compatible with what the graphics driver and monitor
/// support. This function returns the complete list of all video
/// modes that can be used in fullscreen mode.
/// The returned array is sorted from best to worst, so that
/// the first element will always give the best mode (higher
/// width, height and bits-per-pixel).
///
/// \return Array containing all the supported fullscreen modes
///
////////////////////////////////////////////////////////////
static const std::vector<VideoMode>& getFullscreenModes();

////////////////////////////////////////////////////////////
/// \brief Tell whether or not the video mode is valid
///
/// The validity of video modes is only relevant when using
/// fullscreen windows; otherwise any video mode can be used
/// with no restriction.
///
/// \return True if the video mode is valid for fullscreen mode
///
////////////////////////////////////////////////////////////
bool isValid() const;

////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -192,33 +156,6 @@ SFML_WINDOW_API bool operator>=(const VideoMode& left, const VideoMode& right);
/// and the graphics card support), otherwise your window
/// creation will just fail.
///
/// sf::VideoMode provides a static function for retrieving
/// the list of all the video modes supported by the system:
/// getFullscreenModes().
///
/// A custom video mode can also be checked directly for
/// fullscreen compatibility with its isValid() function.
///
/// Additionally, sf::VideoMode provides a static function
/// to get the mode currently used by the desktop: getDesktopMode().
/// This allows to build windows with the same size or pixel
/// depth as the current resolution.
///
/// Usage example:
/// \code
/// // Display the list of all the video modes available for fullscreen
/// std::vector<sf::VideoMode> modes = sf::VideoMode::getFullscreenModes();
/// for (std::size_t i = 0; i < modes.size(); ++i)
/// {
/// sf::VideoMode mode = modes[i];
/// std::cout << "Mode #" << i << ": "
/// << mode.width << "x" << mode.height << " - "
/// << mode.bitsPerPixel << " bpp" << std::endl;
/// }
///
/// // Create a window with the same pixel depth as the desktop
/// sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
/// window.create(sf::VideoMode({1024, 768}, desktop.bitsPerPixel), "SFML window");
/// \endcode
/// See also: sf::Monitor.
///
////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/VideoModeImpl.hpp>
#include <SFML/Window/Android/MonitorImplAndroid.hpp>
#include <SFML/Window/VideoMode.hpp>

#include <SFML/System/Android/Activity.hpp>
#include <SFML/System/Sleep.hpp>
Expand All @@ -36,7 +37,14 @@
namespace sf::priv
{
////////////////////////////////////////////////////////////
std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
std::unique_ptr<MonitorImpl> MonitorImplAndroid::getPrimaryMonitor()
{
return std::make_unique<MonitorImplAndroid>();
}


////////////////////////////////////////////////////////////
std::vector<VideoMode> MonitorImplAndroid::getFullscreenModes()
{
const VideoMode desktop = getDesktopMode();

Expand All @@ -46,7 +54,7 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()


////////////////////////////////////////////////////////////
VideoMode VideoModeImpl::getDesktopMode()
VideoMode MonitorImplAndroid::getDesktopMode()
{
// Get the activity states
priv::ActivityStates& states = priv::getActivity();
Expand Down
81 changes: 81 additions & 0 deletions src/SFML/Window/Android/MonitorImplAndroid.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////

#pragma once

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/MonitorImpl.hpp>


namespace sf
{
class VideoMode;

namespace priv
{
////////////////////////////////////////////////////////////
/// \brief Android implementation of MonitorImpl
///
/// \note Placeholder class. Actual storage of the monitor handle not implemented yet.
///
////////////////////////////////////////////////////////////
class MonitorImplAndroid : public MonitorImpl
{
public:
////////////////////////////////////////////////////////////
/// \brief Construct the monitor implementation
///
////////////////////////////////////////////////////////////
MonitorImplAndroid();

////////////////////////////////////////////////////////////
/// \brief Create primary monitor implementation
///
/// \return Pointer to the created primary monitor implementation
///
////////////////////////////////////////////////////////////
static std::unique_ptr<MonitorImpl> getPrimaryMonitor();

////////////////////////////////////////////////////////////
/// \brief Get the list of all the supported fullscreen video modes of this monitor
///
/// \return Array filled with the fullscreen video modes of this monitor
///
////////////////////////////////////////////////////////////
std::vector<VideoMode> getFullscreenModes();

////////////////////////////////////////////////////////////
/// \brief Get the current desktop video mode of this monitor
///
/// \return Current desktop video mode of this monitor
///
////////////////////////////////////////////////////////////
VideoMode getDesktopMode();
};

} // namespace priv

} // namespace sf