Skip to content

Conversation

timothyqiu
Copy link
Member

The problem: I have my system display scale factor set to 175%. But the Godot editor fails to detect it, the UI is very small and the editor setting says Auto (100%).

The editor is currently using a strange way to determine the default scale:

// Use the smallest dimension to use a correct display scale on portrait displays.
const int smallest_dimension = MIN(DisplayServer::get_singleton()->screen_get_size(screen).x, DisplayServer::get_singleton()->screen_get_size(screen).y);
if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && smallest_dimension >= 1400) {
// hiDPI display.
return 2.0;
} else if (smallest_dimension >= 1700) {
// Likely a hiDPI display, but we aren't certain due to the returned DPI.
// Use an intermediate scale to handle this situation.
return 1.5;
} else if (smallest_dimension <= 800) {
// Small loDPI display. Use a smaller display scale so that editor elements fit more easily.
// Icons won't look great, but this is better than having editor elements overflow from its window.
return 0.75;
}
return 1.0;

My screen resolution is 2560x1600 and the DPI reported is 168. So the scale is indeed 100% according to this algorithm.

According to MSDN, the DPI reported by GetDpiForMonitor(type=MDT_DEFAULT) shows the correct factor for scaling UI elements (with 96 as 100%). I believe the default scale can be as easy as dividing screen_get_dpi() with 96.

In this PR, I also:

  • optimized screen_get_dpi() to avoid enumerating the monitors twice
  • changed the error return value of screen_get_dpi() from 72 to 96 as it means 100% scale on Windows
  • removed an unnecessary optional parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants