-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement DisplayServer.screen_get_scale()
on Windows, Linux (X11) and Android
#2661
Comments
Implementing this for Windows should be as simple as this: diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index ca2b68371c..57ba0ef0b2 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -445,6 +445,14 @@ int DisplayServerWindows::screen_get_dpi(int p_screen) const {
return data.dpi;
}
+float DisplayServerWindows::screen_get_scale(int p_screen) const {
+ _THREAD_SAFE_METHOD_
+
+ EnumDpiData data = { 0, p_screen == SCREEN_OF_MAIN_WINDOW ? window_get_current_screen() : p_screen, 96 };
+ EnumDisplayMonitors(nullptr, nullptr, _MonitorEnumProcDpi, (LPARAM)&data);
+ return data.dpi / 96.f;
+}
+
bool DisplayServerWindows::screen_is_touchscreen(int p_screen) const {
#ifndef _MSC_VER
#warning touchscreen not working
... but let me think this over. |
Does this return the actual scale factor, or just the screen DPI divided by 96? The user can customize the scale factor independently of the monitor DPI. For instance, I have a 14" 4K laptop which defaults to 300% scaling, but I reduced it to 200% to get the same real estate as if it was a 1080p display. |
When it comes to Windows, the monitor scale factor sets the logical screen DPI. The base DPI at 100% is 96, for the rest it's just multiplied (125% -> 120, 150% -> 144, 200% -> 192, etc.). The callback For (Trivia: Even when using the advanced "custom scaling" setting, or when setting the scaling on a version before Windows 8.1, the DPI is calculated and stored as an integer. This has the caveat that some scale factors cannot be stored exactly. For example, if you set the scaling to 110%, the DPI is rounded to 106 and effectively you have a scaling of 1.1041666... times.) |
Taking a look over the Windows API docs the I'll do a bit of sandbox testing in the coming days to see if this actually returns something useful. |
This post says that |
There already seems to be some sort of detection of this implemented for the |
I need this feature for my Godot project. |
This is already implemented on Android and Linux (Wayland).
|
DisplayServer.screen_get_scale()
on Windows, Linux and AndroidDisplayServer.screen_get_scale()
on Windows, Linux (X11) and Android
Describe the project you are working on
The Godot editor 🙂
Describe the problem or limitation you are having in your project
The editor's automatic scaling factor isn't very accurate since it can't rely on the OS-defined scaling factor. Instead, it has to do guesswork based on the screen resolution and reported DPI.
There is a
screen_get_scale()
method in DisplayServer that can be used for this purpose, but it's currently only implemented for macOS, iOS, and HTML5.See godotengine/godot#48226.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Implement
DisplayServer.screen_get_scale(int p_screen)
on Windows, Linux and Android. This method returns a floating-point value corresponding to the screen's scaling factor (1.0 being 100% scale).Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
xxhdpi
correspond to floating-point values – you can see a list here.If this enhancement will not be used often, can it be worked around with a few lines of script?
No, as this is native OS-specific code and is required to ensure the editor scales correctly on all platforms out of the box.
Is there a reason why this should be core and not an add-on in the asset library?
This is core functionality for the editor.
Keywords for easier searching: hiDPI
The text was updated successfully, but these errors were encountered: