From 7d37647897652f3a8ed2036eb25d17986c99833d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 27 Jan 2020 19:06:41 +0100 Subject: [PATCH] Platform: print the "HiDPI not enabled" warning at most once on macOS. If the application is constructed with delayed window creation, the warning would be printed on each context creation attempt / call to dpiScaling(const Configuration&), which is silly. --- src/Magnum/Platform/GlfwApplication.cpp | 11 ++++++++--- src/Magnum/Platform/GlfwApplication.h | 4 ++-- src/Magnum/Platform/Sdl2Application.cpp | 13 +++++++++---- src/Magnum/Platform/Sdl2Application.h | 4 ++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 05f043e7a..10c24bbd2 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -54,7 +54,10 @@ static_assert(GLFW_TRUE == true && GLFW_FALSE == false, "GLFW does not have sane enum class GlfwApplication::Flag: UnsignedByte { Redraw = 1 << 0, - TextInputActive = 1 << 1 + TextInputActive = 1 << 1, + #ifdef CORRADE_TARGET_APPLE + HiDpiWarningPrinted = 1 << 2 + #endif }; GlfwApplication::GlfwApplication(const Arguments& arguments): GlfwApplication{arguments, Configuration{}} {} @@ -127,14 +130,16 @@ void GlfwApplication::create(const Configuration& configuration, const GLConfigu } #endif -Vector2 GlfwApplication::dpiScaling(const Configuration& configuration) const { +Vector2 GlfwApplication::dpiScaling(const Configuration& configuration) { std::ostream* verbose = _verboseLog ? Debug::output() : nullptr; /* Print a helpful warning in case some extra steps are needed for HiDPI support */ #ifdef CORRADE_TARGET_APPLE - if(!Implementation::isAppleBundleHiDpiEnabled()) + if(!Implementation::isAppleBundleHiDpiEnabled() && !(_flags & Flag::HiDpiWarningPrinted)) { Warning{} << "Platform::GlfwApplication: warning: the executable is not a HiDPI-enabled app bundle"; + _flags |= Flag::HiDpiWarningPrinted; + } #elif defined(CORRADE_TARGET_WINDOWS) /** @todo */ #endif diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index 935d1372d..2bf238a4c 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -428,7 +428,7 @@ class GlfwApplication { * * How the content should be scaled relative to system defaults for * given @ref windowSize(). If a window is not created yet, returns - * zero vector, use @ref dpiScaling(const Configuration&) const for + * zero vector, use @ref dpiScaling(const Configuration&) for * calculating a value independently. See @ref Platform-GlfwApplication-dpi * for more information. * @see @ref framebufferSize() @@ -443,7 +443,7 @@ class GlfwApplication { * and custom scaling specified on the command-line. See * @ref Platform-GlfwApplication-dpi for more information. */ - Vector2 dpiScaling(const Configuration& configuration) const; + Vector2 dpiScaling(const Configuration& configuration); /** * @brief Set window title diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index fd3cd2a28..af640b56b 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -87,7 +87,10 @@ enum class Sdl2Application::Flag: UnsignedByte { Exit = 1 << 4, #ifdef CORRADE_TARGET_EMSCRIPTEN TextInputActive = 1 << 5, - Resizable = 1 << 6 + Resizable = 1 << 6, + #endif + #ifdef CORRADE_TARGET_APPLE + HiDpiWarningPrinted = 1 << 7 #endif }; @@ -180,16 +183,18 @@ void Sdl2Application::create(const Configuration& configuration, const GLConfigu } #endif -Vector2 Sdl2Application::dpiScaling(const Configuration& configuration) const { +Vector2 Sdl2Application::dpiScaling(const Configuration& configuration) { std::ostream* verbose = _verboseLog ? Debug::output() : nullptr; /* Print a helpful warning in case some extra steps are needed for HiDPI support */ #ifdef CORRADE_TARGET_APPLE - if(!Implementation::isAppleBundleHiDpiEnabled()) + if(!Implementation::isAppleBundleHiDpiEnabled() && !(_flags & Flag::HiDpiWarningPrinted)) { Warning{} << "Platform::Sdl2Application: warning: the executable is not a HiDPI-enabled app bundle"; + _flags |= Flag::HiDpiWarningPrinted; + } #elif defined(CORRADE_TARGET_WINDOWS) - /** @todo */ + /* Handled below, warning printed only when using virtual DPI scaling */ #endif /* Use values from the configuration only if not overriden on command line. diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index 52b8fbd75..7e4f35a89 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -730,7 +730,7 @@ class Sdl2Application { * * How the content should be scaled relative to system defaults for * given @ref windowSize(). If a window is not created yet, returns - * zero vector, use @ref dpiScaling(const Configuration&) const for + * zero vector, use @ref dpiScaling(const Configuration&) for * calculating a value independently. See @ref Platform-Sdl2Application-dpi * for more information. * @see @ref framebufferSize() @@ -745,7 +745,7 @@ class Sdl2Application { * and custom scaling specified on the command-line. See * @ref Platform-Sdl2Application-dpi for more information. */ - Vector2 dpiScaling(const Configuration& configuration) const; + Vector2 dpiScaling(const Configuration& configuration); /** * @brief Set window title