summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-08-29 15:52:06 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-08-29 15:53:41 +0300
commitfbad0cc670fc12f135af2a60f4af2aa9bd93cf9c (patch)
tree2100291c635de90389688533171d12fa6a52b8ed /src
parentf01530f64b1e3951e0239ac8d2000cef57e814ba (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/app.c14
-rw-r--r--src/app.h2
-rw-r--r--src/ui/window.c13
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 {
122 uint32_t lastTickerTime; 122 uint32_t lastTickerTime;
123 uint32_t elapsedSinceLastTicker; 123 uint32_t elapsedSinceLastTicker;
124 iBool isRunning; 124 iBool isRunning;
125 iBool isRunningUnderWindowSystem;
125#if defined (LAGRANGE_ENABLE_IDLE_SLEEP) 126#if defined (LAGRANGE_ENABLE_IDLE_SLEEP)
126 iBool isIdling; 127 iBool isIdling;
127 uint32_t lastEventTime; 128 uint32_t lastEventTime;
@@ -626,6 +627,12 @@ static iBool hasCommandLineOpenableScheme_(const iRangecc uri) {
626} 627}
627 628
628static void init_App_(iApp *d, int argc, char **argv) { 629static void init_App_(iApp *d, int argc, char **argv) {
630#if defined (iPlatformLinux)
631 d->isRunningUnderWindowSystem = !iCmpStr(SDL_GetCurrentVideoDriver(), "x11") ||
632 !iCmpStr(SDL_GetCurrentVideoDriver(), "wayland");
633#else
634 d->isRunningUnderWindowSystem = iTrue;
635#endif
629 init_CommandLine(&d->args, argc, argv); 636 init_CommandLine(&d->args, argc, argv);
630 /* Where was the app started from? We ask SDL first because the command line alone is 637 /* Where was the app started from? We ask SDL first because the command line alone is
631 not a reliable source of this information, particularly when it comes to different 638 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) {
749 mulfv_I2(&d->initialWindowRect.size, desktopDPI_Win32()); 756 mulfv_I2(&d->initialWindowRect.size, desktopDPI_Win32());
750#endif 757#endif
751#if defined (iPlatformLinux) 758#if defined (iPlatformLinux)
752 /* Scale by the primary (?) monitor DPI. */ { 759 /* Scale by the primary (?) monitor DPI. */
760 if (isRunningUnderWindowSystem_App()) {
753 float vdpi; 761 float vdpi;
754 SDL_GetDisplayDPI(0, NULL, NULL, &vdpi); 762 SDL_GetDisplayDPI(0, NULL, NULL, &vdpi);
755 const float factor = vdpi / 96.0f; 763 const float factor = vdpi / 96.0f;
@@ -1582,6 +1590,10 @@ enum iAppDeviceType deviceType_App(void) {
1582#endif 1590#endif
1583} 1591}
1584 1592
1593iBool isRunningUnderWindowSystem_App(void) {
1594 return app_.isRunningUnderWindowSystem;
1595}
1596
1585iGmCerts *certs_App(void) { 1597iGmCerts *certs_App(void) {
1586 return app_.certs; 1598 return app_.certs;
1587} 1599}
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);
87iLocalDef iBool isPortrait_App (void) { return !isLandscape_App(); } 87iLocalDef iBool isPortrait_App (void) { return !isLandscape_App(); }
88enum iAppDeviceType deviceType_App (void); 88enum iAppDeviceType deviceType_App (void);
89iLocalDef iBool isPortraitPhone_App (void) { return isPortrait_App() && deviceType_App() == phone_AppDeviceType; } 89iLocalDef iBool isPortraitPhone_App (void) { return isPortrait_App() && deviceType_App() == phone_AppDeviceType; }
90iBool isRunningUnderWindowSystem_App (void);
91
90iGmCerts * certs_App (void); 92iGmCerts * certs_App (void);
91iVisited * visited_App (void); 93iVisited * visited_App (void);
92iBookmarks * bookmarks_App (void); 94iBookmarks * 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) {
278 iUnused(d); 278 iUnused(d);
279 return desktopDPI_Win32(); 279 return desktopDPI_Win32();
280#else 280#else
281 float vdpi = 0.0f; 281 if (isRunningUnderWindowSystem_App()) {
282 SDL_GetDisplayDPI(SDL_GetWindowDisplayIndex(d->win), NULL, NULL, &vdpi); 282 float vdpi = 0.0f;
283// printf("DPI: %f\n", vdpi); 283 SDL_GetDisplayDPI(SDL_GetWindowDisplayIndex(d->win), NULL, NULL, &vdpi);
284 const float factor = vdpi / baseDPI_Window / pixelRatio_Window_(d); 284// printf("DPI: %f\n", vdpi);
285 return iMax(1.0f, factor); 285 const float factor = vdpi / baseDPI_Window / pixelRatio_Window_(d);
286 return iMax(1.0f, factor);
287 }
288 return 1.0f;
286#endif 289#endif
287} 290}
288 291