Browse Source

Add carla_get_desktop_scale_factor utility function

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.4.0
falkTX 3 years ago
parent
commit
7d57489180
3 changed files with 24 additions and 0 deletions
  1. +2
    -0
      source/backend/CarlaUtils.h
  2. +16
    -0
      source/backend/utils/Windows.cpp
  3. +6
    -0
      source/frontend/carla_utils.py

+ 2
- 0
source/backend/CarlaUtils.h View File

@@ -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);



+ 16
- 0
source/backend/utils/Windows.cpp View File

@@ -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);


+ 6
- 0
source/frontend/carla_utils.py View File

@@ -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)



Loading…
Cancel
Save