mirror of
https://github.com/libretro/pcsx2.git
synced 2024-11-27 03:10:31 +00:00
Qt: Implement screensaver inhibit
This commit is contained in:
parent
16f7bdcd33
commit
f63e1b3760
@ -24,6 +24,7 @@
|
||||
|
||||
#include "common/Pcsx2Types.h"
|
||||
#include "common/General.h"
|
||||
#include "common/WindowInfo.h"
|
||||
|
||||
// Darwin (OSX) is a bit different from Linux when requesting properties of
|
||||
// the OS because of its BSD/Mach heritage. Helpfully, most of this code
|
||||
@ -96,7 +97,7 @@ std::string GetOSVersionString()
|
||||
|
||||
static IOPMAssertionID s_pm_assertion;
|
||||
|
||||
void ScreensaverAllow(bool allow)
|
||||
bool WindowInfo::InhibitScreensaver(const WindowInfo& wi, bool inhibit)
|
||||
{
|
||||
if (s_pm_assertion)
|
||||
{
|
||||
@ -104,7 +105,9 @@ void ScreensaverAllow(bool allow)
|
||||
s_pm_assertion = 0;
|
||||
}
|
||||
|
||||
if (!allow)
|
||||
if (inhibit)
|
||||
IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep, kIOPMAssertionLevelOn, CFSTR("Playing a game"), &s_pm_assertion);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
@ -165,8 +165,6 @@ extern const u32 SPIN_TIME_NS;
|
||||
|
||||
extern std::string GetOSVersionString();
|
||||
|
||||
void ScreensaverAllow(bool allow);
|
||||
|
||||
namespace Common
|
||||
{
|
||||
/// Abstracts platform-specific code for asynchronously playing a sound.
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "common/Pcsx2Types.h"
|
||||
#include "common/General.h"
|
||||
#include "common/WindowInfo.h"
|
||||
|
||||
// Returns 0 on failure (not supported by the operating system).
|
||||
u64 GetPhysicalMemory()
|
||||
@ -62,9 +63,10 @@ std::string GetOSVersionString()
|
||||
#endif
|
||||
}
|
||||
|
||||
void ScreensaverAllow(bool allow)
|
||||
bool WindowInfo::InhibitScreensaver(const WindowInfo& wi, bool inhibit)
|
||||
{
|
||||
// no-op
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Common::PlaySoundAsync(const char* path)
|
||||
|
@ -54,4 +54,7 @@ struct WindowInfo
|
||||
|
||||
/// Returns the host's refresh rate for the given window, if available.
|
||||
static bool QueryRefreshRateForWindow(const WindowInfo& wi, float* refresh_rate);
|
||||
|
||||
/// Enables or disables the screen saver from starting.
|
||||
static bool InhibitScreensaver(const WindowInfo& wi, bool inhibit);
|
||||
};
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "common/Exceptions.h"
|
||||
#include "common/StringUtil.h"
|
||||
#include "common/General.h"
|
||||
#include "common/WindowInfo.h"
|
||||
|
||||
#include "fmt/core.h"
|
||||
|
||||
@ -112,12 +113,13 @@ std::string Exception::WinApiError::FormatDiagnosticMessage() const
|
||||
return m_message_diag + "\n\t" + GetMsgFromWindows();
|
||||
}
|
||||
|
||||
void ScreensaverAllow(bool allow)
|
||||
bool WindowInfo::InhibitScreensaver(const WindowInfo& wi, bool inhibit)
|
||||
{
|
||||
EXECUTION_STATE flags = ES_CONTINUOUS;
|
||||
if (!allow)
|
||||
if (inhibit)
|
||||
flags |= ES_DISPLAY_REQUIRED;
|
||||
SetThreadExecutionState(flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Common::PlaySoundAsync(const char* path)
|
||||
|
@ -54,7 +54,7 @@ InterfaceSettingsWidget::InterfaceSettingsWidget(SettingsDialog* dialog, QWidget
|
||||
|
||||
m_ui.setupUi(this);
|
||||
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.inhibitScreensaver, "UI", "InhibitScreensaver", true);
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.inhibitScreensaver, "EmuCore", "InhibitScreensaver", true);
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.confirmShutdown, "UI", "ConfirmShutdown", true);
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.saveStateOnShutdown, "EmuCore", "SaveStateOnShutdown", false);
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.pauseOnStart, "UI", "StartPaused", false);
|
||||
|
@ -991,6 +991,7 @@ struct Pcsx2Config
|
||||
EnableGameFixes : 1, // enables automatic game fixes
|
||||
SaveStateOnShutdown : 1, // default value for saving state on shutdown
|
||||
EnableDiscordPresence : 1, // enables discord rich presence integration
|
||||
InhibitScreensaver : 1,
|
||||
#endif
|
||||
// when enabled uses BOOT2 injection, skipping sony bios splashes
|
||||
UseBOOT2Injection : 1,
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "GS.h"
|
||||
#include "GS/Renderers/HW/GSTextureReplacements.h"
|
||||
#include "Host.h"
|
||||
#include "HostDisplay.h"
|
||||
#include "HostSettings.h"
|
||||
#include "IconsFontAwesome5.h"
|
||||
#include "MemoryCardFile.h"
|
||||
@ -60,6 +61,8 @@ namespace CommonHost
|
||||
static void SetDataDirectory();
|
||||
static void SetCommonDefaultSettings(SettingsInterface& si);
|
||||
|
||||
static void UpdateInhibitScreensaver(bool allow);
|
||||
|
||||
#ifdef ENABLE_DISCORD_PRESENCE
|
||||
static void InitializeDiscordPresence();
|
||||
static void ShutdownDiscordPresence();
|
||||
@ -68,6 +71,8 @@ namespace CommonHost
|
||||
#endif
|
||||
} // namespace CommonHost
|
||||
|
||||
static bool s_screensaver_inhibited = false;
|
||||
|
||||
#ifdef ENABLE_DISCORD_PRESENCE
|
||||
static bool s_discord_presence_active = false;
|
||||
#endif
|
||||
@ -294,6 +299,9 @@ void CommonHost::CheckForSettingsChanges(const Pcsx2Config& old_config)
|
||||
|
||||
FullscreenUI::CheckForConfigChanges(old_config);
|
||||
|
||||
if (EmuConfig.InhibitScreensaver != old_config.InhibitScreensaver)
|
||||
UpdateInhibitScreensaver(EmuConfig.InhibitScreensaver && VMManager::GetState() == VMState::Running);
|
||||
|
||||
#ifdef ENABLE_DISCORD_PRESENCE
|
||||
if (EmuConfig.EnableDiscordPresence != old_config.EnableDiscordPresence)
|
||||
{
|
||||
@ -313,11 +321,13 @@ void CommonHost::OnVMStarting()
|
||||
void CommonHost::OnVMStarted()
|
||||
{
|
||||
FullscreenUI::OnVMStarted();
|
||||
UpdateInhibitScreensaver(EmuConfig.InhibitScreensaver);
|
||||
}
|
||||
|
||||
void CommonHost::OnVMDestroyed()
|
||||
{
|
||||
FullscreenUI::OnVMDestroyed();
|
||||
UpdateInhibitScreensaver(false);
|
||||
}
|
||||
|
||||
void CommonHost::OnVMPaused()
|
||||
@ -328,6 +338,8 @@ void CommonHost::OnVMPaused()
|
||||
#ifdef ENABLE_ACHIEVEMENTS
|
||||
Achievements::OnPaused(true);
|
||||
#endif
|
||||
|
||||
UpdateInhibitScreensaver(false);
|
||||
}
|
||||
|
||||
void CommonHost::OnVMResumed()
|
||||
@ -337,6 +349,8 @@ void CommonHost::OnVMResumed()
|
||||
#ifdef ENABLE_ACHIEVEMENTS
|
||||
Achievements::OnPaused(false);
|
||||
#endif
|
||||
|
||||
UpdateInhibitScreensaver(EmuConfig.InhibitScreensaver);
|
||||
}
|
||||
|
||||
void CommonHost::OnGameChanged(const std::string& disc_path, const std::string& game_serial, const std::string& game_name, u32 game_crc)
|
||||
@ -395,6 +409,20 @@ bool Host::GetSerialAndCRCForFilename(const char* filename, std::string* serial,
|
||||
return false;
|
||||
}
|
||||
|
||||
void CommonHost::UpdateInhibitScreensaver(bool inhibit)
|
||||
{
|
||||
if (s_screensaver_inhibited == inhibit)
|
||||
return;
|
||||
|
||||
WindowInfo wi;
|
||||
if (g_host_display)
|
||||
wi = g_host_display->GetWindowInfo();
|
||||
|
||||
s_screensaver_inhibited = inhibit;
|
||||
if (!WindowInfo::InhibitScreensaver(wi, inhibit) && inhibit)
|
||||
Console.Warning("Failed to inhibit screen saver.");
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DISCORD_PRESENCE
|
||||
|
||||
void CommonHost::InitializeDiscordPresence()
|
||||
|
@ -2185,7 +2185,7 @@ void FullscreenUI::DrawInterfaceSettingsPage()
|
||||
MenuHeading("Behaviour");
|
||||
|
||||
DrawToggleSetting(bsi, ICON_FA_MAGIC " Inhibit Screensaver",
|
||||
"Prevents the screen saver from activating and the host from sleeping while emulation is running.", "UI", "InhibitScreensaver",
|
||||
"Prevents the screen saver from activating and the host from sleeping while emulation is running.", "EmuCore", "InhibitScreensaver",
|
||||
true);
|
||||
#ifdef WITH_DISCORD_PRESENCE
|
||||
DrawToggleSetting(bsi, "Enable Discord Presence", "Shows the game you are currently playing as part of your profile on Discord.", "UI",
|
||||
|
@ -1051,6 +1051,7 @@ Pcsx2Config::Pcsx2Config()
|
||||
EnableRecordingTools = true;
|
||||
#ifdef PCSX2_CORE
|
||||
EnableGameFixes = true;
|
||||
InhibitScreensaver = true;
|
||||
#endif
|
||||
BackupSavestate = true;
|
||||
SavestateZstdCompression = true;
|
||||
@ -1096,6 +1097,7 @@ void Pcsx2Config::LoadSave(SettingsWrapper& wrap)
|
||||
SettingsWrapBitBool(EnableGameFixes);
|
||||
SettingsWrapBitBool(SaveStateOnShutdown);
|
||||
SettingsWrapBitBool(EnableDiscordPresence);
|
||||
SettingsWrapBitBool(InhibitScreensaver);
|
||||
#endif
|
||||
SettingsWrapBitBool(ConsoleToStdio);
|
||||
SettingsWrapBitBool(HostFs);
|
||||
|
@ -137,6 +137,7 @@ static u32 s_active_no_interlacing_patches = 0;
|
||||
static u32 s_frame_advance_count = 0;
|
||||
static u32 s_mxcsr_saved;
|
||||
static bool s_gs_open_on_initialize = false;
|
||||
static bool s_screensaver_inhibited = false;
|
||||
|
||||
bool VMManager::PerformEarlyHardwareChecks(const char** error)
|
||||
{
|
||||
|
@ -527,8 +527,8 @@ void GSPanel::DirectKeyCommand( wxKeyEvent& evt )
|
||||
|
||||
void GSPanel::UpdateScreensaver()
|
||||
{
|
||||
bool prevent = g_Conf->GSWindow.DisableScreenSaver && m_HasFocus && m_coreRunning;
|
||||
ScreensaverAllow(!prevent);
|
||||
const bool prevent = g_Conf->GSWindow.DisableScreenSaver && m_HasFocus && m_coreRunning;
|
||||
WindowInfo::InhibitScreensaver(g_gs_window_info, prevent);
|
||||
}
|
||||
|
||||
void GSPanel::OnFocus( wxFocusEvent& evt )
|
||||
|
Loading…
Reference in New Issue
Block a user