Browse Source

Implement fetching desktop scale factor on macOS; Tweak d_info size

pull/309/head
falkTX 4 years ago
parent
commit
9b9e0a3618
4 changed files with 36 additions and 9 deletions
  1. +6
    -5
      dgl/src/WindowPrivateData.cpp
  2. +21
    -2
      dgl/src/pugl.cpp
  3. +4
    -0
      dgl/src/pugl.hpp
  4. +5
    -2
      examples/Info/InfoExampleUI.cpp

+ 6
- 5
dgl/src/WindowPrivateData.cpp View File

@@ -64,12 +64,13 @@ START_NAMESPACE_DGL
static const char* const kWin32SelectedFileCancelled = "__dpf_cancelled__";
#endif

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

return 1.0;
return puglGetDesktopScaleFactor(view);
}

// -----------------------------------------------------------------------
@@ -84,7 +85,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s)
isClosed(true),
isVisible(false),
isEmbed(false),
scaleFactor(getDesktopScaleFactor()),
scaleFactor(getDesktopScaleFactor(view)),
autoScaling(false),
autoScaleFactor(1.0),
minWidth(0),
@@ -137,7 +138,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s,
isClosed(parentWindowHandle == 0),
isVisible(parentWindowHandle != 0),
isEmbed(parentWindowHandle != 0),
scaleFactor(scale != 0.0 ? scale : getDesktopScaleFactor()),
scaleFactor(scale != 0.0 ? scale : getDesktopScaleFactor(view)),
autoScaling(false),
autoScaleFactor(1.0),
minWidth(0),
@@ -167,7 +168,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s,
isClosed(parentWindowHandle == 0),
isVisible(parentWindowHandle != 0),
isEmbed(parentWindowHandle != 0),
scaleFactor(scale != 0.0 ? scale : getDesktopScaleFactor()),
scaleFactor(scale != 0.0 ? scale : getDesktopScaleFactor(view)),
autoScaling(false),
autoScaleFactor(1.0),
minWidth(0),


+ 21
- 2
dgl/src/pugl.cpp View File

@@ -197,13 +197,32 @@ const char* puglGetWindowTitle(const PuglView* const view)
return view->title;
}

// --------------------------------------------------------------------------------------------------------------------
// get global scale factor

double puglGetDesktopScaleFactor(const PuglView* const view)
{
#if defined(DISTRHO_OS_MAC)
return (view->impl->window ? [view->impl->window screen]
: [NSScreen mainScreen]).backingScaleFactor;
#else
return 1.0;

// unused
(void)view;
#endif
}

// --------------------------------------------------------------------------------------------------------------------
// bring view window into the foreground, aka "raise" window

void puglRaiseWindow(PuglView* view)
void puglRaiseWindow(PuglView* const view)
{
#if defined(DISTRHO_OS_HAIKU) || defined(DISTRHO_OS_MAC)
#if defined(DISTRHO_OS_HAIKU)
// nothing here yet
#elif defined(DISTRHO_OS_MAC)
if (view->impl->window)
[view->impl->window orderFrontRegardless];
#elif defined(DISTRHO_OS_WINDOWS)
SetForegroundWindow(view->impl->hwnd);
SetActiveWindow(view->impl->hwnd);


+ 4
- 0
dgl/src/pugl.hpp View File

@@ -67,6 +67,10 @@ puglGetTransientParent(const PuglView* view);
PUGL_API const char*
puglGetWindowTitle(const PuglView* view);

// get global scale factor
PUGL_API double
puglGetDesktopScaleFactor(const PuglView* view);

// bring view window into the foreground, aka "raise" window
PUGL_API void
puglRaiseWindow(PuglView* view);


+ 5
- 2
examples/Info/InfoExampleUI.cpp View File

@@ -34,7 +34,7 @@ public:
: UI(kInitialWidth, kInitialHeight),
fSampleRate(getSampleRate()),
fResizable(isResizable()),
fScale(1.0f),
fScale(getScaleFactor()),
fResizeHandle(this)
{
std::memset(fParameters, 0, sizeof(float)*kParameterCount);
@@ -46,7 +46,10 @@ public:
loadSharedResources();
#endif

setGeometryConstraints(kInitialWidth, kInitialHeight, true);
if (d_isNotEqual(fScale, 1.0f))
setSize(kInitialWidth * fScale, kInitialHeight * fScale);

setGeometryConstraints(kInitialWidth * fScale, kInitialHeight * fScale, true);

// no need to show resize handle if window is user-resizable
if (fResizable)


Loading…
Cancel
Save