From d9a9fe554ff491670afef2b0291abc363570ea65 Mon Sep 17 00:00:00 2001 From: Carlos Aragones <> Date: Mon, 21 Sep 2020 14:38:51 +0200 Subject: [PATCH] Added to iOS not working on X11 & Wayland --- CMakeLists.txt | 1 + src/ios/iOSMiniFB.m | 22 ++++++++++++++++++++++ src/macosx/MacMiniFB.m | 1 - src/wayland/WaylandMiniFB.c | 27 +++++++++++++++++++++++++++ src/x11/X11MiniFB.c | 37 +++++++++++++++++++++++++++++++++++++ tests/ios/AppDelegate.m | 3 ++- 6 files changed, 89 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8364455..457c6af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -230,6 +230,7 @@ elseif(UNIX) else() target_link_libraries(minifb "-lX11" + #"-lXrandr" DPI NOT WORKING ) if(USE_OPENGL_API) target_link_libraries(minifb diff --git a/src/ios/iOSMiniFB.m b/src/ios/iOSMiniFB.m index 847c307..cb5e4ea 100644 --- a/src/ios/iOSMiniFB.m +++ b/src/ios/iOSMiniFB.m @@ -248,3 +248,25 @@ mfb_timer_init() { g_timer_resolution = 1.0 / g_timer_frequency; } +//------------------------------------- +void +mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) { + (void) window; + float scale = 1.0f; + + scale = [[UIScreen mainScreen] scale]; + + if (dpi_x) { + *dpi_x = scale; + if(*dpi_x == 0) { + *dpi_x = 1; + } + } + + if (dpi_y) { + *dpi_y = scale; + if (*dpi_y == 0) { + *dpi_y = 1; + } + } +} diff --git a/src/macosx/MacMiniFB.m b/src/macosx/MacMiniFB.m index 059c00f..34c431b 100644 --- a/src/macosx/MacMiniFB.m +++ b/src/macosx/MacMiniFB.m @@ -579,6 +579,5 @@ mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) { *dpi_y = 1; } } - } diff --git a/src/wayland/WaylandMiniFB.c b/src/wayland/WaylandMiniFB.c index cc4e672..a7a4528 100644 --- a/src/wayland/WaylandMiniFB.c +++ b/src/wayland/WaylandMiniFB.c @@ -996,3 +996,30 @@ mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y return false; } +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void +mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) { + float x = 96.0, y = 96.0; + + if(window != 0x0) { + //SWindowData *window_data = (SWindowData *) window; + //SWindowData_X11 *window_data_x11 = (SWindowData_X11 *) window_data->specific; + + // I cannot find a way to get dpi under VirtualBox + } + + if (dpi_x) { + *dpi_x = x / 96.0f; + if(*dpi_x == 0) { + *dpi_x = 1.0f; + } + } + + if (dpi_y) { + *dpi_y = y / 96.0f; + if (*dpi_y == 0) { + *dpi_y = 1.0f; + } + } +} diff --git a/src/x11/X11MiniFB.c b/src/x11/X11MiniFB.c index a7c4f8c..6730ea0 100644 --- a/src/x11/X11MiniFB.c +++ b/src/x11/X11MiniFB.c @@ -4,6 +4,11 @@ #include #include #include + +// I cannot find a way to get dpi under VirtualBox +//#include +//#include + #include #include #include @@ -789,3 +794,35 @@ mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y return true; } + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void +mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) { + float x = 96.0, y = 96.0; + + if(window != 0x0) { + //SWindowData *window_data = (SWindowData *) window; + //SWindowData_X11 *window_data_x11 = (SWindowData_X11 *) window_data->specific; + + // I cannot find a way to get dpi under VirtualBox + // XrmGetResource "Xft.dpi", "Xft.Dpi" + // XRRGetOutputInfo + // DisplayWidthMM, DisplayHeightMM + // All returning invalid values or 0 + } + + if (dpi_x) { + *dpi_x = x / 96.0f; + if(*dpi_x == 0) { + *dpi_x = 1.0f; + } + } + + if (dpi_y) { + *dpi_y = y / 96.0f; + if (*dpi_y == 0) { + *dpi_y = 1.0f; + } + } +} diff --git a/tests/ios/AppDelegate.m b/tests/ios/AppDelegate.m index 26e03cd..380a89b 100644 --- a/tests/ios/AppDelegate.m +++ b/tests/ios/AppDelegate.m @@ -91,7 +91,8 @@ resize(struct mfb_window *window, int width, int height) { kUnused(launchOptions); if(g_window == 0x0) { - g_scale = [UIScreen mainScreen].scale; + mfb_get_monitor_dpi(0x0, &g_scale, 0x0); + //g_scale = [UIScreen mainScreen].scale; g_width = [UIScreen mainScreen].bounds.size.width * g_scale; g_height = [UIScreen mainScreen].bounds.size.height * g_scale; g_window = mfb_open("noise", g_width, g_height);