Skip to content

Commit

Permalink
Remove rounded corners on emulation render window
Browse files Browse the repository at this point in the history
On Windows 11, when playing windowed in a separate window/widget from the main emulator window, we don't want the window to have rounded corners, as it prevents the corner pixels from being visible
  • Loading branch information
Filoppi committed Apr 28, 2024
1 parent e69486d commit 9106704
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Source/Core/DolphinNoGUI/PlatformWin32.cpp
Expand Up @@ -13,6 +13,7 @@
#include <Windows.h>
#include <climits>
#include <cstdio>
#include <dwmapi.h>

#include "VideoCommon/Present.h"
#include "resource.h"
Expand Down Expand Up @@ -180,6 +181,18 @@ LRESULT PlatformWin32::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam
return DefWindowProc(hwnd, msg, wParam, lParam);
}

case WM_CREATE:
{
if (hwnd)
{
// Remove rounded corners from the render window on Windows 11
const DWM_WINDOW_CORNER_PREFERENCE corner_preference = DWMWCP_DONOTROUND;
DwmSetWindowAttribute(hwnd, DWMWA_WINDOW_CORNER_PREFERENCE, &corner_preference,
sizeof(corner_preference));
}
}
break;

case WM_SIZE:
{
if (g_presenter)
Expand Down
17 changes: 16 additions & 1 deletion Source/Core/DolphinQt/RenderWidget.cpp
Expand Up @@ -37,6 +37,7 @@

#ifdef _WIN32
#include <Windows.h>
#include <dwmapi.h>
#endif

RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent)
Expand Down Expand Up @@ -69,7 +70,7 @@ RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent)
// (which results in them not getting called)
connect(this, &RenderWidget::StateChanged, Host::GetInstance(), &Host::SetRenderFullscreen,
Qt::DirectConnection);
connect(this, &RenderWidget::HandleChanged, Host::GetInstance(), &Host::SetRenderHandle,
connect(this, &RenderWidget::HandleChanged, this, &RenderWidget::OnHandleChanged,
Qt::DirectConnection);
connect(this, &RenderWidget::SizeChanged, Host::GetInstance(), &Host::ResizeSurface,
Qt::DirectConnection);
Expand Down Expand Up @@ -133,6 +134,20 @@ void RenderWidget::dropEvent(QDropEvent* event)
State::LoadAs(Core::System::GetInstance(), path.toStdString());
}

void RenderWidget::OnHandleChanged(void* handle)
{
if (handle)
{
#ifdef _WIN32
// Remove rounded corners from the render window on Windows 11
const DWM_WINDOW_CORNER_PREFERENCE corner_preference = DWMWCP_DONOTROUND;
DwmSetWindowAttribute(reinterpret_cast<HWND>(handle), DWMWA_WINDOW_CORNER_PREFERENCE,
&corner_preference, sizeof(corner_preference));
#endif
}
Host::GetInstance()->SetRenderHandle(handle);
}

void RenderWidget::OnHideCursorChanged()
{
UpdateCursor();
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/RenderWidget.h
Expand Up @@ -34,6 +34,7 @@ class RenderWidget final : public QWidget

private:
void HandleCursorTimer();
void OnHandleChanged(void* handle);
void OnHideCursorChanged();
void OnNeverHideCursorChanged();
void OnLockCursorChanged();
Expand Down

0 comments on commit 9106704

Please sign in to comment.