Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions editor/settings/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,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) {
Expand All @@ -1845,6 +1848,8 @@ float EditorSettings::get_auto_display_scale() {
}
return 1.0;
#endif

#endif
}

// Shortcuts
Expand Down
20 changes: 11 additions & 9 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,17 +1330,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;
Expand All @@ -1366,23 +1366,25 @@ 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->current_index++;

if (data->current_index == data->screen) {
data->dpi = QueryDpiForMonitor(hMonitor);
return FALSE;
}

data->count++;
return TRUE;
}

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;
}

Expand Down