diff --git a/include/SFML/System.hpp b/include/SFML/System.hpp index eca81a33..b094272f 100644 --- a/include/SFML/System.hpp +++ b/include/SFML/System.hpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include diff --git a/include/SFML/System/Power.hpp b/include/SFML/System/Power.hpp new file mode 100644 index 00000000..4836ae09 --- /dev/null +++ b/include/SFML/System/Power.hpp @@ -0,0 +1,58 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// 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. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_POWER_HPP +#define SFML_POWER_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// \ingroup system +/// \brief Allows or disallows the system to assume being idle +/// +/// Depending on the local machine's settings, the system +/// might disable the screen or go into sleep if no input is +/// registered for an extended period of time. +/// +/// This functions allows suspending these features while +/// the current application is still active. +/// +/// \param duration Time to sleep +/// +/// \return Whether the request has been successful +/// +//////////////////////////////////////////////////////////// +bool SFML_SYSTEM_API setPowersavingEnabled(bool enable); + +} // namespace sf + + +#endif // SFML_POWER_HPP diff --git a/src/SFML/System/Android/PowerImpl.cpp b/src/SFML/System/Android/PowerImpl.cpp new file mode 100644 index 00000000..e06c7be7 --- /dev/null +++ b/src/SFML/System/Android/PowerImpl.cpp @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// 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. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +bool setPowersavingEnabledImpl(bool enabled) +{ + return false; +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Android/PowerImpl.hpp b/src/SFML/System/Android/PowerImpl.hpp new file mode 100644 index 00000000..6b509b0f --- /dev/null +++ b/src/SFML/System/Android/PowerImpl.hpp @@ -0,0 +1,52 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// 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. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_POWERIMPLANDROID_HPP +#define SFML_POWERIMPLANDROID_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Android implementation of sf::setPowersavingEnabled +/// +/// \param enabled +/// +//////////////////////////////////////////////////////////// +bool setPowersavingEnabledImpl(bool enabled); + +} // namespace priv + +} // namespace sf + + +#endif // SFML_SLEEPIMPLUNIX_HPP diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index 74c95de4..d7cb7bc1 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -15,6 +15,8 @@ set(SRC ${SRCROOT}/Mutex.cpp ${INCROOT}/Mutex.hpp ${INCROOT}/NonCopyable.hpp + ${SRCROOT}/Power.cpp + ${INCROOT}/Power.hpp ${SRCROOT}/Sleep.cpp ${INCROOT}/Sleep.hpp ${SRCROOT}/String.cpp @@ -45,6 +47,8 @@ if(SFML_OS_WINDOWS) ${SRCROOT}/Win32/ClockImpl.hpp ${SRCROOT}/Win32/MutexImpl.cpp ${SRCROOT}/Win32/MutexImpl.hpp + ${SRCROOT}/Win32/PowerImpl.cpp + ${SRCROOT}/Win32/PowerImpl.hpp ${SRCROOT}/Win32/SleepImpl.cpp ${SRCROOT}/Win32/SleepImpl.hpp ${SRCROOT}/Win32/ThreadImpl.cpp @@ -53,7 +57,7 @@ if(SFML_OS_WINDOWS) ${SRCROOT}/Win32/ThreadLocalImpl.hpp ) source_group("windows" FILES ${PLATFORM_SRC}) -else() +else(SFML_OS_ANDROID) set(PLATFORM_SRC ${SRCROOT}/Unix/ClockImpl.cpp ${SRCROOT}/Unix/ClockImpl.hpp @@ -64,18 +68,30 @@ else() ${SRCROOT}/Unix/ThreadImpl.cpp ${SRCROOT}/Unix/ThreadImpl.hpp ${SRCROOT}/Unix/ThreadLocalImpl.cpp + ${SRCROOT}/Unix/ThreadLocalImpl.hpp + ${SRCROOT}/Android/Activity.cpp + ${SRCROOT}/Android/Activity.hpp + ${SRCROOT}/Android/PowerImpl.cpp + ${SRCROOT}/Android/PowerImpl.hpp + ${SRCROOT}/Android/ResourceStream.cpp + ${SRCROOT}/Android/ResourceStream.hpp + ) + source_group("android" FILES ${PLATFORM_SRC}) +else() + set(PLATFORM_SRC + ${SRCROOT}/Unix/ClockImpl.cpp + ${SRCROOT}/Unix/ClockImpl.hpp + ${SRCROOT}/Unix/MutexImpl.cpp + ${SRCROOT}/Unix/MutexImpl.hpp + ${SRCROOT}/Unix/PowerImpl.cpp + ${SRCROOT}/Unix/PowerImpl.hpp + ${SRCROOT}/Unix/SleepImpl.cpp + ${SRCROOT}/Unix/SleepImpl.hpp + ${SRCROOT}/Unix/ThreadImpl.cpp + ${SRCROOT}/Unix/ThreadImpl.hpp + ${SRCROOT}/Unix/ThreadLocalImpl.cpp ${SRCROOT}/Unix/ThreadLocalImpl.hpp ) - - if(SFML_OS_ANDROID) - set(PLATFORM_SRC ${PLATFORM_SRC} - ${SRCROOT}/Android/Activity.hpp - ${SRCROOT}/Android/Activity.cpp - ${SRCROOT}/Android/ResourceStream.cpp - ${SRCROOT}/Android/ResourceStream.cpp - ) - endif() - source_group("unix" FILES ${PLATFORM_SRC}) endif() diff --git a/src/SFML/System/Power.cpp b/src/SFML/System/Power.cpp new file mode 100644 index 00000000..2f784160 --- /dev/null +++ b/src/SFML/System/Power.cpp @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// 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. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + +#if defined(SFML_SYSTEM_WINDOWS) + #include +#else + #include +#endif + + +namespace sf +{ +//////////////////////////////////////////////////////////// +bool setPowersavingEnabled(bool enable) +{ + return priv::setPowersavingEnabledImpl(enable); +} + +} // namespace sf diff --git a/src/SFML/System/Unix/PowerImpl.cpp b/src/SFML/System/Unix/PowerImpl.cpp new file mode 100644 index 00000000..326ce712 --- /dev/null +++ b/src/SFML/System/Unix/PowerImpl.cpp @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// 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. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +bool setPowersavingEnabledImpl(bool enabled) +{ + return false; +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Unix/PowerImpl.hpp b/src/SFML/System/Unix/PowerImpl.hpp new file mode 100644 index 00000000..781dbd7a --- /dev/null +++ b/src/SFML/System/Unix/PowerImpl.hpp @@ -0,0 +1,52 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// 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. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_POWERIMPLUNIX_HPP +#define SFML_POWERIMPLUNIX_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Unix implementation of sf::setPowersavingEnabled +/// +/// \param enabled +/// +//////////////////////////////////////////////////////////// +bool setPowersavingEnabledImpl(bool enabled); + +} // namespace priv + +} // namespace sf + + +#endif // SFML_SLEEPIMPLUNIX_HPP diff --git a/src/SFML/System/Win32/PowerImpl.cpp b/src/SFML/System/Win32/PowerImpl.cpp new file mode 100644 index 00000000..b3be5d1c --- /dev/null +++ b/src/SFML/System/Win32/PowerImpl.cpp @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// 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. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +bool setPowersavingEnabledImpl(bool enabled) +{ + return SetThreadExecutionState(enabled ? ES_CONTINUOUS : ES_CONTINUOUS | ES_DISPLAY_REQUIRED); +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Win32/PowerImpl.hpp b/src/SFML/System/Win32/PowerImpl.hpp new file mode 100644 index 00000000..e5d802c4 --- /dev/null +++ b/src/SFML/System/Win32/PowerImpl.hpp @@ -0,0 +1,52 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// 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. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_POWERIMPLWIN32_HPP +#define SFML_POWERIMPLWIN32_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Windows implementation of sf::setPowersavingEnabled +/// +/// \param enabled +/// +//////////////////////////////////////////////////////////// +bool setPowersavingEnabledImpl(bool enabled); + +} // namespace priv + +} // namespace sf + + +#endif // SFML_SLEEPIMPLWIN32_HPP