From 17c375002f5db121a765bfefba91bafd5a49a347 Mon Sep 17 00:00:00 2001 From: Carlos Aragones <> Date: Mon, 21 Sep 2020 13:02:47 +0200 Subject: [PATCH] working on MacOS --- src/macosx/MacMiniFB.m | 31 +++++++++++++++++++++++++++++++ src/windows/WinMiniFB.c | 12 ++++++------ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/macosx/MacMiniFB.m b/src/macosx/MacMiniFB.m index 959cd1c..059c00f 100644 --- a/src/macosx/MacMiniFB.m +++ b/src/macosx/MacMiniFB.m @@ -551,3 +551,34 @@ 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) { + float scale = 1.0f; + + if(window != 0x0) { + SWindowData *window_data = (SWindowData *) window; + SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific; + + scale = [window_data_osx->window backingScaleFactor]; + } + else { + scale = [[NSScreen mainScreen] backingScaleFactor]; + } + + 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/windows/WinMiniFB.c b/src/windows/WinMiniFB.c index adc2802..87fe99a 100644 --- a/src/windows/WinMiniFB.c +++ b/src/windows/WinMiniFB.c @@ -85,28 +85,28 @@ dpi_aware() { //-- void get_monitor_dpi(HWND hWnd, float *dpi_x, float *dpi_y) { - UINT xdpi, ydpi; + UINT x, y; if(mfb_GetDpiForMonitor != 0x0) { HMONITOR monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); - mfb_GetDpiForMonitor(monitor, mfb_MDT_EFFECTIVE_DPI, &xdpi, &ydpi); + mfb_GetDpiForMonitor(monitor, mfb_MDT_EFFECTIVE_DPI, &x, &y); } else { const HDC dc = GetDC(hWnd); - xdpi = GetDeviceCaps(dc, LOGPIXELSX); - ydpi = GetDeviceCaps(dc, LOGPIXELSY); + x = GetDeviceCaps(dc, LOGPIXELSX); + y = GetDeviceCaps(dc, LOGPIXELSY); ReleaseDC(NULL, dc); } if (dpi_x) { - *dpi_x = xdpi / (float) USER_DEFAULT_SCREEN_DPI; + *dpi_x = x / (float) USER_DEFAULT_SCREEN_DPI; if(*dpi_x == 0) { *dpi_x = 1; } } if (dpi_y) { - *dpi_y = ydpi / (float) USER_DEFAULT_SCREEN_DPI; + *dpi_y = y / (float) USER_DEFAULT_SCREEN_DPI; if (*dpi_y == 0) { *dpi_y = 1; }