From fbad0cc670fc12f135af2a60f4af2aa9bd93cf9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Sun, 29 Aug 2021 15:52:06 +0300 Subject: [PATCH 1/1] Fixed running under KMSDRM video driver on Linux SDL2 works fine without a window system, but it seems the DPI-querying API will crash so let's not call that. Should still add command line options to control the screen resolution, i.e., overriding the window size. --- src/app.c | 14 +++++++++++++- src/app.h | 2 ++ src/ui/window.c | 13 ++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/app.c b/src/app.c index bf781c03..f8dc5697 100644 --- a/src/app.c +++ b/src/app.c @@ -122,6 +122,7 @@ struct Impl_App { uint32_t lastTickerTime; uint32_t elapsedSinceLastTicker; iBool isRunning; + iBool isRunningUnderWindowSystem; #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) iBool isIdling; uint32_t lastEventTime; @@ -626,6 +627,12 @@ static iBool hasCommandLineOpenableScheme_(const iRangecc uri) { } static void init_App_(iApp *d, int argc, char **argv) { +#if defined (iPlatformLinux) + d->isRunningUnderWindowSystem = !iCmpStr(SDL_GetCurrentVideoDriver(), "x11") || + !iCmpStr(SDL_GetCurrentVideoDriver(), "wayland"); +#else + d->isRunningUnderWindowSystem = iTrue; +#endif init_CommandLine(&d->args, argc, argv); /* Where was the app started from? We ask SDL first because the command line alone is not a reliable source of this information, particularly when it comes to different @@ -749,7 +756,8 @@ static void init_App_(iApp *d, int argc, char **argv) { mulfv_I2(&d->initialWindowRect.size, desktopDPI_Win32()); #endif #if defined (iPlatformLinux) - /* Scale by the primary (?) monitor DPI. */ { + /* Scale by the primary (?) monitor DPI. */ + if (isRunningUnderWindowSystem_App()) { float vdpi; SDL_GetDisplayDPI(0, NULL, NULL, &vdpi); const float factor = vdpi / 96.0f; @@ -1582,6 +1590,10 @@ enum iAppDeviceType deviceType_App(void) { #endif } +iBool isRunningUnderWindowSystem_App(void) { + return app_.isRunningUnderWindowSystem; +} + iGmCerts *certs_App(void) { return app_.certs; } diff --git a/src/app.h b/src/app.h index 5d1d42e1..55bec5a6 100644 --- a/src/app.h +++ b/src/app.h @@ -87,6 +87,8 @@ iBool isLandscape_App (void); iLocalDef iBool isPortrait_App (void) { return !isLandscape_App(); } enum iAppDeviceType deviceType_App (void); iLocalDef iBool isPortraitPhone_App (void) { return isPortrait_App() && deviceType_App() == phone_AppDeviceType; } +iBool isRunningUnderWindowSystem_App (void); + iGmCerts * certs_App (void); iVisited * visited_App (void); iBookmarks * bookmarks_App (void); diff --git a/src/ui/window.c b/src/ui/window.c index ebb4d1a8..f8391ed9 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -278,11 +278,14 @@ static float displayScale_Window_(const iWindow *d) { iUnused(d); return desktopDPI_Win32(); #else - float vdpi = 0.0f; - SDL_GetDisplayDPI(SDL_GetWindowDisplayIndex(d->win), NULL, NULL, &vdpi); -// printf("DPI: %f\n", vdpi); - const float factor = vdpi / baseDPI_Window / pixelRatio_Window_(d); - return iMax(1.0f, factor); + if (isRunningUnderWindowSystem_App()) { + float vdpi = 0.0f; + SDL_GetDisplayDPI(SDL_GetWindowDisplayIndex(d->win), NULL, NULL, &vdpi); +// printf("DPI: %f\n", vdpi); + const float factor = vdpi / baseDPI_Window / pixelRatio_Window_(d); + return iMax(1.0f, factor); + } + return 1.0f; #endif } -- 2.34.1