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