From 3c233850bd1ff79e10060675bfd1090d673db5f5 Mon Sep 17 00:00:00 2001 From: xionglinlin Date: Tue, 18 Jun 2024 18:14:21 +0800 Subject: [PATCH] fix: incorrect scaling of greeter interface on first login Modify the algorithm for setting scaling Issue: https://github.com/linuxdeepin/developer-center/issues/8684 --- src/app/lightdm-deepin-greeter.cpp | 44 ++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/app/lightdm-deepin-greeter.cpp b/src/app/lightdm-deepin-greeter.cpp index 024ee5e7..e3f0aacc 100644 --- a/src/app/lightdm-deepin-greeter.cpp +++ b/src/app/lightdm-deepin-greeter.cpp @@ -106,6 +106,30 @@ static int set_rootwindow_cursor() { } // Load system cursor --end +// 参照后端算法,保持一致 +float toListedScaleFactor(float s) { + const float min = 1.0, max = 3.0, step = 0.25; + if (s <= min) { + return min; + } else if (s >= max) { + return max; + } + + for (float i = min; i <= max; i += step) { + if (i > s) { + float ii = i - step; + float d1 = s - ii; + float d2 = i - s; + if (d1 >= d2) { + return i; + } else { + return ii; + } + } + } + return max; +} + static double get_scale_ratio() { Display *display = XOpenDisplay(nullptr); double scaleRatio = 0.0; @@ -128,18 +152,14 @@ static double get_scale_ratio() { XRRCrtcInfo *crtInfo = XRRGetCrtcInfo(display, resources, outputInfo->crtc); if (crtInfo == nullptr) continue; - - scaleRatio = static_cast(crtInfo->width) / static_cast(outputInfo->mm_width) / (1366.0 / 310.0); - - if (scaleRatio > 1 + 2.0 / 3.0) { - scaleRatio = 2; - } - else if (scaleRatio > 1 + 1.0 / 3.0) { - scaleRatio = 1.5; - } - else { - scaleRatio = 1; - } + // 参照后端的算法,与后端保持一致 + float lenPx = hypot(static_cast(crtInfo->width), static_cast(crtInfo->height)); + float lenMm = hypot(static_cast(outputInfo->mm_width), static_cast(outputInfo->mm_height)); + float lenPxStd = hypot(1920, 1080); + float lenMmStd = hypot(477, 268); + float fix = (lenMm - lenMmStd) * (lenPx / lenPxStd) * 0.00158; + float scale = (lenPx / lenMm) / (lenPxStd / lenMmStd) + fix; + scaleRatio = toListedScaleFactor(scale); } } else {