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.
This commit is contained in:
Augustin Cavalier 2022-09-30 20:57:53 -04:00
parent 0716e5094e
commit 9004d85ec5

View File

@ -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<ServerFont&>(fSettings->DefaultPlainFont()).SetSize(fontSize);
const_cast<ServerFont&>(fSettings->DefaultBoldFont()).SetSize(fontSize);
const_cast<ServerFont&>(fSettings->DefaultFixedFont()).SetSize(fontSize);
const_cast<menu_info&>(fSettings->MenuInfo()).font_size = fontSize;
}
HWInterface()->SetDPMSMode(B_DPMS_ON);
float brightness = fWorkspaces[0].StoredScreenConfiguration().Brightness(0);