common: minor tweaks

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-07-29 15:36:28 +08:00
parent 4fe67c9313
commit cf83b050d2
12 changed files with 74 additions and 41 deletions

View File

@ -93,7 +93,7 @@ FramelessConfig *FramelessConfig::instance()
void FramelessConfig::reload(const bool force) void FramelessConfig::reload(const bool force)
{ {
QMutexLocker locker(&g_data()->mutex); const QMutexLocker locker(&g_data()->mutex);
if (g_data()->loaded && !force) { if (g_data()->loaded && !force) {
return; return;
} }
@ -117,25 +117,25 @@ void FramelessConfig::reload(const bool force)
void FramelessConfig::set(const Option option, const bool on) void FramelessConfig::set(const Option option, const bool on)
{ {
QMutexLocker locker(&g_data()->mutex); const QMutexLocker locker(&g_data()->mutex);
g_data()->options[static_cast<int>(option)] = on; g_data()->options[static_cast<int>(option)] = on;
} }
bool FramelessConfig::isSet(const Option option) const bool FramelessConfig::isSet(const Option option) const
{ {
QMutexLocker locker(&g_data()->mutex); const QMutexLocker locker(&g_data()->mutex);
return g_data()->options[static_cast<int>(option)]; return g_data()->options[static_cast<int>(option)];
} }
void FramelessConfig::setLoadFromEnvironmentVariablesDisabled(const bool on) void FramelessConfig::setLoadFromEnvironmentVariablesDisabled(const bool on)
{ {
QMutexLocker locker(&g_data()->mutex); const QMutexLocker locker(&g_data()->mutex);
g_data()->disableEnvVar = on; g_data()->disableEnvVar = on;
} }
void FramelessConfig::setLoadFromConfigurationFileDisabled(const bool on) void FramelessConfig::setLoadFromConfigurationFileDisabled(const bool on)
{ {
QMutexLocker locker(&g_data()->mutex); const QMutexLocker locker(&g_data()->mutex);
g_data()->disableCfgFile = on; g_data()->disableCfgFile = on;
} }
@ -147,7 +147,7 @@ std::optional<QVariant> FramelessConfig::setInternal(const QString &key, const Q
return std::nullopt; return std::nullopt;
} }
std::optional<QVariant> previous = std::nullopt; std::optional<QVariant> previous = std::nullopt;
QMutexLocker locker(&g_data()->mutex); const QMutexLocker locker(&g_data()->mutex);
if (g_data()->internals.contains(key)) { if (g_data()->internals.contains(key)) {
previous = g_data()->internals.value(key); previous = g_data()->internals.value(key);
g_data()->internals.remove(key); g_data()->internals.remove(key);
@ -162,7 +162,7 @@ std::optional<QVariant> FramelessConfig::getInternal(const QString &key) const
if (key.isEmpty()) { if (key.isEmpty()) {
return std::nullopt; return std::nullopt;
} }
QMutexLocker locker(&g_data()->mutex); const QMutexLocker locker(&g_data()->mutex);
if (g_data()->internals.contains(key)) { if (g_data()->internals.contains(key)) {
return g_data()->internals.value(key); return g_data()->internals.value(key);
} }

View File

@ -166,7 +166,7 @@ bool FramelessHelperQt::eventFilter(QObject *object, QEvent *event)
} break; } break;
case QEvent::MouseButtonRelease: { case QEvent::MouseButtonRelease: {
if (button == Qt::LeftButton) { if (button == Qt::LeftButton) {
QMutexLocker locker(&g_qtHelper()->mutex); const QMutexLocker locker(&g_qtHelper()->mutex);
g_qtHelper()->data[windowId].leftButtonPressed = false; g_qtHelper()->data[windowId].leftButtonPressed = false;
} }
if (button == Qt::RightButton) { if (button == Qt::RightButton) {
@ -191,12 +191,12 @@ bool FramelessHelperQt::eventFilter(QObject *object, QEvent *event)
if (cs == Qt::ArrowCursor) { if (cs == Qt::ArrowCursor) {
if (data.cursorShapeChanged) { if (data.cursorShapeChanged) {
window->unsetCursor(); window->unsetCursor();
QMutexLocker locker(&g_qtHelper()->mutex); const QMutexLocker locker(&g_qtHelper()->mutex);
g_qtHelper()->data[windowId].cursorShapeChanged = false; g_qtHelper()->data[windowId].cursorShapeChanged = false;
} }
} else { } else {
window->setCursor(cs); window->setCursor(cs);
QMutexLocker locker(&g_qtHelper()->mutex); const QMutexLocker locker(&g_qtHelper()->mutex);
g_qtHelper()->data[windowId].cursorShapeChanged = true; g_qtHelper()->data[windowId].cursorShapeChanged = true;
} }
} }

View File

@ -257,7 +257,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper)
WARNING << Utils::getSystemErrorMessage(kTrackMouseEvent); WARNING << Utils::getSystemErrorMessage(kTrackMouseEvent);
break; break;
} }
QMutexLocker locker(&g_win32Helper()->mutex); const QMutexLocker locker(&g_win32Helper()->mutex);
g_win32Helper()->data[parentWindowId].trackingMouse = true; g_win32Helper()->data[parentWindowId].trackingMouse = true;
} }
} break; } break;
@ -265,7 +265,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper)
case WM_MOUSELEAVE: { case WM_MOUSELEAVE: {
// When the mouse leaves the drag rect, make sure to dismiss any hover. // When the mouse leaves the drag rect, make sure to dismiss any hover.
releaseButtons(std::nullopt); releaseButtons(std::nullopt);
QMutexLocker locker(&g_win32Helper()->mutex); const QMutexLocker locker(&g_win32Helper()->mutex);
g_win32Helper()->data[parentWindowId].trackingMouse = false; g_win32Helper()->data[parentWindowId].trackingMouse = false;
} break; } break;
// NB: *Shouldn't be forwarding these* when they're not over the caption // NB: *Shouldn't be forwarding these* when they're not over the caption
@ -346,7 +346,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper)
case WM_NCRBUTTONUP: case WM_NCRBUTTONUP:
return SendMessageW(parentWindowHandle, uMsg, wParam, lParam); return SendMessageW(parentWindowHandle, uMsg, wParam, lParam);
case WM_DESTROY: { case WM_DESTROY: {
QMutexLocker locker(&g_win32Helper()->mutex); const QMutexLocker locker(&g_win32Helper()->mutex);
g_win32Helper()->fallbackTitleBarToParentWindowMapping.remove(windowId); g_win32Helper()->fallbackTitleBarToParentWindowMapping.remove(windowId);
if (g_win32Helper()->fallbackTitleBarToParentWindowMapping.count() < 1) { if (g_win32Helper()->fallbackTitleBarToParentWindowMapping.count() < 1) {
// According to Microsoft Docs, window classes registered by DLLs will // According to Microsoft Docs, window classes registered by DLLs will
@ -473,7 +473,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper)
WARNING << "Failed to re-position the fallback title bar window."; WARNING << "Failed to re-position the fallback title bar window.";
return false; return false;
} }
QMutexLocker locker(&g_win32Helper()->mutex); const QMutexLocker locker(&g_win32Helper()->mutex);
g_win32Helper()->data[parentWindowId].fallbackTitleBarWindowId = fallbackTitleBarWindowId; g_win32Helper()->data[parentWindowId].fallbackTitleBarWindowId = fallbackTitleBarWindowId;
g_win32Helper()->fallbackTitleBarToParentWindowMapping.insert(fallbackTitleBarWindowId, parentWindowId); g_win32Helper()->fallbackTitleBarToParentWindowMapping.insert(fallbackTitleBarWindowId, parentWindowId);
return true; return true;

View File

@ -152,25 +152,25 @@ QFont FramelessManagerPrivate::getIconFont()
SystemTheme FramelessManagerPrivate::systemTheme() const SystemTheme FramelessManagerPrivate::systemTheme() const
{ {
QMutexLocker locker(&g_helper()->mutex); const QMutexLocker locker(&g_helper()->mutex);
return m_systemTheme; return m_systemTheme;
} }
QColor FramelessManagerPrivate::systemAccentColor() const QColor FramelessManagerPrivate::systemAccentColor() const
{ {
QMutexLocker locker(&g_helper()->mutex); const QMutexLocker locker(&g_helper()->mutex);
return m_accentColor; return m_accentColor;
} }
QString FramelessManagerPrivate::wallpaper() const QString FramelessManagerPrivate::wallpaper() const
{ {
QMutexLocker locker(&g_helper()->mutex); const QMutexLocker locker(&g_helper()->mutex);
return m_wallpaper; return m_wallpaper;
} }
WallpaperAspectStyle FramelessManagerPrivate::wallpaperAspectStyle() const WallpaperAspectStyle FramelessManagerPrivate::wallpaperAspectStyle() const
{ {
QMutexLocker locker(&g_helper()->mutex); const QMutexLocker locker(&g_helper()->mutex);
return m_wallpaperAspectStyle; return m_wallpaperAspectStyle;
} }
@ -227,7 +227,7 @@ void FramelessManagerPrivate::addWindow(const SystemParameters &params)
void FramelessManagerPrivate::notifySystemThemeHasChangedOrNot() void FramelessManagerPrivate::notifySystemThemeHasChangedOrNot()
{ {
QMutexLocker locker(&g_helper()->mutex); const QMutexLocker locker(&g_helper()->mutex);
const SystemTheme currentSystemTheme = Utils::getSystemTheme(); const SystemTheme currentSystemTheme = Utils::getSystemTheme();
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
const DwmColorizationArea currentColorizationArea = Utils::getDwmColorizationArea(); const DwmColorizationArea currentColorizationArea = Utils::getDwmColorizationArea();
@ -263,7 +263,7 @@ void FramelessManagerPrivate::notifySystemThemeHasChangedOrNot()
void FramelessManagerPrivate::notifyWallpaperHasChangedOrNot() void FramelessManagerPrivate::notifyWallpaperHasChangedOrNot()
{ {
QMutexLocker locker(&g_helper()->mutex); const QMutexLocker locker(&g_helper()->mutex);
const QString currentWallpaper = Utils::getWallpaperFilePath(); const QString currentWallpaper = Utils::getWallpaperFilePath();
const WallpaperAspectStyle currentWallpaperAspectStyle = Utils::getWallpaperAspectStyle(); const WallpaperAspectStyle currentWallpaperAspectStyle = Utils::getWallpaperAspectStyle();
bool notify = false; bool notify = false;
@ -284,7 +284,7 @@ void FramelessManagerPrivate::notifyWallpaperHasChangedOrNot()
void FramelessManagerPrivate::initialize() void FramelessManagerPrivate::initialize()
{ {
QMutexLocker locker(&g_helper()->mutex); const QMutexLocker locker(&g_helper()->mutex);
m_systemTheme = Utils::getSystemTheme(); m_systemTheme = Utils::getSystemTheme();
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
m_colorizationArea = Utils::getDwmColorizationArea(); m_colorizationArea = Utils::getDwmColorizationArea();

View File

@ -82,7 +82,7 @@ bool SysApiLoader::isAvailable(const QString &library, const QString &function)
if (library.isEmpty() || function.isEmpty()) { if (library.isEmpty() || function.isEmpty()) {
return false; return false;
} }
QMutexLocker locker(&m_mutex); const QMutexLocker locker(&m_mutex);
if (m_functionCache.contains(function)) { if (m_functionCache.contains(function)) {
return m_functionCache.value(function).has_value(); return m_functionCache.value(function).has_value();
} }
@ -103,7 +103,7 @@ QFunctionPointer SysApiLoader::get(const QString &function)
if (function.isEmpty()) { if (function.isEmpty()) {
return nullptr; return nullptr;
} }
QMutexLocker locker(&m_mutex); const QMutexLocker locker(&m_mutex);
if (m_functionCache.contains(function)) { if (m_functionCache.contains(function)) {
const std::optional<QFunctionPointer> symbol = m_functionCache.value(function); const std::optional<QFunctionPointer> symbol = m_functionCache.value(function);
if (symbol.has_value()) { if (symbol.has_value()) {

View File

@ -144,6 +144,8 @@ QString Utils::getSystemButtonIconCode(const SystemButtonType button)
return QChar(icon.segoe); return QChar(icon.segoe);
} }
#endif #endif
// We always use Micon on UNIX platforms because Microsoft doesn't allow distributing
// the Segoe icon font to other platforms than Windows.
return QChar(icon.micon); return QChar(icon.micon);
} }

View File

@ -406,7 +406,7 @@ Q_GLOBAL_STATIC(MacUtilsData, g_macUtilsData);
if (!windowId) { if (!windowId) {
return nil; return nil;
} }
QMutexLocker locker(&g_macUtilsData()->mutex); const QMutexLocker locker(&g_macUtilsData()->mutex);
if (!g_macUtilsData()->hash.contains(windowId)) { if (!g_macUtilsData()->hash.contains(windowId)) {
QWindow * const qwindow = Utils::findWindow(windowId); QWindow * const qwindow = Utils::findWindow(windowId);
Q_ASSERT(qwindow); Q_ASSERT(qwindow);

View File

@ -132,6 +132,7 @@ FRAMELESSHELPER_STRING_CONSTANT(AccentColor)
FRAMELESSHELPER_STRING_CONSTANT(GetScaleFactorForMonitor) FRAMELESSHELPER_STRING_CONSTANT(GetScaleFactorForMonitor)
FRAMELESSHELPER_STRING_CONSTANT(WallpaperStyle) FRAMELESSHELPER_STRING_CONSTANT(WallpaperStyle)
FRAMELESSHELPER_STRING_CONSTANT(TileWallpaper) FRAMELESSHELPER_STRING_CONSTANT(TileWallpaper)
FRAMELESSHELPER_STRING_CONSTANT(UnregisterClassW)
struct Win32UtilsHelperData struct Win32UtilsHelperData
{ {
@ -176,15 +177,15 @@ static const QHash<int, SYSTEM_METRIC> g_systemMetricsTable = {
{SM_CXPADDEDBORDER, { 4, 5, 5, 6, 6, 6, 7, 7, 8, 9, 10, 12, 14, 16, 18, 20}} {SM_CXPADDEDBORDER, { 4, 5, 5, 6, 6, 6, 7, 7, 8, 9, 10, 12, 14, 16, 18, 20}}
}; };
template <typename T> template<typename T>
class HumbleComPtr class HumbleComPtr
{ {
Q_DISABLE_COPY_MOVE(HumbleComPtr) Q_DISABLE_COPY_MOVE(HumbleComPtr)
public: public:
HumbleComPtr() = default; explicit HumbleComPtr() = default;
HumbleComPtr(std::nullptr_t ptr) explicit HumbleComPtr(std::nullptr_t ptr)
{ {
Q_UNUSED(ptr); Q_UNUSED(ptr);
} }
@ -231,6 +232,35 @@ private:
T *p = nullptr; T *p = nullptr;
}; };
struct WindowClassCleaner
{
explicit WindowClassCleaner(const std::wstring &name)
{
this->name = name;
}
~WindowClassCleaner()
{
if (name.empty()) {
return;
}
const HINSTANCE instance = GetModuleHandleW(nullptr);
if (!instance) {
WARNING << Utils::getSystemErrorMessage(kGetModuleHandleW);
return;
}
if (UnregisterClassW(name.c_str(), instance) == FALSE) {
WARNING << Utils::getSystemErrorMessage(kUnregisterClassW);
}
}
private:
Q_DISABLE_COPY_MOVE(WindowClassCleaner)
private:
std::wstring name = {};
};
[[nodiscard]] static inline QString hkcuRegistryKey() [[nodiscard]] static inline QString hkcuRegistryKey()
{ {
static const QString key = FRAMELESSHELPER_STRING_LITERAL("HKEY_CURRENT_USER"); static const QString key = FRAMELESSHELPER_STRING_LITERAL("HKEY_CURRENT_USER");
@ -274,6 +304,7 @@ private:
WARNING << Utils::getSystemErrorMessage(kRegisterClassExW); WARNING << Utils::getSystemErrorMessage(kRegisterClassExW);
return nullptr; return nullptr;
} }
static const auto cleaner = WindowClassCleaner(kDummyWindowClassName);
} }
const HWND window = CreateWindowExW(0, kDummyWindowClassName, nullptr, const HWND window = CreateWindowExW(0, kDummyWindowClassName, nullptr,
WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, nullptr, nullptr, instance, nullptr); WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, nullptr, nullptr, instance, nullptr);
@ -961,7 +992,7 @@ quint32 Utils::getPrimaryScreenDpi(const bool horizontal)
HRESULT(WINAPI *)(D2D1_FACTORY_TYPE, REFIID, CONST D2D1_FACTORY_OPTIONS *, void **); HRESULT(WINAPI *)(D2D1_FACTORY_TYPE, REFIID, CONST D2D1_FACTORY_OPTIONS *, void **);
const auto pD2D1CreateFactory = const auto pD2D1CreateFactory =
reinterpret_cast<D2D1CreateFactoryPtr>(SysApiLoader::instance()->get(kD2D1CreateFactory)); reinterpret_cast<D2D1CreateFactoryPtr>(SysApiLoader::instance()->get(kD2D1CreateFactory));
HumbleComPtr<ID2D1Factory> d2dFactory = nullptr; auto d2dFactory = HumbleComPtr<ID2D1Factory>(nullptr);
HRESULT hr = pD2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), HRESULT hr = pD2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory),
nullptr, reinterpret_cast<void **>(&d2dFactory)); nullptr, reinterpret_cast<void **>(&d2dFactory));
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
@ -1279,7 +1310,7 @@ void Utils::installSystemMenuHook(const WId windowId,
if (!windowId || !isWindowFixedSize) { if (!windowId || !isWindowFixedSize) {
return; return;
} }
QMutexLocker locker(&g_utilsHelper()->mutex); const QMutexLocker locker(&g_utilsHelper()->mutex);
if (g_utilsHelper()->data.contains(windowId)) { if (g_utilsHelper()->data.contains(windowId)) {
return; return;
} }
@ -1311,7 +1342,7 @@ void Utils::uninstallSystemMenuHook(const WId windowId)
if (!windowId) { if (!windowId) {
return; return;
} }
QMutexLocker locker(&g_utilsHelper()->mutex); const QMutexLocker locker(&g_utilsHelper()->mutex);
if (!g_utilsHelper()->data.contains(windowId)) { if (!g_utilsHelper()->data.contains(windowId)) {
return; return;
} }

View File

@ -129,7 +129,7 @@ void FramelessQuickHelperPrivate::setTitleBarItem(QQuickItem *value)
if (!value) { if (!value) {
return; return;
} }
QMutexLocker locker(&g_quickHelper()->mutex); const QMutexLocker locker(&g_quickHelper()->mutex);
QuickHelperData *data = getWindowDataMutable(); QuickHelperData *data = getWindowDataMutable();
if (!data) { if (!data) {
return; return;
@ -225,7 +225,7 @@ void FramelessQuickHelperPrivate::setSystemButton(QQuickItem *item, const QuickG
if (!item || (buttonType == QuickGlobal::SystemButtonType::Unknown)) { if (!item || (buttonType == QuickGlobal::SystemButtonType::Unknown)) {
return; return;
} }
QMutexLocker locker(&g_quickHelper()->mutex); const QMutexLocker locker(&g_quickHelper()->mutex);
QuickHelperData *data = getWindowDataMutable(); QuickHelperData *data = getWindowDataMutable();
if (!data) { if (!data) {
return; return;
@ -259,7 +259,7 @@ void FramelessQuickHelperPrivate::setHitTestVisible(QQuickItem *item, const bool
if (!item) { if (!item) {
return; return;
} }
QMutexLocker locker(&g_quickHelper()->mutex); const QMutexLocker locker(&g_quickHelper()->mutex);
QuickHelperData *data = getWindowDataMutable(); QuickHelperData *data = getWindowDataMutable();
if (!data) { if (!data) {
return; return;
@ -662,7 +662,7 @@ QuickHelperData FramelessQuickHelperPrivate::getWindowData() const
return {}; return {};
} }
const WId windowId = window->winId(); const WId windowId = window->winId();
QMutexLocker locker(&g_quickHelper()->mutex); const QMutexLocker locker(&g_quickHelper()->mutex);
if (!g_quickHelper()->data.contains(windowId)) { if (!g_quickHelper()->data.contains(windowId)) {
g_quickHelper()->data.insert(windowId, {}); g_quickHelper()->data.insert(windowId, {});
} }

View File

@ -114,7 +114,7 @@ void WallpaperImageNode::initialize()
void WallpaperImageNode::maybeGenerateWallpaperImageCache(const bool force) void WallpaperImageNode::maybeGenerateWallpaperImageCache(const bool force)
{ {
QMutexLocker locker(&g_data()->mutex); const QMutexLocker locker(&g_data()->mutex);
if (!m_pixmapCache.isNull() && !force) { if (!m_pixmapCache.isNull() && !force) {
return; return;
} }
@ -130,7 +130,7 @@ void WallpaperImageNode::maybeGenerateWallpaperImageCache(const bool force)
void WallpaperImageNode::maybeUpdateWallpaperImageClipRect() void WallpaperImageNode::maybeUpdateWallpaperImageClipRect()
{ {
QMutexLocker locker(&g_data()->mutex); const QMutexLocker locker(&g_data()->mutex);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
const QSizeF itemSize = m_item->size(); const QSizeF itemSize = m_item->size();
#else #else

View File

@ -236,7 +236,7 @@ void FramelessWidgetsHelperPrivate::setTitleBarWidget(QWidget *widget)
if (!widget) { if (!widget) {
return; return;
} }
QMutexLocker locker(&g_widgetsHelper()->mutex); const QMutexLocker locker(&g_widgetsHelper()->mutex);
WidgetsHelperData *data = getWindowDataMutable(); WidgetsHelperData *data = getWindowDataMutable();
if (!data) { if (!data) {
return; return;
@ -259,7 +259,7 @@ void FramelessWidgetsHelperPrivate::setHitTestVisible(QWidget *widget, const boo
if (!widget) { if (!widget) {
return; return;
} }
QMutexLocker locker(&g_widgetsHelper()->mutex); const QMutexLocker locker(&g_widgetsHelper()->mutex);
WidgetsHelperData *data = getWindowDataMutable(); WidgetsHelperData *data = getWindowDataMutable();
if (!data) { if (!data) {
return; return;
@ -378,7 +378,7 @@ WidgetsHelperData FramelessWidgetsHelperPrivate::getWindowData() const
return {}; return {};
} }
const WId windowId = window->winId(); const WId windowId = window->winId();
QMutexLocker locker(&g_widgetsHelper()->mutex); const QMutexLocker locker(&g_widgetsHelper()->mutex);
if (!g_widgetsHelper()->data.contains(windowId)) { if (!g_widgetsHelper()->data.contains(windowId)) {
g_widgetsHelper()->data.insert(windowId, {}); g_widgetsHelper()->data.insert(windowId, {});
} }
@ -672,7 +672,7 @@ void FramelessWidgetsHelperPrivate::setSystemButton(QWidget *widget, const Syste
if (!widget || (buttonType == SystemButtonType::Unknown)) { if (!widget || (buttonType == SystemButtonType::Unknown)) {
return; return;
} }
QMutexLocker locker(&g_widgetsHelper()->mutex); const QMutexLocker locker(&g_widgetsHelper()->mutex);
WidgetsHelperData *data = getWindowDataMutable(); WidgetsHelperData *data = getWindowDataMutable();
if (!data) { if (!data) {
return; return;

View File

@ -424,7 +424,7 @@ EXTERN_C int WINAPI wmain(int argc, wchar_t *argv[])
for (int i = 0; i != DPI_COUNT; ++i) { for (int i = 0; i != DPI_COUNT; ++i) {
const auto entry = DPI_TABLE[i]; const auto entry = DPI_TABLE[i];
const auto percent = int(std::round(entry.DevicePixelRatio * double(100))); const auto percent = int(std::round(entry.DevicePixelRatio * double(100)));
text += L" const int DPI_" + std::to_wstring(entry.DotsPerInch) + L" = 0;"; text += L" int DPI_" + std::to_wstring(entry.DotsPerInch) + L" = 0;";
text += L" // " + std::to_wstring(percent) + L"%. The scale factor for the device is " text += L" // " + std::to_wstring(percent) + L"%. The scale factor for the device is "
+ std::to_wstring(entry.DevicePixelRatio) + L"x.\n"; + std::to_wstring(entry.DevicePixelRatio) + L"x.\n";
if (i == (DPI_COUNT - 1)) { if (i == (DPI_COUNT - 1)) {