diff --git a/CMakeLists.txt b/CMakeLists.txt index 23e1bf41211..40535dc7ca9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/platform/sdl/sdl2_ui.cpp b/src/platform/sdl/sdl2_ui.cpp index 6156bf2e1f7..6e5255166d6 100644 --- a/src/platform/sdl/sdl2_ui.cpp +++ b/src/platform/sdl/sdl2_ui.cpp @@ -25,6 +25,7 @@ #ifdef _WIN32 # include # include +# include #elif defined(__ANDROID__) # include # include @@ -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) @@ -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(); @@ -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 { @@ -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, @@ -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