Browse Source

Correct external ui scale factor code

pull/320/head
falkTX 4 years ago
parent
commit
a61cb185b6
3 changed files with 39 additions and 18 deletions
  1. +0
    -2
      Makefile.plugins.mk
  2. +23
    -0
      distrho/DistrhoUI_macOS.mm
  3. +16
    -16
      distrho/src/DistrhoUI.cpp

+ 0
- 2
Makefile.plugins.mk View File

@@ -89,11 +89,9 @@ endif
OBJS_DSP = $(FILES_DSP:%=$(BUILD_DIR)/%.o)
OBJS_UI = $(FILES_UI:%=$(BUILD_DIR)/%.o)

ifneq ($(UI_TYPE),external)
ifeq ($(MACOS),true)
OBJS_UI += $(BUILD_DIR)/DistrhoUI_macOS_$(NAME).mm.o
endif
endif

# ---------------------------------------------------------------------------------------------------------------------
# Set plugin binary file targets


+ 23
- 0
distrho/DistrhoUI_macOS.mm View File

@@ -19,6 +19,28 @@
#endif

#include "src/DistrhoPluginChecks.h"
#include "src/DistrhoDefines.h"

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#import <Cocoa/Cocoa.h>
#include <algorithm>
#include <cmath>

START_NAMESPACE_DISTRHO
double getDesktopScaleFactor(const uintptr_t parentWindowHandle)
{
// allow custom scale for testing
if (const char* const scale = getenv("DPF_SCALE_FACTOR"))
return std::max(1.0, std::atof(scale));

if (NSView* const parentView = (NSView*)parentWindowHandle)
if (NSWindow* const parentWindow = [parentView window])
return [parentWindow screen].backingScaleFactor;

return [NSScreen mainScreen].backingScaleFactor;
}
END_NAMESPACE_DISTRHO
#else // DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#include "../dgl/Base.hpp"

#define DISTRHO_MACOS_NAMESPACE_MACRO_HELPER(DGL_NS, SEP, PUGL_NS, INTERFACE) DGL_NS ## SEP ## PUGL_NS ## SEP ## INTERFACE
@@ -33,3 +55,4 @@
#define PuglWrapperView DISTRHO_MACOS_NAMESPACE_MACRO(DGL_NAMESPACE, PUGL_NAMESPACE, WrapperView)

#import "src/pugl.mm"
#endif // DISTRHO_PLUGIN_HAS_EXTERNAL_UI

+ 16
- 16
distrho/src/DistrhoUI.cpp View File

@@ -17,17 +17,10 @@
#include "DistrhoUIPrivateData.hpp"
#include "src/WindowPrivateData.hpp"
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# if defined(DISTRHO_OS_HAIKU)
# elif defined(DISTRHO_OS_MAC)
# define Point CocoaPoint
# define Size CocoaSize
# import <Cocoa/Cocoa.h>
# undef Point
# undef Size
# elif defined(DISTRHO_OS_WINDOWS)
# if defined(DISTRHO_OS_WINDOWS)
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# else
# elif defined(HAVE_X11)
# include <X11/Xresource.h>
# endif
#else
@@ -47,15 +40,16 @@ const char* g_nextBundlePath = nullptr;
/* ------------------------------------------------------------------------------------------------------------
* get global scale factor */

static double getDesktopScaleFactor()
#ifdef DISTRHO_OS_MAC
double getDesktopScaleFactor(uintptr_t parentWindowHandle);
#else
static double getDesktopScaleFactor(const uintptr_t parentWindowHandle)
{
// allow custom scale for testing
if (const char* const scale = getenv("DPF_SCALE_FACTOR"))
return std::max(1.0, std::atof(scale));

#if defined(DISTRHO_OS_MAC)
return [NSScreen mainScreen].backingScaleFactor;
#elif defined(DISTRHO_OS_WINDOWS)
#if defined(DISTRHO_OS_WINDOWS)
if (const HMODULE Shcore = LoadLibraryA("Shcore.dll"))
{
typedef HRESULT(WINAPI* PFN_GetProcessDpiAwareness)(HANDLE, DWORD*);
@@ -70,8 +64,10 @@ static double getDesktopScaleFactor()
if (GetProcessDpiAwareness && GetScaleFactorForMonitor
&& GetProcessDpiAwareness(NULL, &dpiAware) == 0 && dpiAware != 0)
{
// TODO replace with something else
const HMONITOR hMon = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);
const HMONITOR hMon = parentWindowHandle != 0
? MonitorFromWindow((HWND)parentWindowHandle, MONITOR_DEFAULTTOPRIMARY)
/* TODO replace with something else for parent-less */
: MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);

DWORD scaleFactor = 0;
if (GetScaleFactorForMonitor(hMon, &scaleFactor) == 0 && scaleFactor != 0)
@@ -114,7 +110,11 @@ static double getDesktopScaleFactor()
#endif

return 1.0;

// might be unused
(void)parentWindowHandle;
}
#endif // !DISTRHO_OS_MAC

#endif

@@ -137,7 +137,7 @@ UI::PrivateData::createNextWindow(UI* const ui, const uint width, const uint hei
ewData.parentWindowHandle = pData->winId;
ewData.width = width;
ewData.height = height;
ewData.scaleFactor = pData->scaleFactor != 0.0 ? pData->scaleFactor : getDesktopScaleFactor();
ewData.scaleFactor = pData->scaleFactor != 0.0 ? pData->scaleFactor : getDesktopScaleFactor(pData->winId);
ewData.title = DISTRHO_PLUGIN_NAME;
ewData.isStandalone = DISTRHO_UI_IS_STANDALONE;
return ewData;


Loading…
Cancel
Save