1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Fix editor auto scale on Windows

This commit is contained in:
Haoyu Qiu
2025-10-06 22:48:31 +08:00
parent 0fdb93cde6
commit 9f7ebaea5c
2 changed files with 18 additions and 11 deletions

View File

@@ -1823,6 +1823,9 @@ float EditorSettings::get_auto_display_scale() {
return 1.0;
}
#if defined(WINDOWS_ENABLED)
return DisplayServer::get_singleton()->screen_get_dpi(screen) / 96.0;
#else
// 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) {
@@ -1838,7 +1841,9 @@ float EditorSettings::get_auto_display_scale() {
return 0.75;
}
return 1.0;
#endif
#endif // defined(WINDOWS_ENABLED)
#endif // defined(MACOS_ENABLED) || defined(ANDROID_ENABLED)
}
// Shortcuts

View File

@@ -1331,17 +1331,17 @@ Rect2i DisplayServerWindows::screen_get_usable_rect(int p_screen) const {
}
typedef struct {
int count;
int current_index;
int screen;
int dpi;
} EnumDpiData;
static int QueryDpiForMonitor(HMONITOR hmon, MONITOR_DPI_TYPE dpiType = MDT_DEFAULT) {
static int QueryDpiForMonitor(HMONITOR hmon) {
int dpiX = 96, dpiY = 96;
UINT x = 0, y = 0;
if (hmon) {
HRESULT hr = GetDpiForMonitor(hmon, dpiType, &x, &y);
HRESULT hr = GetDpiForMonitor(hmon, MDT_DEFAULT, &x, &y);
if (SUCCEEDED(hr) && (x > 0) && (y > 0)) {
dpiX = (int)x;
dpiY = (int)y;
@@ -1367,11 +1367,13 @@ static int QueryDpiForMonitor(HMONITOR hmon, MONITOR_DPI_TYPE dpiType = MDT_DEFA
static BOOL CALLBACK _MonitorEnumProcDpi(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
EnumDpiData *data = (EnumDpiData *)dwData;
if (data->count == data->screen) {
data->dpi = QueryDpiForMonitor(hMonitor);
}
data->count++;
data->current_index++;
if (data->current_index == data->screen) {
data->dpi = QueryDpiForMonitor(hMonitor);
return FALSE;
}
return TRUE;
}
@@ -1379,11 +1381,11 @@ int DisplayServerWindows::screen_get_dpi(int p_screen) const {
_THREAD_SAFE_METHOD_
p_screen = _get_screen_index(p_screen);
int screen_count = get_screen_count();
ERR_FAIL_INDEX_V(p_screen, screen_count, 72);
EnumDpiData data = { 0, p_screen, 72 };
EnumDpiData data = { -1, p_screen, 96 };
EnumDisplayMonitors(nullptr, nullptr, _MonitorEnumProcDpi, (LPARAM)&data);
ERR_FAIL_COND_V_MSG(data.current_index < p_screen, 96, vformat("Screen index %d out of range [0, %d].", p_screen, data.current_index));
return data.dpi;
}