diff --git a/src/duckstation-nogui/nogui_host.cpp b/src/duckstation-nogui/nogui_host.cpp index 025dad4a7..c8fb80ea0 100644 --- a/src/duckstation-nogui/nogui_host.cpp +++ b/src/duckstation-nogui/nogui_host.cpp @@ -964,9 +964,9 @@ void Host::SetFullscreen(bool enabled) g_nogui_window->SetFullscreen(enabled); } -void* Host::GetTopLevelWindowHandle() +std::optional Host::GetTopLevelWindowInfo() { - return g_nogui_window->GetPlatformWindowHandle(); + return g_nogui_window->GetPlatformWindowInfo(); } void Host::RequestExit(bool save_state_if_running) diff --git a/src/duckstation-nogui/nogui_platform.h b/src/duckstation-nogui/nogui_platform.h index 124438448..47a841c33 100644 --- a/src/duckstation-nogui/nogui_platform.h +++ b/src/duckstation-nogui/nogui_platform.h @@ -25,7 +25,6 @@ public: virtual std::optional GetPlatformWindowInfo() = 0; virtual void SetPlatformWindowTitle(std::string title) = 0; - virtual void* GetPlatformWindowHandle() = 0; virtual std::optional ConvertHostKeyboardStringToCode(const std::string_view& str) = 0; virtual std::optional ConvertHostKeyboardCodeToString(u32 code) = 0; diff --git a/src/duckstation-nogui/vty_nogui_platform.cpp b/src/duckstation-nogui/vty_nogui_platform.cpp index 8cc6d0b73..3112f0092 100644 --- a/src/duckstation-nogui/vty_nogui_platform.cpp +++ b/src/duckstation-nogui/vty_nogui_platform.cpp @@ -130,11 +130,6 @@ void VTYNoGUIPlatform::SetPlatformWindowTitle(std::string title) Log_InfoPrintf("Window Title: %s", title.c_str()); } -void* VTYNoGUIPlatform::GetPlatformWindowHandle() -{ - return nullptr; -} - void VTYNoGUIPlatform::RunMessageLoop() { while (m_message_loop_running.load(std::memory_order_acquire)) diff --git a/src/duckstation-nogui/vty_nogui_platform.h b/src/duckstation-nogui/vty_nogui_platform.h index f417a91c1..3ba06e463 100644 --- a/src/duckstation-nogui/vty_nogui_platform.h +++ b/src/duckstation-nogui/vty_nogui_platform.h @@ -24,7 +24,6 @@ public: void DestroyPlatformWindow() override; std::optional GetPlatformWindowInfo() override; void SetPlatformWindowTitle(std::string title) override; - void* GetPlatformWindowHandle() override; std::optional ConvertHostKeyboardStringToCode(const std::string_view& str) override; std::optional ConvertHostKeyboardCodeToString(u32 code) override; diff --git a/src/duckstation-nogui/wayland_nogui_platform.cpp b/src/duckstation-nogui/wayland_nogui_platform.cpp index 58982113e..e0e0a4310 100644 --- a/src/duckstation-nogui/wayland_nogui_platform.cpp +++ b/src/duckstation-nogui/wayland_nogui_platform.cpp @@ -193,11 +193,6 @@ void WaylandNoGUIPlatform::SetPlatformWindowTitle(std::string title) xdg_toplevel_set_title(m_xdg_toplevel, title.c_str()); } -void* WaylandNoGUIPlatform::GetPlatformWindowHandle() -{ - return m_surface; -} - std::optional WaylandNoGUIPlatform::ConvertHostKeyboardStringToCode(const std::string_view& str) { std::unique_lock lock(m_key_map_mutex); diff --git a/src/duckstation-nogui/wayland_nogui_platform.h b/src/duckstation-nogui/wayland_nogui_platform.h index 49f06bd25..a5a3fe480 100644 --- a/src/duckstation-nogui/wayland_nogui_platform.h +++ b/src/duckstation-nogui/wayland_nogui_platform.h @@ -29,7 +29,6 @@ public: void DestroyPlatformWindow() override; std::optional GetPlatformWindowInfo() override; void SetPlatformWindowTitle(std::string title) override; - void* GetPlatformWindowHandle() override; std::optional ConvertHostKeyboardStringToCode(const std::string_view& str) override; std::optional ConvertHostKeyboardCodeToString(u32 code) override; diff --git a/src/duckstation-nogui/win32_nogui_platform.cpp b/src/duckstation-nogui/win32_nogui_platform.cpp index 000516adf..18cf2c12c 100644 --- a/src/duckstation-nogui/win32_nogui_platform.cpp +++ b/src/duckstation-nogui/win32_nogui_platform.cpp @@ -177,11 +177,6 @@ void Win32NoGUIPlatform::SetPlatformWindowTitle(std::string title) SetWindowTextW(m_hwnd, StringUtil::UTF8StringToWideString(title).c_str()); } -void* Win32NoGUIPlatform::GetPlatformWindowHandle() -{ - return m_hwnd; -} - std::optional Win32NoGUIPlatform::ConvertHostKeyboardStringToCode(const std::string_view& str) { std::optional converted(Win32KeyNames::GetKeyCodeForName(str)); diff --git a/src/duckstation-nogui/win32_nogui_platform.h b/src/duckstation-nogui/win32_nogui_platform.h index cc4f496d0..e54cf429e 100644 --- a/src/duckstation-nogui/win32_nogui_platform.h +++ b/src/duckstation-nogui/win32_nogui_platform.h @@ -23,7 +23,6 @@ public: void DestroyPlatformWindow() override; std::optional GetPlatformWindowInfo() override; void SetPlatformWindowTitle(std::string title) override; - void* GetPlatformWindowHandle() override; std::optional ConvertHostKeyboardStringToCode(const std::string_view& str) override; std::optional ConvertHostKeyboardCodeToString(u32 code) override; diff --git a/src/duckstation-nogui/x11_nogui_platform.cpp b/src/duckstation-nogui/x11_nogui_platform.cpp index 23d5851b1..43d871922 100644 --- a/src/duckstation-nogui/x11_nogui_platform.cpp +++ b/src/duckstation-nogui/x11_nogui_platform.cpp @@ -129,11 +129,6 @@ void X11NoGUIPlatform::SetPlatformWindowTitle(std::string title) }); } -void* X11NoGUIPlatform::GetPlatformWindowHandle() -{ - return reinterpret_cast(m_window); -} - void X11NoGUIPlatform::InitializeKeyMap() { int min_keycode = 0, max_keycode = -1; diff --git a/src/duckstation-nogui/x11_nogui_platform.h b/src/duckstation-nogui/x11_nogui_platform.h index fc8819364..3cb344046 100644 --- a/src/duckstation-nogui/x11_nogui_platform.h +++ b/src/duckstation-nogui/x11_nogui_platform.h @@ -48,7 +48,6 @@ public: void DestroyPlatformWindow() override; std::optional GetPlatformWindowInfo() override; void SetPlatformWindowTitle(std::string title) override; - void* GetPlatformWindowHandle() override; std::optional ConvertHostKeyboardStringToCode(const std::string_view& str) override; std::optional ConvertHostKeyboardCodeToString(u32 code) override; diff --git a/src/duckstation-qt/displaywidget.cpp b/src/duckstation-qt/displaywidget.cpp index 32628a9de..66ae58fb7 100644 --- a/src/duckstation-qt/displaywidget.cpp +++ b/src/duckstation-qt/displaywidget.cpp @@ -44,62 +44,28 @@ DisplayWidget::~DisplayWidget() #endif } -qreal DisplayWidget::devicePixelRatioFromScreen() const -{ - const QScreen* screen_for_ratio = screen(); - if (!screen_for_ratio) - screen_for_ratio = QGuiApplication::primaryScreen(); - - return screen_for_ratio ? screen_for_ratio->devicePixelRatio() : static_cast(1); -} - int DisplayWidget::scaledWindowWidth() const { - return std::max(static_cast(std::ceil(static_cast(width()) * devicePixelRatioFromScreen())), 1); + return std::max( + static_cast(std::ceil(static_cast(width()) * QtUtils::GetDevicePixelRatioForWidget(this))), 1); } int DisplayWidget::scaledWindowHeight() const { - return std::max(static_cast(std::ceil(static_cast(height()) * devicePixelRatioFromScreen())), 1); + return std::max( + static_cast(std::ceil(static_cast(height()) * QtUtils::GetDevicePixelRatioForWidget(this))), 1); } std::optional DisplayWidget::getWindowInfo() { - WindowInfo wi; - - // Windows and Apple are easy here since there's no display connection. -#if defined(_WIN32) - wi.type = WindowInfo::Type::Win32; - wi.window_handle = reinterpret_cast(winId()); -#elif defined(__APPLE__) - wi.type = WindowInfo::Type::MacOS; - wi.window_handle = reinterpret_cast(winId()); -#else - QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface(); - const QString platform_name = QGuiApplication::platformName(); - if (platform_name == QStringLiteral("xcb")) + std::optional ret(QtUtils::GetWindowInfoForWidget(this)); + if (ret.has_value()) { - wi.type = WindowInfo::Type::X11; - wi.display_connection = pni->nativeResourceForWindow("display", windowHandle()); - wi.window_handle = reinterpret_cast(winId()); + m_last_window_width = ret->surface_width; + m_last_window_height = ret->surface_height; + m_last_window_scale = ret->surface_scale; } - else if (platform_name == QStringLiteral("wayland")) - { - wi.type = WindowInfo::Type::Wayland; - wi.display_connection = pni->nativeResourceForWindow("display", windowHandle()); - wi.window_handle = pni->nativeResourceForWindow("surface", windowHandle()); - } - else - { - qCritical() << "Unknown PNI platform " << platform_name; - return std::nullopt; - } -#endif - - m_last_window_width = wi.surface_width = static_cast(scaledWindowWidth()); - m_last_window_height = wi.surface_height = static_cast(scaledWindowHeight()); - m_last_window_scale = wi.surface_scale = static_cast(devicePixelRatioFromScreen()); - return wi; + return ret; } void DisplayWidget::updateRelativeMode(bool enabled) @@ -270,7 +236,7 @@ bool DisplayWidget::event(QEvent* event) if (!m_relative_mouse_enabled) { - const qreal dpr = devicePixelRatioFromScreen(); + const qreal dpr = QtUtils::GetDevicePixelRatioForWidget(this); const QPoint mouse_pos = mouse_event->pos(); const float scaled_x = static_cast(static_cast(mouse_pos.x()) * dpr); @@ -341,7 +307,7 @@ bool DisplayWidget::event(QEvent* event) { QWidget::event(event); - const float dpr = devicePixelRatioFromScreen(); + const float dpr = QtUtils::GetDevicePixelRatioForWidget(this); const u32 scaled_width = static_cast(std::max(static_cast(std::ceil(static_cast(width()) * dpr)), 1)); const u32 scaled_height = diff --git a/src/duckstation-qt/displaywidget.h b/src/duckstation-qt/displaywidget.h index e9739ca9e..9e7d5444b 100644 --- a/src/duckstation-qt/displaywidget.h +++ b/src/duckstation-qt/displaywidget.h @@ -19,7 +19,6 @@ public: int scaledWindowWidth() const; int scaledWindowHeight() const; - qreal devicePixelRatioFromScreen() const; std::optional getWindowInfo(); diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 7f68d601a..9172641f1 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -2520,6 +2520,13 @@ void MainWindow::checkForSettingChanges() updateWindowState(); } +void MainWindow::getWindowInfo(WindowInfo* wi) +{ + std::optional opt_wi(QtUtils::GetWindowInfoForWidget(this)); + if (opt_wi.has_value()) + *wi = opt_wi.value(); +} + void MainWindow::onCheckForUpdatesActionTriggered() { // Wipe out the last version, that way it displays the update if we've previously skipped it. diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index 6c16cb7ac..2fe0d6e1a 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -4,8 +4,10 @@ #include #include #include +#include #include "controllersettingsdialog.h" +#include "common/window_info.h" #include "core/types.h" #include "displaywidget.h" #include "settingsdialog.h" @@ -97,6 +99,7 @@ public Q_SLOTS: bool requestShutdown(bool allow_confirm = true, bool allow_save_to_state = true, bool save_state = true, bool block_until_done = false); void requestExit(bool allow_save_to_state = true); void checkForSettingChanges(); + void getWindowInfo(WindowInfo* wi); void checkForUpdates(bool display_message); diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 0cfb425fe..3539d7c6f 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -6,6 +6,7 @@ #include "common/log.h" #include "common/path.h" #include "common/string_util.h" +#include "common/window_info.h" #include "core/cheats.h" #include "core/controller.h" #include "core/game_database.h" @@ -1757,10 +1758,13 @@ void Host::RequestExit(bool save_state_if_running) QMetaObject::invokeMethod(g_main_window, "requestExit", Qt::QueuedConnection, Q_ARG(bool, save_state_if_running)); } -void* Host::GetTopLevelWindowHandle() +std::optional Host::GetTopLevelWindowInfo() { - void* ret = nullptr; - QMetaObject::invokeMethod(g_main_window, &MainWindow::getNativeWindowId, Qt::BlockingQueuedConnection, &ret); + // Normally we'd just feed the std::optional all the way through here. But that won't work because of some bug + // in Qt 6.1, and we can't upgrade that because of raging/abusive Win7 users... to anyone still using that dead + // OS, this is a passive-aggressive "screw you". + WindowInfo ret; + QMetaObject::invokeMethod(g_main_window, "getWindowInfo", Qt::BlockingQueuedConnection, Q_ARG(WindowInfo*, &ret)); return ret; } diff --git a/src/duckstation-qt/qtutils.cpp b/src/duckstation-qt/qtutils.cpp index fa1c96a87..f36d2c362 100644 --- a/src/duckstation-qt/qtutils.cpp +++ b/src/duckstation-qt/qtutils.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,14 @@ #include #include +#if !defined(_WIN32) && !defined(APPLE) +#include +#endif + +#ifdef _WIN32 +#include "common/windows_headers.h" +#endif + namespace QtUtils { QFrame* CreateHorizontalLine(QWidget* parent) @@ -862,4 +871,53 @@ QIcon GetIconForCompatibility(GameDatabase::CompatibilityRating rating) return QIcon(QStringLiteral(":/icons/star-%1.png").arg(static_cast(rating))); } +qreal GetDevicePixelRatioForWidget(const QWidget* widget) +{ + const QScreen* screen_for_ratio = widget->screen(); + if (!screen_for_ratio) + screen_for_ratio = QGuiApplication::primaryScreen(); + + return screen_for_ratio ? screen_for_ratio->devicePixelRatio() : static_cast(1); +} + +std::optional GetWindowInfoForWidget(QWidget* widget) +{ + WindowInfo wi; + + // Windows and Apple are easy here since there's no display connection. +#if defined(_WIN32) + wi.type = WindowInfo::Type::Win32; + wi.window_handle = reinterpret_cast(widget->winId()); +#elif defined(__APPLE__) + wi.type = WindowInfo::Type::MacOS; + wi.window_handle = reinterpret_cast(widget->winId()); +#else + QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface(); + const QString platform_name = QGuiApplication::platformName(); + if (platform_name == QStringLiteral("xcb")) + { + wi.type = WindowInfo::Type::X11; + wi.display_connection = pni->nativeResourceForWindow("display", widget->windowHandle()); + wi.window_handle = reinterpret_cast(widget->winId()); + } + else if (platform_name == QStringLiteral("wayland")) + { + wi.type = WindowInfo::Type::Wayland; + wi.display_connection = pni->nativeResourceForWindow("display", widget->windowHandle()); + wi.window_handle = pni->nativeResourceForWindow("surface", widget->windowHandle()); + } + else + { + qCritical() << "Unknown PNI platform " << platform_name; + return std::nullopt; + } +#endif + + const qreal dpr = GetDevicePixelRatioForWidget(widget); + wi.surface_width = static_cast(static_cast(widget->width()) * dpr); + wi.surface_height = static_cast(static_cast(widget->height()) * dpr); + wi.surface_scale = static_cast(dpr); + return wi; +} + } // namespace QtUtils diff --git a/src/duckstation-qt/qtutils.h b/src/duckstation-qt/qtutils.h index f841b6412..cd13d67c3 100644 --- a/src/duckstation-qt/qtutils.h +++ b/src/duckstation-qt/qtutils.h @@ -1,4 +1,5 @@ #pragma once +#include "common/window_info.h" #include "common/types.h" #include #include @@ -91,4 +92,10 @@ QIcon GetIconForRegion(DiscRegion region); QIcon GetIconForEntryType(GameList::EntryType type); QIcon GetIconForCompatibility(GameDatabase::CompatibilityRating rating); +/// Returns the pixel ratio/scaling factor for a widget. +qreal GetDevicePixelRatioForWidget(const QWidget* widget); + +/// Returns the common window info structure for a Qt widget. +std::optional GetWindowInfoForWidget(QWidget* widget); + } // namespace QtUtils diff --git a/src/frontend-common/common_host.cpp b/src/frontend-common/common_host.cpp index 2146e4476..8a7749cfd 100644 --- a/src/frontend-common/common_host.cpp +++ b/src/frontend-common/common_host.cpp @@ -243,7 +243,7 @@ void CommonHost::OnSystemStarted() FullscreenUI::OnSystemStarted(); if (g_settings.inhibit_screensaver) - FrontendCommon::SuspendScreensaver(g_host_display->GetWindowInfo()); + FrontendCommon::SuspendScreensaver(); } void CommonHost::OnSystemPaused() @@ -261,7 +261,7 @@ void CommonHost::OnSystemResumed() FullscreenUI::OnSystemResumed(); if (g_settings.inhibit_screensaver) - FrontendCommon::SuspendScreensaver(g_host_display->GetWindowInfo()); + FrontendCommon::SuspendScreensaver(); } void CommonHost::OnSystemDestroyed() @@ -361,7 +361,7 @@ void CommonHost::CheckForSettingsChanges(const Settings& old_settings) if (g_settings.inhibit_screensaver != old_settings.inhibit_screensaver) { if (g_settings.inhibit_screensaver) - FrontendCommon::SuspendScreensaver(g_host_display->GetWindowInfo()); + FrontendCommon::SuspendScreensaver(); else FrontendCommon::ResumeScreensaver(); } diff --git a/src/frontend-common/common_host.h b/src/frontend-common/common_host.h index 6bb941724..f6625746f 100644 --- a/src/frontend-common/common_host.h +++ b/src/frontend-common/common_host.h @@ -49,8 +49,3 @@ std::unique_ptr CreateXAudio2Stream(u32 sample_rate, u32 channels, namespace ImGuiManager { void RenderDebugWindows(); } - -namespace Host { -/// Return the current window handle. Needed for DInput. -void* GetTopLevelWindowHandle(); -} // namespace Host \ No newline at end of file diff --git a/src/frontend-common/dinput_source.cpp b/src/frontend-common/dinput_source.cpp index 8bcaeb07e..b806e1ee5 100644 --- a/src/frontend-common/dinput_source.cpp +++ b/src/frontend-common/dinput_source.cpp @@ -85,9 +85,15 @@ bool DInputSource::Initialize(SettingsInterface& si, std::unique_lock(Host::GetTopLevelWindowHandle()); + const std::optional toplevel_wi(Host::GetTopLevelWindowInfo()); + if (!toplevel_wi.has_value() || toplevel_wi->type != WindowInfo::Type::Win32) + { + Log_ErrorPrintf("Missing top level window, cannot add DInput devices."); + return false; + } settings_lock.lock(); + m_toplevel_window = static_cast(toplevel_wi->window_handle); ReloadDevices(); return true; } diff --git a/src/frontend-common/input_manager.h b/src/frontend-common/input_manager.h index 0a9e8611e..9d77acc52 100644 --- a/src/frontend-common/input_manager.h +++ b/src/frontend-common/input_manager.h @@ -9,6 +9,7 @@ #include "common/settings_interface.h" #include "common/types.h" +#include "common/window_info.h" /// Class, or source of an input event. enum class InputSourceType : u32 @@ -308,6 +309,9 @@ std::vector GetInputProfileNames(); } // namespace InputManager namespace Host { +/// Return the current window handle. Needed for DInput. +std::optional GetTopLevelWindowInfo(); + /// Called when a new input device is connected. void OnInputDeviceConnected(const std::string_view& identifier, const std::string_view& device_name); diff --git a/src/frontend-common/platform_misc.h b/src/frontend-common/platform_misc.h index 2c1a6ee58..8b383264a 100644 --- a/src/frontend-common/platform_misc.h +++ b/src/frontend-common/platform_misc.h @@ -1,7 +1,7 @@ #include "common/window_info.h" namespace FrontendCommon { -void SuspendScreensaver(const WindowInfo& wi); +void SuspendScreensaver(); void ResumeScreensaver(); /// Abstracts platform-specific code for asynchronously playing a sound. diff --git a/src/frontend-common/platform_misc_mac.mm b/src/frontend-common/platform_misc_mac.mm index 2cb34725e..b25fbba56 100644 --- a/src/frontend-common/platform_misc_mac.mm +++ b/src/frontend-common/platform_misc_mac.mm @@ -32,13 +32,10 @@ static bool SetScreensaverInhibitMacOS(bool inhibit) } static bool s_screensaver_suspended; -static WindowInfo s_screensaver_suspender; -void FrontendCommon::SuspendScreensaver(const WindowInfo& wi) +void FrontendCommon::SuspendScreensaver() { - if (s_screensaver_suspended && - (s_screensaver_suspender.type != wi.type || s_screensaver_suspender.window_handle != wi.window_handle)) - ResumeScreensaver(); + if (s_screensaver_suspended) if (!SetScreensaverInhibitMacOS(true)) { @@ -46,10 +43,7 @@ void FrontendCommon::SuspendScreensaver(const WindowInfo& wi) return; } - Log_InfoPrintf("Screensaver suspended by 0x%" PRIx64 ".", - static_cast(reinterpret_cast(wi.window_handle))); s_screensaver_suspended = true; - s_screensaver_suspender = wi; } void FrontendCommon::ResumeScreensaver() @@ -59,11 +53,8 @@ void FrontendCommon::ResumeScreensaver() if (!SetScreensaverInhibitMacOS(false)) Log_ErrorPrint("Failed to resume screensaver."); - else - Log_InfoPrint("Screensaver resumed."); s_screensaver_suspended = false; - s_screensaver_suspender = {}; } bool FrontendCommon::PlaySoundAsync(const char* path) diff --git a/src/frontend-common/platform_misc_unix.cpp b/src/frontend-common/platform_misc_unix.cpp index 1f7ae9ecb..70cc79f29 100644 --- a/src/frontend-common/platform_misc_unix.cpp +++ b/src/frontend-common/platform_misc_unix.cpp @@ -1,6 +1,7 @@ #include "common/log.h" #include "common/string.h" #include "platform_misc.h" +#include "input_manager.h" #include Log_SetChannel(FrontendCommon); @@ -36,40 +37,42 @@ static bool SetScreensaverInhibitX11(bool inhibit, const WindowInfo& wi) #endif // USE_X11 -static bool SetScreensaverInhibit(bool inhibit, const WindowInfo& wi) +static bool SetScreensaverInhibit(bool inhibit) { - switch (wi.type) + std::optional wi(Host::GetTopLevelWindowInfo()); + if (!wi.has_value()) + { + Log_ErrorPrintf("No top-level window."); + return false; + } + + switch (wi->type) { #ifdef USE_X11 case WindowInfo::Type::X11: - return SetScreensaverInhibitX11(inhibit, wi); + return SetScreensaverInhibitX11(inhibit, wi.value()); #endif default: - Log_ErrorPrintf("Unknown type: %u", static_cast(wi.type)); + Log_ErrorPrintf("Unknown type: %u", static_cast(wi->type)); return false; } } static bool s_screensaver_suspended; -static WindowInfo s_screensaver_suspender; -void FrontendCommon::SuspendScreensaver(const WindowInfo& wi) +void FrontendCommon::SuspendScreensaver() { - if (s_screensaver_suspended && - (s_screensaver_suspender.type != wi.type || s_screensaver_suspender.window_handle != wi.window_handle)) - ResumeScreensaver(); + if (s_screensaver_suspended) + return; - if (!SetScreensaverInhibit(true, wi)) + if (!SetScreensaverInhibit(true)) { Log_ErrorPrintf("Failed to suspend screensaver."); return; } - Log_InfoPrintf("Screensaver suspended by 0x%" PRIx64 ".", - static_cast(reinterpret_cast(wi.window_handle))); s_screensaver_suspended = true; - s_screensaver_suspender = wi; } void FrontendCommon::ResumeScreensaver() @@ -77,13 +80,10 @@ void FrontendCommon::ResumeScreensaver() if (!s_screensaver_suspended) return; - if (!SetScreensaverInhibit(false, s_screensaver_suspender)) + if (!SetScreensaverInhibit(false)) Log_ErrorPrint("Failed to resume screensaver."); - else - Log_InfoPrint("Screensaver resumed."); s_screensaver_suspended = false; - s_screensaver_suspender = {}; } bool FrontendCommon::PlaySoundAsync(const char* path) diff --git a/src/frontend-common/platform_misc_win32.cpp b/src/frontend-common/platform_misc_win32.cpp index e3179b326..1cf3a2789 100644 --- a/src/frontend-common/platform_misc_win32.cpp +++ b/src/frontend-common/platform_misc_win32.cpp @@ -20,13 +20,11 @@ static bool SetScreensaverInhibitWin32(bool inhibit) } static bool s_screensaver_suspended; -static WindowInfo s_screensaver_suspender; -void FrontendCommon::SuspendScreensaver(const WindowInfo& wi) +void FrontendCommon::SuspendScreensaver() { - if (s_screensaver_suspended && - (s_screensaver_suspender.type != wi.type || s_screensaver_suspender.window_handle != wi.window_handle)) - ResumeScreensaver(); + if (s_screensaver_suspended) + return; if (!SetScreensaverInhibitWin32(true)) { @@ -34,10 +32,7 @@ void FrontendCommon::SuspendScreensaver(const WindowInfo& wi) return; } - Log_InfoPrintf("Screensaver suspended by 0x%" PRIx64 ".", - static_cast(reinterpret_cast(wi.window_handle))); s_screensaver_suspended = true; - s_screensaver_suspender = wi; } void FrontendCommon::ResumeScreensaver() @@ -47,11 +42,8 @@ void FrontendCommon::ResumeScreensaver() if (!SetScreensaverInhibitWin32(false)) Log_ErrorPrint("Failed to resume screensaver."); - else - Log_InfoPrint("Screensaver resumed."); s_screensaver_suspended = false; - s_screensaver_suspender = {}; } bool FrontendCommon::PlaySoundAsync(const char* path)