Skip to content

Commit

Permalink
Windows 11: Disable Window rounding
Browse files Browse the repository at this point in the history
This looses pixels in the edges of the game.

No error check. Will silently fail when unsupported.
  • Loading branch information
Ghabry committed Apr 11, 2024
1 parent 799cbba commit 9877d73
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,10 @@ if(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2")
target_sources(${PROJECT_NAME} PRIVATE
src/platform/wiiu/input_buttons.cpp)
endif()

if(WIN32)
target_link_libraries(${PROJECT_NAME} "Dwmapi")
endif()
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL1")
target_sources(${PROJECT_NAME} PRIVATE
src/platform/sdl/sdl_audio.cpp
Expand Down
35 changes: 24 additions & 11 deletions src/platform/sdl/sdl2_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifdef _WIN32
# include <windows.h>
# include <SDL_syswm.h>
# include <dwmapi.h>
#elif defined(__ANDROID__)
# include <jni.h>
# include <SDL_system.h>
Expand Down Expand Up @@ -118,6 +119,19 @@ static uint32_t SelectFormat(const SDL_RendererInfo& rinfo, bool print_all) {
return current_fmt;
}

#ifdef _WIN32
HWND GetWindowHandle(SDL_Window* window) {
SDL_SysWMinfo wminfo;
SDL_VERSION(&wminfo.version)
SDL_bool success = SDL_GetWindowWMInfo(window, &wminfo);

if (success < 0)
Output::Error("Wrong SDL version");

return wminfo.info.win.window;
}
#endif

static int FilterUntilFocus(const SDL_Event* evnt);

#if defined(USE_KEYBOARD) && defined(SUPPORT_KEYBOARD)
Expand Down Expand Up @@ -354,8 +368,8 @@ bool Sdl2Ui::RefreshDisplayMode() {
window.size_changed = true;

auto window_sg = lcf::makeScopeGuard([&]() {
SDL_DestroyWindow(sdl_window);
sdl_window = nullptr;
SDL_DestroyWindow(sdl_window);
sdl_window = nullptr;
});

SetAppIcon();
Expand Down Expand Up @@ -415,6 +429,13 @@ bool Sdl2Ui::RefreshDisplayMode() {
return false;
}

#ifdef _WIN32
HWND window = GetWindowHandle(sdl_window);
// Not using the enum names because this will fail to build when not using a recent Windows 11 SDK
int window_rounding = 1; // DWMWCP_DONOTROUND
DwmSetWindowAttribute(window, 33 /* DWMWA_WINDOW_CORNER_PREFERENCE */, &window_rounding, sizeof(window_rounding));
#endif

renderer_sg.Dismiss();
window_sg.Dismiss();
} else {
Expand Down Expand Up @@ -973,14 +994,6 @@ void Sdl2Ui::SetAppIcon() {
#if defined(__MORPHOS__)
// do nothing
#elif defined(_WIN32)
SDL_SysWMinfo wminfo;
SDL_VERSION(&wminfo.version)
SDL_bool success = SDL_GetWindowWMInfo(sdl_window, &wminfo);

if (success < 0)
Output::Error("Wrong SDL version");

HWND window;
HINSTANCE handle = GetModuleHandle(NULL);
HICON icon = LoadIcon(handle, MAKEINTRESOURCE(23456));
HICON icon_small = (HICON) LoadImage(handle, MAKEINTRESOURCE(23456), IMAGE_ICON,
Expand All @@ -989,7 +1002,7 @@ void Sdl2Ui::SetAppIcon() {
if (icon == NULL || icon_small == NULL)
Output::Warning("Could not load window icon.");

window = wminfo.info.win.window;
HWND window = GetWindowHandle(sdl_window);
SetClassLongPtr(window, GCLP_HICON, (LONG_PTR) icon);
SetClassLongPtr(window, GCLP_HICONSM, (LONG_PTR) icon_small);
#else
Expand Down

0 comments on commit 9877d73

Please sign in to comment.