mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-04 05:04:33 +00:00
Qt: Move window corner rounding out of PlatformMisc
This commit is contained in:
@@ -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<void*>(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<void*>(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<void*>(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<void*>(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<void*>(widget->winId()), false);
|
||||
QtUtils::SetWindowRoundedCornerState(widget, false);
|
||||
#endif
|
||||
|
||||
const std::optional<WindowInfo>& owi = widget->getWindowInfo(render_api, error);
|
||||
|
||||
@@ -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<HWND>(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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "common/windows_headers.h"
|
||||
#include <Psapi.h>
|
||||
#include <WinSock2.h>
|
||||
#include <dwmapi.h>
|
||||
|
||||
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<HWND>(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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user