From 9004d85ec54182a1768abafbcdcf56feeaf98a60 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 30 Sep 2022 20:57:53 -0400 Subject: [PATCH] app_server: Automatically pick a larger font size on HiDPI screens. Ideally DesktopSettings would take care of this. However, we cannot put this logic into its _SetDefaults, because that runs before we actually set (or confirm) a display mode, and so attempts to fetch the display mode in that function will fail. (FontManager initializes even earlier and thus also is an unsuitable place for this logic.) At present, it merely uses a 2x larger font size at resolutions >"4K" and a 1.5x larger font size at resolutions between 1080p and 4K. Further adjustments can be made as necessary later on. --- src/servers/app/Desktop.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/servers/app/Desktop.cpp b/src/servers/app/Desktop.cpp index e85814f222..c25a0d3f5b 100644 --- a/src/servers/app/Desktop.cpp +++ b/src/servers/app/Desktop.cpp @@ -50,6 +50,7 @@ #include "HWInterface.h" #include "InputManager.h" #include "Screen.h" +#include "ScreenManager.h" #include "ServerApp.h" #include "ServerConfig.h" #include "ServerCursor.h" @@ -524,6 +525,29 @@ Desktop::Init() return B_ERROR; } + // now that the mode is set, see if we should increase the default font size + if (fSettings->DefaultPlainFont() == *gFontManager->DefaultPlainFont()) { + float fontSize = fSettings->DefaultPlainFont().Size(); + gScreenManager->Lock(); + Screen* screen = gScreenManager->ScreenAt(0); + if (screen != NULL) { + display_mode mode; + screen->GetMode(mode); + + if (mode.virtual_width > 3840 && mode.virtual_height > 2160) + fontSize *= 2.0f; + else if (mode.virtual_width > 1920 && mode.virtual_height > 1080) + fontSize *= 1.5f; + } + gScreenManager->Unlock(); + + // modify settings without saving them + const_cast(fSettings->DefaultPlainFont()).SetSize(fontSize); + const_cast(fSettings->DefaultBoldFont()).SetSize(fontSize); + const_cast(fSettings->DefaultFixedFont()).SetSize(fontSize); + const_cast(fSettings->MenuInfo()).font_size = fontSize; + } + HWInterface()->SetDPMSMode(B_DPMS_ON); float brightness = fWorkspaces[0].StoredScreenConfiguration().Brightness(0);