From 8135aefacfcd966274a04b05dc64574aa3d5996a Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 17 Jan 2026 16:23:28 +1000 Subject: [PATCH] Qt: Move window corner rounding out of PlatformMisc --- src/duckstation-qt/mainwindow.cpp | 14 +++++--------- src/duckstation-qt/qtwindowinfo.cpp | 18 ++++++++++++++++++ src/duckstation-qt/qtwindowinfo.h | 8 ++++++++ src/util/platform_misc.h | 4 ---- src/util/platform_misc_mac.mm | 6 ------ src/util/platform_misc_unix.cpp | 6 ------ src/util/platform_misc_win32.cpp | 11 ----------- 7 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index fe2fab90d..440400c71 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -390,7 +390,7 @@ void MainWindow::createDisplayWidget(bool fullscreen, bool render_to_main) #ifdef _WIN32 if (s_locals.disable_window_rounded_corners) - PlatformMisc::SetWindowRoundedCornerState(reinterpret_cast(container->winId()), false); + QtUtils::SetWindowRoundedCornerState(container, false); #endif } else @@ -1898,7 +1898,7 @@ void MainWindow::setupAdditionalUi() #ifdef _WIN32 s_locals.disable_window_rounded_corners = Core::GetBaseBoolSettingValue("Main", "DisableWindowRoundedCorners", false); if (s_locals.disable_window_rounded_corners) - PlatformMisc::SetWindowRoundedCornerState(reinterpret_cast(winId()), false); + QtUtils::SetWindowRoundedCornerState(this, false); #endif QtUtils::StyleChildMenus(this); @@ -3074,14 +3074,10 @@ void MainWindow::checkForSettingChanges() disable_window_rounded_corners != s_locals.disable_window_rounded_corners) { s_locals.disable_window_rounded_corners = disable_window_rounded_corners; - PlatformMisc::SetWindowRoundedCornerState(reinterpret_cast(winId()), - !s_locals.disable_window_rounded_corners); + QtUtils::SetWindowRoundedCornerState(this, !s_locals.disable_window_rounded_corners); if (QWidget* container = getDisplayContainer(); container && !container->parent() && !container->isFullScreen()) - { - PlatformMisc::SetWindowRoundedCornerState(reinterpret_cast(container->winId()), - !s_locals.disable_window_rounded_corners); - } + QtUtils::SetWindowRoundedCornerState(container, !s_locals.disable_window_rounded_corners); } #endif @@ -3244,7 +3240,7 @@ bool MainWindow::onCreateAuxiliaryRenderWindow(RenderAPI render_api, qint32 x, q #ifdef _WIN32 if (s_locals.disable_window_rounded_corners) - PlatformMisc::SetWindowRoundedCornerState(reinterpret_cast(widget->winId()), false); + QtUtils::SetWindowRoundedCornerState(widget, false); #endif const std::optional& owi = widget->getWindowInfo(render_api, error); diff --git a/src/duckstation-qt/qtwindowinfo.cpp b/src/duckstation-qt/qtwindowinfo.cpp index 5673790a5..7fd8f2ba0 100644 --- a/src/duckstation-qt/qtwindowinfo.cpp +++ b/src/duckstation-qt/qtwindowinfo.cpp @@ -310,3 +310,21 @@ bool Host::SetScreensaverInhibit(bool inhibit, Error* error) #endif } + +#ifdef _WIN32 + +bool QtUtils::SetWindowRoundedCornerState(QWidget* widget, bool enabled) +{ + const HWND window_handle = reinterpret_cast(widget->winId()); + const DWM_WINDOW_CORNER_PREFERENCE value = enabled ? DWMWCP_DEFAULT : DWMWCP_DONOTROUND; + const HRESULT hr = DwmSetWindowAttribute(window_handle, DWMWA_WINDOW_CORNER_PREFERENCE, &value, sizeof(value)); + if (FAILED(hr)) + { + ERROR_LOG("DwmSetWindowAttribute(DWMWA_WINDOW_CORNER_PREFERENCE) failed: ", + Error::CreateHResult(hr).GetDescription()); + } + + return SUCCEEDED(hr); +} + +#endif // _WIN32 diff --git a/src/duckstation-qt/qtwindowinfo.h b/src/duckstation-qt/qtwindowinfo.h index 4e2f5296f..a82de1c01 100644 --- a/src/duckstation-qt/qtwindowinfo.h +++ b/src/duckstation-qt/qtwindowinfo.h @@ -26,4 +26,12 @@ void UpdateSurfaceSize(QWidget* widget, WindowInfo* wi); /// Changes the screensaver inhibit state. bool SetScreensaverInhibit(bool inhibit, Error* error); +#ifdef _WIN32 + +/// Sets the rounded corner state for a window. +/// Currently only supported on Windows. +bool SetWindowRoundedCornerState(QWidget* widget, bool enabled); + +#endif + } // namespace QtUtils diff --git a/src/util/platform_misc.h b/src/util/platform_misc.h index f834e62a5..2ef14caf1 100644 --- a/src/util/platform_misc.h +++ b/src/util/platform_misc.h @@ -11,10 +11,6 @@ namespace PlatformMisc { bool InitializeSocketSupport(Error* error); -/// Sets the rounded corner state for a window. -/// Currently only supported on Windows. -bool SetWindowRoundedCornerState(void* window_handle, bool enabled, Error* error = nullptr); - } // namespace PlatformMisc namespace Host { diff --git a/src/util/platform_misc_mac.mm b/src/util/platform_misc_mac.mm index 96d84a465..e04f5b191 100644 --- a/src/util/platform_misc_mac.mm +++ b/src/util/platform_misc_mac.mm @@ -27,12 +27,6 @@ bool PlatformMisc::InitializeSocketSupport(Error* error) return true; } -bool PlatformMisc::SetWindowRoundedCornerState(void* window_handle, bool enabled, Error* error /* = nullptr */) -{ - Error::SetStringView(error, "Unsupported on this platform."); - return false; -} - void* CocoaTools::CreateMetalLayer(const WindowInfo& wi, Error* error) { // Punt off to main thread if we're not calling from it already. diff --git a/src/util/platform_misc_unix.cpp b/src/util/platform_misc_unix.cpp index 235fd4d8e..a8ece9d08 100644 --- a/src/util/platform_misc_unix.cpp +++ b/src/util/platform_misc_unix.cpp @@ -29,9 +29,3 @@ bool PlatformMisc::InitializeSocketSupport(Error* error) return true; } - -bool PlatformMisc::SetWindowRoundedCornerState(void* window_handle, bool enabled, Error* error /* = nullptr */) -{ - Error::SetStringView(error, "Unsupported on this platform."); - return false; -} diff --git a/src/util/platform_misc_win32.cpp b/src/util/platform_misc_win32.cpp index 82995aa4c..5ac22c0d7 100644 --- a/src/util/platform_misc_win32.cpp +++ b/src/util/platform_misc_win32.cpp @@ -16,7 +16,6 @@ #include "common/windows_headers.h" #include #include -#include LOG_CHANNEL(PlatformMisc); @@ -45,13 +44,3 @@ bool PlatformMisc::InitializeSocketSupport(Error* error) return s_winsock_initialized; } -bool PlatformMisc::SetWindowRoundedCornerState(void* window_handle, bool enabled, Error* error) -{ - const DWM_WINDOW_CORNER_PREFERENCE value = enabled ? DWMWCP_DEFAULT : DWMWCP_DONOTROUND; - const HRESULT hr = - DwmSetWindowAttribute(static_cast(window_handle), DWMWA_WINDOW_CORNER_PREFERENCE, &value, sizeof(value)); - if (FAILED(hr)) - Error::SetHResult(error, "DwmSetWindowAttribute(DWMWA_WINDOW_CORNER_PREFERENCE) failed: ", hr); - - return SUCCEEDED(hr); -}