impr: Make fonts look less blurry with Wayland fractional scaling

This commit is contained in:
WerWolv
2026-02-06 22:12:40 +01:00
parent d39d107de4
commit f476842008
3 changed files with 17 additions and 3 deletions

View File

@@ -680,10 +680,20 @@ namespace hex {
if (!sessionType.has_value() || sessionType == "x11")
return 1.0F;
else {
float xScale = 0, yScale = 0;
glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &xScale, &yScale);
static float scaleFactor = -1;
if (scaleFactor <= 0) {
int windowW, windowH;
int displayW, displayH;
glfwGetWindowSize(getMainWindowHandle(), &windowW, &windowH);
glfwGetFramebufferSize(getMainWindowHandle(), &displayW, &displayH);
return std::midpoint(xScale, yScale);
float xScale = (windowW > 0) ? float(displayW) / windowW : 1.0f;
float yScale = (windowH > 0) ? float(displayH) / windowH : 1.0f;
scaleFactor = std::midpoint(xScale, yScale);
}
return scaleFactor;
}
#elif defined(OS_WEB)
return MAIN_THREAD_EM_ASM_INT({ return window.devicePixelRatio; });

View File

@@ -1301,6 +1301,7 @@ namespace hex {
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigWindowsMoveFromTitleBarOnly = true;
io.ConfigDragClickToInputText = true;
io.ConfigDpiScaleFonts = true;
if (glfwGetPrimaryMonitor() != nullptr) {
if (ImHexApi::System::isMultiWindowModeEnabled()) {

View File

@@ -24,6 +24,9 @@ namespace hex::fonts::loader {
ImFontConfig config;
config.MergeMode = false;
config.SizePixels = settings.getFontSize() / ImHexApi::System::getNativeScale();
config.OversampleH = 3;
config.OversampleV = 2;
config.RasterizerDensity = ImHexApi::System::getNativeScale();
config.Flags |= ImFontFlags_NoLoadError;
std::memcpy(config.Name, name.get().c_str(), std::min(name.get().size(), sizeof(config.Name) - 1));