Skip to content

Commit

Permalink
Windows: load and call SetProcessDPIAware in platform_init
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceLR committed Apr 10, 2020
1 parent a250958 commit a5fba89
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.txt
Expand Up @@ -34,6 +34,9 @@ USERS
decreased the size of the output HTML files somewhat.
+ Fixed libxmp playback for S3Ms containing ADPCM4 samples. This
fixes mm2flash.s3m in ZeuxDrop.
+ Windows builds now attempt to load and call SetProcessDPIAware
on startup. This should fix undesirable DPI-related scaling
and fullscreen bugs.

DEVELOPERS

Expand Down
40 changes: 40 additions & 0 deletions src/platform_sdl.c
Expand Up @@ -56,6 +56,42 @@ Uint32 get_ticks(void)
return SDL_GetTicks();
}

#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

/**
* Set DPI awareness for Windows to avoid bad window scaling and various
* fullscreen-related bugs. This function was added in Windows Vista so it
* needs to be dynamically loaded.
*/
static void set_dpi_aware(void)
{
BOOL (*_SetProcessDPIAware)(void) = NULL;
void *handle;

handle = SDL_LoadObject("User32.dll");
if(handle)
{
void **dest = (void **)&_SetProcessDPIAware;
*dest = SDL_LoadFunction(handle, "SetProcessDPIAware");

if(_SetProcessDPIAware && !_SetProcessDPIAware())
{
warn("failed to SetProcessDPIAware!\n");
}
else

if(!_SetProcessDPIAware)
debug("couldn't load SetProcessDPIAware.\n");

SDL_UnloadObject(handle);
}
else
debug("couldn't load User32.dll: %s\n", SDL_GetError());
}
#endif

boolean platform_init(void)
{
Uint32 flags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
Expand All @@ -81,6 +117,10 @@ boolean platform_init(void)
flags |= SDL_INIT_AUDIO;
#endif

#ifdef __WIN32__
set_dpi_aware();
#endif

if(SDL_Init(flags) < 0)
{
debug("Failed to initialize SDL; attempting with joystick support disabled: %s\n", SDL_GetError());
Expand Down

0 comments on commit a5fba89

Please sign in to comment.