From 5dac1beb7bd29604142988961d69ac2c17be1f86 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 2 Feb 2021 15:01:01 +0200 Subject: Linux: Use SDL to query display monitor DPI value IssueID #133 --- src/app.c | 8 ++++++++ src/ui/window.c | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/app.c b/src/app.c index f44fdf4f..a2d80bf2 100644 --- a/src/app.c +++ b/src/app.c @@ -373,6 +373,14 @@ static void init_App_(iApp *d, int argc, char **argv) { #if defined (iPlatformMsys) /* Must scale by UI scaling factor. */ mulfv_I2(&d->initialWindowRect.size, desktopDPI_Win32()); +#endif +#if defined (iPlatformLinux) + /* Scale by the primary (?) monitor DPI. */ { + float vdpi; + SDL_GetDisplayDPI(0, NULL, NULL, &vdpi); + const float factor = vdpi / 96.0f; + mulfv_I2(&d->initialWindowRect.size, iMax(factor, 1.0f)); + } #endif init_Prefs(&d->prefs); setCStr_String(&d->prefs.downloadDir, downloadDir_App_); diff --git a/src/ui/window.c b/src/ui/window.c index 8df92706..f8123a17 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -685,7 +685,12 @@ static float pixelRatio_Window_(const iWindow *d) { #if defined (iPlatformMsys) iUnused(d); return desktopDPI_Win32(); -#else +#elif defined (iPlatformLinux) + float vdpi = 0.0f; + SDL_GetDisplayDPI(SDL_GetWindowDisplayIndex(d->win), NULL, NULL, &vdpi); + const float factor = vdpi / 96.0f; + return iMax(1.0f, factor); +#else int dx, x; SDL_GetRendererOutputSize(d->render, &dx, NULL); SDL_GetWindowSize(d->win, &x, NULL); @@ -764,6 +769,7 @@ void init_Window(iWindow *d, iRect rect) { useExecutableIconResource_SDLWindow(d->win); #endif #if defined (iPlatformLinux) + SDL_SetWindowMinimumSize(d->win, minSize.x * d->pixelRatio, minSize.y * d->pixelRatio); /* Load the window icon. */ { int w, h, num; const iBlock *icon = &imageLagrange64_Embedded; @@ -1033,7 +1039,7 @@ iInt2 rootSize_Window(const iWindow *d) { } iInt2 coord_Window(const iWindow *d, int x, int y) { -#if defined (iPlatformMsys) +#if defined (iPlatformMsys) || defined (iPlatformLinux) /* On Windows, surface coordinates are in pixels. */ return init_I2(x, y); #else -- cgit v1.2.3