代码拉取完成,页面将自动刷新
From 3d55d3e81a2de1b91994473695b2bffa27c47b1b Mon Sep 17 00:00:00 2001
From: liuxinhao <liuxinhao@kylinsec.com.cn>
Date: Tue, 6 Feb 2024 13:45:31 +0800
Subject: [PATCH 15/16] fix(cursor): incorrect scaling cursor size
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 错误的缩放光标大小
---
lib/utils/scaling-helper.cpp | 10 +++++-----
lib/utils/scaling-helper.h | 6 +++---
src/lightdm-greeter/main.cpp | 22 +++++++++++++---------
3 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/lib/utils/scaling-helper.cpp b/lib/utils/scaling-helper.cpp
index 697744e..fcfd608 100644
--- a/lib/utils/scaling-helper.cpp
+++ b/lib/utils/scaling-helper.cpp
@@ -23,12 +23,12 @@ namespace Kiran
{
namespace SessionGuard
{
-void ScalingHelper::set_scale_factor(double factor)
+void ScalingHelper::set_scale_factor(qreal factor)
{
qputenv("QT_SCALE_FACTOR", QString::number(factor).toUtf8());
}
-void ScalingHelper::auto_calculate_screen_scaling()
+qreal ScalingHelper::auto_calculate_screen_scaling()
{
Display *display = nullptr;
XRRScreenResources *resources = nullptr;
@@ -40,7 +40,7 @@ void ScalingHelper::auto_calculate_screen_scaling()
{
KLOG_WARNING("auto_calculate_screen_scaling failed,set QT_AUTO_SCREEN_SCALE_FACTOR=1");
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
- return;
+ return scale_factor;
}
resources = XRRGetScreenResourcesCurrent(display, DefaultRootWindow(display));
@@ -59,7 +59,7 @@ void ScalingHelper::auto_calculate_screen_scaling()
}
KLOG_WARNING("auto_calculate_screen_scaling failed,set QT_AUTO_SCREEN_SCALE_FACTOR=1");
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
- return;
+ return scale_factor;
}
for (int i = 0; i < resources->noutput; i++)
@@ -132,7 +132,7 @@ void ScalingHelper::auto_calculate_screen_scaling()
KLOG_WARNING() << "set scale factor failed.";
}
- return;
+ return scale_factor;
}
} // namespace SessionGuard
diff --git a/lib/utils/scaling-helper.h b/lib/utils/scaling-helper.h
index 669fef1..1a3eb9b 100644
--- a/lib/utils/scaling-helper.h
+++ b/lib/utils/scaling-helper.h
@@ -13,15 +13,15 @@
*/
#pragma once
-
+#include <QtMath>
namespace Kiran
{
namespace SessionGuard
{
namespace ScalingHelper
{
-void auto_calculate_screen_scaling();
-void set_scale_factor(double factor);
+qreal auto_calculate_screen_scaling();
+void set_scale_factor(qreal factor);
} // namespace ScalingHelper
} // namespace SessionGuard
diff --git a/src/lightdm-greeter/main.cpp b/src/lightdm-greeter/main.cpp
index 61255ec..254911a 100644
--- a/src/lightdm-greeter/main.cpp
+++ b/src/lightdm-greeter/main.cpp
@@ -31,20 +31,22 @@ using namespace ::Kiran::SessionGuard;
using namespace ::Kiran::SessionGuard::Greeter;
// 根据配置项,调整缩放率
-void adjustScaleFactor(Prefs* prefs)
+qreal adjustScaleFactor(Prefs* prefs)
{
+ qreal factor = 1.0;
+
/// 设置缩放比
switch (prefs->scale_mode())
{
case GREETER_SCALING_MODE_AUTO:
{
- ScalingHelper::auto_calculate_screen_scaling();
+ factor = ScalingHelper::auto_calculate_screen_scaling();
break;
}
case GREETER_SCALING_MODE_MANUAL:
{
- double scaleFcator = prefs->scale_factor();
- ScalingHelper::set_scale_factor(scaleFcator);
+ factor = prefs->scale_factor();
+ ScalingHelper::set_scale_factor(factor);
break;
}
case GREETER_SCALING_MODE_DISABLE:
@@ -53,6 +55,8 @@ void adjustScaleFactor(Prefs* prefs)
KLOG_ERROR("enable-scaling: unsupported options %d", prefs->scale_mode());
break;
}
+
+ return factor;
}
// 加载样式表
@@ -91,12 +95,12 @@ bool loadTranslator()
}
// 设置当前光标缩放,以及Root窗口光标避免开始会话到进入会话之中的空窗期光标错误显示
-void setCursor(Prefs* prefs)
+void setCursor(qreal factor)
{
// 光标放大
- if (!CursorHelper::setDefaultCursorSize(prefs->scale_factor()))
+ if (!CursorHelper::setDefaultCursorSize(factor))
{
- KLOG_ERROR("set default cursor size for factor %d failed!", prefs->scale_factor());
+ KLOG_ERROR("set default cursor size for factor %f failed!", factor);
}
// 登录成功和进入桌面的间隔会显示根窗口,为了避免显示根窗口时光标显示为"X",需设置ROOT窗口光标
@@ -121,12 +125,12 @@ int main(int argc, char* argv[])
Prefs::globalInit();
auto prefs = Prefs::getInstance();
- adjustScaleFactor(prefs);
+ qreal factor = adjustScaleFactor(prefs);
QApplication app(argc, argv);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
- setCursor(prefs);
+ setCursor(factor);
loadTranslator();
loadStyleSheet();
--
2.27.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。