mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-28 13:28:01 +03:00
Move display sleep functions to emu callbacks
This commit is contained in:
parent
87db82cacd
commit
8d801dadc4
8 changed files with 38 additions and 48 deletions
|
@ -51,8 +51,6 @@
|
|||
|
||||
#include "Utilities/JIT.h"
|
||||
|
||||
#include "display_sleep_control.h"
|
||||
|
||||
#include "Emu/IPC_socket.h"
|
||||
|
||||
#if defined(HAVE_VULKAN)
|
||||
|
@ -2506,7 +2504,7 @@ void Emulator::Run(bool start_playtime)
|
|||
|
||||
if (g_cfg.misc.prevent_display_sleep)
|
||||
{
|
||||
disable_display_sleep();
|
||||
Emu.GetCallbacks().enable_display_sleep(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2791,7 +2789,7 @@ bool Emulator::Pause(bool freeze_emulation, bool show_resume_message)
|
|||
}
|
||||
|
||||
// Always Enable display sleep, not only if it was prevented.
|
||||
enable_display_sleep();
|
||||
Emu.GetCallbacks().enable_display_sleep(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2888,7 +2886,7 @@ void Emulator::Resume()
|
|||
|
||||
if (g_cfg.misc.prevent_display_sleep)
|
||||
{
|
||||
disable_display_sleep();
|
||||
Emu.GetCallbacks().enable_display_sleep(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3798,7 +3796,7 @@ void Emulator::Kill(bool allow_autoexit, bool savestate, savestate_stage* save_s
|
|||
GetCallbacks().on_stop();
|
||||
|
||||
// Always Enable display sleep, not only if it was prevented.
|
||||
enable_display_sleep();
|
||||
Emu.GetCallbacks().enable_display_sleep(true);
|
||||
|
||||
if (allow_autoexit)
|
||||
{
|
||||
|
|
|
@ -107,6 +107,8 @@ struct EmuCallbacks
|
|||
std::function<std::vector<std::string>()> get_font_dirs;
|
||||
std::function<bool(const std::vector<std::string>&)> on_install_pkgs;
|
||||
std::function<void(u32)> add_breakpoint;
|
||||
std::function<bool()> display_sleep_control_supported;
|
||||
std::function<void(bool)> enable_display_sleep;
|
||||
std::function<void()> check_microphone_permissions;
|
||||
};
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ bool display_sleep_control_supported()
|
|||
#endif
|
||||
}
|
||||
|
||||
void enable_display_sleep()
|
||||
void enable_display_sleep(bool enabled)
|
||||
{
|
||||
if (!display_sleep_control_supported())
|
||||
{
|
||||
|
@ -47,15 +47,23 @@ void enable_display_sleep()
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
SetThreadExecutionState(ES_CONTINUOUS);
|
||||
SetThreadExecutionState(enabled ? ES_CONTINUOUS : (ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED));
|
||||
#elif defined(__APPLE__)
|
||||
if (s_pm_assertion != kIOPMNullAssertionID)
|
||||
if (enabled && s_pm_assertion != kIOPMNullAssertionID)
|
||||
{
|
||||
IOPMAssertionRelease(s_pm_assertion);
|
||||
s_pm_assertion = kIOPMNullAssertionID;
|
||||
}
|
||||
else if (!enabled)
|
||||
{
|
||||
#pragma GCC diagnostic push
|
||||
// Necessary as some of those values are macro using old casts
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep, kIOPMAssertionLevelOn, CFSTR("Game running"), &s_pm_assertion);
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
#elif defined(HAVE_QTDBUS)
|
||||
if (s_dbus_cookie != 0)
|
||||
if (enabled && s_dbus_cookie != 0)
|
||||
{
|
||||
for (const char* service : { "org.freedesktop.ScreenSaver", "org.mate.ScreenSaver" })
|
||||
{
|
||||
|
@ -68,36 +76,20 @@ void enable_display_sleep()
|
|||
}
|
||||
s_dbus_cookie = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void disable_display_sleep()
|
||||
{
|
||||
if (!display_sleep_control_supported())
|
||||
else if (!enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
|
||||
#elif defined(__APPLE__)
|
||||
#pragma GCC diagnostic push
|
||||
// Necessary as some of those values are macro using old casts
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep, kIOPMAssertionLevelOn, CFSTR("Game running"), &s_pm_assertion);
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined(HAVE_QTDBUS)
|
||||
for (const char* service : { "org.freedesktop.ScreenSaver", "org.mate.ScreenSaver" })
|
||||
{
|
||||
QDBusInterface interface(service, "/ScreenSaver", service, QDBusConnection::sessionBus());
|
||||
if (interface.isValid())
|
||||
for (const char* service : { "org.freedesktop.ScreenSaver", "org.mate.ScreenSaver" })
|
||||
{
|
||||
QDBusReply<u32> reply = interface.call("Inhibit", "rpcs3", "Game running");
|
||||
if (reply.isValid())
|
||||
QDBusInterface interface(service, "/ScreenSaver", service, QDBusConnection::sessionBus());
|
||||
if (interface.isValid())
|
||||
{
|
||||
s_dbus_cookie = reply.value();
|
||||
QDBusReply<u32> reply = interface.call("Inhibit", "rpcs3", "Game running");
|
||||
if (reply.isValid())
|
||||
{
|
||||
s_dbus_cookie = reply.value();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
bool display_sleep_control_supported();
|
||||
void enable_display_sleep();
|
||||
void disable_display_sleep();
|
||||
void enable_display_sleep(bool enabled);
|
||||
|
|
|
@ -168,6 +168,9 @@ void headless_application::InitializeCallbacks()
|
|||
callbacks.play_sound = [](const std::string&){};
|
||||
callbacks.add_breakpoint = [](u32 /*addr*/){};
|
||||
|
||||
callbacks.display_sleep_control_supported = [](){ return false; };
|
||||
callbacks.enable_display_sleep = [](bool /*enabled*/){};
|
||||
|
||||
callbacks.check_microphone_permissions = [](){};
|
||||
|
||||
Emu.SetCallbacks(std::move(callbacks));
|
||||
|
|
|
@ -73,14 +73,7 @@ void main_application::OnEmuSettingsChange()
|
|||
{
|
||||
if (Emu.IsRunning())
|
||||
{
|
||||
if (g_cfg.misc.prevent_display_sleep)
|
||||
{
|
||||
disable_display_sleep();
|
||||
}
|
||||
else
|
||||
{
|
||||
enable_display_sleep();
|
||||
}
|
||||
enable_display_sleep(!g_cfg.misc.prevent_display_sleep);
|
||||
}
|
||||
|
||||
if (!Emu.IsStopped())
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "qt_camera_handler.h"
|
||||
#include "qt_music_handler.h"
|
||||
#include "rpcs3_version.h"
|
||||
#include "display_sleep_control.h"
|
||||
|
||||
#ifdef WITH_DISCORD_RPC
|
||||
#include "_discord_utils.h"
|
||||
|
@ -882,6 +883,9 @@ void gui_application::InitializeCallbacks()
|
|||
});
|
||||
};
|
||||
|
||||
callbacks.display_sleep_control_supported = [](){ return display_sleep_control_supported(); };
|
||||
callbacks.enable_display_sleep = [](bool enabled){ enable_display_sleep(enabled); };
|
||||
|
||||
callbacks.check_microphone_permissions = []()
|
||||
{
|
||||
#if QT_CONFIG(permissions)
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <QStyleFactory>
|
||||
|
||||
#include "gui_settings.h"
|
||||
#include "display_sleep_control.h"
|
||||
#include "qt_utils.h"
|
||||
#include "uuid.h"
|
||||
#include "settings_dialog.h"
|
||||
|
@ -1822,7 +1821,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
|
|||
|
||||
m_emu_settings->EnhanceCheckBox(ui->preventDisplaySleep, emu_settings_type::PreventDisplaySleep);
|
||||
SubscribeTooltip(ui->preventDisplaySleep, tooltips.settings.prevent_display_sleep);
|
||||
ui->preventDisplaySleep->setEnabled(display_sleep_control_supported());
|
||||
ui->preventDisplaySleep->setEnabled(Emu.GetCallbacks().display_sleep_control_supported());
|
||||
|
||||
m_emu_settings->EnhanceCheckBox(ui->showTrophyPopups, emu_settings_type::ShowTrophyPopups);
|
||||
SubscribeTooltip(ui->showTrophyPopups, tooltips.settings.show_trophy_popups);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue