Skip to content

Commit

Permalink
sdl: generalize window scale code
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Oct 15, 2024
1 parent 42fa44f commit 1a65a8a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/sdl/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#endif

#include <ctype.h>
#include <math.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -457,16 +458,13 @@ int main(int argc, char **argv) {
sdl_resize_window(0, false, false);
SDL_StartTextInput(window);

#ifdef _WIN32
{
float dpi = 0.0f;
int display_index = SDL_GetDisplayForWindow(window);
if (display_index >= 0 && !SDL_GetDisplayDPI(display_index, &dpi, NULL, NULL) && dpi > 96.0f) {
sdl_resize_window((int) ceil(dpi / 96.0f), false, true);
float scale = SDL_GetWindowDisplayScale(window);
if (scale > 1.0f) {
sdl_resize_window((int) ceil(scale / 1.0f), false, true);
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}
}
#endif

const SDL_AudioSpec audio_spec = { SDL_AUDIO_S16LE, 1, 48000 };
audio_stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audio_spec, audio_callback, NULL);
Expand Down

0 comments on commit 1a65a8a

Please sign in to comment.