Skip to content

Commit 3c23385

Browse files
xionglinlindeepin-bot[bot]
authored andcommitted
fix: incorrect scaling of greeter interface on first login
Modify the algorithm for setting scaling Issue: linuxdeepin/developer-center#8684
1 parent 3cc6359 commit 3c23385

1 file changed

Lines changed: 32 additions & 12 deletions

File tree

src/app/lightdm-deepin-greeter.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@ static int set_rootwindow_cursor() {
106106
}
107107
// Load system cursor --end
108108

109+
// 参照后端算法,保持一致
110+
float toListedScaleFactor(float s) {
111+
const float min = 1.0, max = 3.0, step = 0.25;
112+
if (s <= min) {
113+
return min;
114+
} else if (s >= max) {
115+
return max;
116+
}
117+
118+
for (float i = min; i <= max; i += step) {
119+
if (i > s) {
120+
float ii = i - step;
121+
float d1 = s - ii;
122+
float d2 = i - s;
123+
if (d1 >= d2) {
124+
return i;
125+
} else {
126+
return ii;
127+
}
128+
}
129+
}
130+
return max;
131+
}
132+
109133
static double get_scale_ratio() {
110134
Display *display = XOpenDisplay(nullptr);
111135
double scaleRatio = 0.0;
@@ -128,18 +152,14 @@ static double get_scale_ratio() {
128152

129153
XRRCrtcInfo *crtInfo = XRRGetCrtcInfo(display, resources, outputInfo->crtc);
130154
if (crtInfo == nullptr) continue;
131-
132-
scaleRatio = static_cast<double>(crtInfo->width) / static_cast<double>(outputInfo->mm_width) / (1366.0 / 310.0);
133-
134-
if (scaleRatio > 1 + 2.0 / 3.0) {
135-
scaleRatio = 2;
136-
}
137-
else if (scaleRatio > 1 + 1.0 / 3.0) {
138-
scaleRatio = 1.5;
139-
}
140-
else {
141-
scaleRatio = 1;
142-
}
155+
// 参照后端的算法,与后端保持一致
156+
float lenPx = hypot(static_cast<double>(crtInfo->width), static_cast<double>(crtInfo->height));
157+
float lenMm = hypot(static_cast<double>(outputInfo->mm_width), static_cast<double>(outputInfo->mm_height));
158+
float lenPxStd = hypot(1920, 1080);
159+
float lenMmStd = hypot(477, 268);
160+
float fix = (lenMm - lenMmStd) * (lenPx / lenPxStd) * 0.00158;
161+
float scale = (lenPx / lenMm) / (lenPxStd / lenMmStd) + fix;
162+
scaleRatio = toListedScaleFactor(scale);
143163
}
144164
}
145165
else {

0 commit comments

Comments
 (0)