From 9abf74569467056045cfa62270416f8e2f0a0a0a Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 15 Aug 2021 13:28:49 +0100 Subject: [PATCH] Set scale factor for carla-bridge-*/carla-single standalone usage Signed-off-by: falkTX --- source/backend/CarlaStandalone.cpp | 17 ++++++++--------- source/backend/CarlaUtils.h | 7 +++++-- source/backend/utils/Information.cpp | 6 +++++- source/backend/utils/Windows.cpp | 6 ++++-- source/bridges-plugin/CarlaBridgePlugin.cpp | 12 ++++++++++++ 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/source/backend/CarlaStandalone.cpp b/source/backend/CarlaStandalone.cpp index 899374982..8be4c027a 100644 --- a/source/backend/CarlaStandalone.cpp +++ b/source/backend/CarlaStandalone.cpp @@ -43,18 +43,16 @@ // -------------------------------------------------------------------------------------------------------------------- -#ifdef USING_JUCE static void carla_standalone_juce_init(void); static void carla_standalone_juce_idle(void); static void carla_standalone_juce_cleanup(void); -# define carla_juce_init carla_standalone_juce_init -# define carla_juce_idle carla_standalone_juce_idle -# define carla_juce_cleanup carla_standalone_juce_cleanup -# include "utils/JUCE.cpp" -# undef carla_juce_init -# undef carla_juce_idle -# undef carla_juce_cleanup -#endif +#define carla_juce_init carla_standalone_juce_init +#define carla_juce_idle carla_standalone_juce_idle +#define carla_juce_cleanup carla_standalone_juce_cleanup +#include "utils/JUCE.cpp" +#undef carla_juce_init +#undef carla_juce_idle +#undef carla_juce_cleanup // ------------------------------------------------------------------------------------------------------------------- // Always return a valid string ptr for standalone functions @@ -2375,6 +2373,7 @@ const char* carla_get_host_osc_url_udp(CarlaHostHandle handle) # include "CarlaProcessUtils.cpp" # include "CarlaStateUtils.cpp" # include "utils/Information.cpp" +# include "utils/Windows.cpp" #endif /* CARLA_PLUGIN_EXPORT */ // -------------------------------------------------------------------------------------------------------------------- diff --git a/source/backend/CarlaUtils.h b/source/backend/CarlaUtils.h index 5e2f69e60..a9348e7d1 100644 --- a/source/backend/CarlaUtils.h +++ b/source/backend/CarlaUtils.h @@ -1,6 +1,6 @@ /* * Carla Plugin Host - * Copyright (C) 2011-2019 Filipe Coelho + * Copyright (C) 2011-2021 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -304,7 +304,10 @@ CARLA_EXPORT void carla_set_process_name(const char* name); /* -------------------------------------------------------------------------------------------------------------------- * window control */ -CARLA_EXPORT double carla_get_desktop_scale_factor(); +/*! + * Get the global/desktop scale factor. + */ +CARLA_EXPORT double carla_get_desktop_scale_factor(void); 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/Information.cpp b/source/backend/utils/Information.cpp index 83ca604de..ac398ceaf 100644 --- a/source/backend/utils/Information.cpp +++ b/source/backend/utils/Information.cpp @@ -1,6 +1,6 @@ /* * Carla Plugin Host - * Copyright (C) 2011-2020 Filipe Coelho + * Copyright (C) 2011-2021 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -45,6 +45,10 @@ # pragma GCC diagnostic pop #endif +#ifdef CARLA_OS_MAC +# import +#endif + #include "water/files/File.h" // ------------------------------------------------------------------------------------------------------------------- diff --git a/source/backend/utils/Windows.cpp b/source/backend/utils/Windows.cpp index 05a72da1b..ca0c8d8a7 100644 --- a/source/backend/utils/Windows.cpp +++ b/source/backend/utils/Windows.cpp @@ -1,6 +1,6 @@ /* * Carla Plugin Host - * Copyright (C) 2011-2019 Filipe Coelho + * Copyright (C) 2011-2021 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -40,13 +40,15 @@ double carla_get_desktop_scale_factor() 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) +#ifdef CARLA_OS_MAC 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/bridges-plugin/CarlaBridgePlugin.cpp b/source/bridges-plugin/CarlaBridgePlugin.cpp index 3d2e009df..a41398094 100644 --- a/source/bridges-plugin/CarlaBridgePlugin.cpp +++ b/source/bridges-plugin/CarlaBridgePlugin.cpp @@ -21,6 +21,7 @@ #include "CarlaEngine.hpp" #include "CarlaHost.h" +#include "CarlaUtils.h" #include "CarlaBackendUtils.hpp" #include "CarlaJuceUtils.hpp" @@ -657,6 +658,17 @@ int main(int argc, char* argv[]) return 1; } + if (! useBridge && ! testing) + { +#ifdef HAVE_X11 + if (std::getenv("DISPLAY") != nullptr) +#endif + carla_set_engine_option(gHostHandle, + CarlaBackend::ENGINE_OPTION_FRONTEND_UI_SCALE, + static_cast(carla_get_desktop_scale_factor()*1000+0.5), + nullptr); + } + // ----------------------------------------------------------------- // Init plugin