diff --git a/source/backend/CarlaUtils.h b/source/backend/CarlaUtils.h index fdaa70e7f..5e2f69e60 100644 --- a/source/backend/CarlaUtils.h +++ b/source/backend/CarlaUtils.h @@ -304,6 +304,8 @@ CARLA_EXPORT void carla_set_process_name(const char* name); /* -------------------------------------------------------------------------------------------------------------------- * window control */ +CARLA_EXPORT double carla_get_desktop_scale_factor(); + CARLA_EXPORT int carla_cocoa_get_window(void* nsViewPtr); CARLA_EXPORT void carla_cocoa_set_transient_window_for(void* nsViewChild, void* nsViewParent); diff --git a/source/backend/utils/Windows.cpp b/source/backend/utils/Windows.cpp index bdf3c8bc3..05a72da1b 100644 --- a/source/backend/utils/Windows.cpp +++ b/source/backend/utils/Windows.cpp @@ -31,6 +31,22 @@ namespace CB = CarlaBackend; // ------------------------------------------------------------------------------------------------------------------- +double carla_get_desktop_scale_factor() +{ + // allow custom scale for testing + if (const char* const scale = getenv("DPF_SCALE_FACTOR")) + return std::max(1.0, std::atof(scale)); + // Qt env var for the same + if (const char* const scale = getenv("QT_SCALE_FACTOR")) + return std::max(1.0, std::atof(scale)); + +#if defined(CARLA_OS_MAC) && !defined(CARLA_PLUGIN_EXPORT) + return [NSScreen mainScreen].backingScaleFactor; +#endif + + return 1.0; +} + int carla_cocoa_get_window(void* nsViewPtr) { CARLA_SAFE_ASSERT_RETURN(nsViewPtr != nullptr, 0); diff --git a/source/frontend/carla_utils.py b/source/frontend/carla_utils.py index ad8a7c96f..116c71904 100644 --- a/source/frontend/carla_utils.py +++ b/source/frontend/carla_utils.py @@ -327,6 +327,9 @@ class CarlaUtils(): self.lib.carla_juce_cleanup.argtypes = None self.lib.carla_juce_cleanup.restype = None + self.lib.carla_get_desktop_scale_factor.argtypes = None + self.lib.carla_get_desktop_scale_factor.restype = c_double + self.lib.carla_cocoa_get_window.argtypes = [c_uintptr] self.lib.carla_cocoa_get_window.restype = c_int @@ -480,6 +483,9 @@ class CarlaUtils(): def juce_cleanup(self): self.lib.carla_juce_cleanup() + def get_desktop_scale_factor(self): + return float(self.lib.carla_get_desktop_scale_factor()) + def cocoa_get_window(self, winId): return self.lib.carla_cocoa_get_window(winId)