Merge pull request #40084 from bruvzg/macos_seamless_scaling
[macOS] Implement seamless display scaling.
This commit is contained in:
commit
8ccb1cec91
@ -523,6 +523,15 @@
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="screen_get_max_scale" qualifiers="const">
|
||||
<return type="float">
|
||||
</return>
|
||||
<description>
|
||||
Return the greatest scale factor of all screens.
|
||||
[b]Note:[/b] On macOS returned value is [code]2.0[/code] if there is at least one hiDPI (Retina) screen in the system, and [code]1.0[/code] in all other cases.
|
||||
[b]Note:[/b] This method is implemented on macOS.
|
||||
</description>
|
||||
</method>
|
||||
<method name="screen_get_orientation" qualifiers="const">
|
||||
<return type="int" enum="DisplayServer.ScreenOrientation">
|
||||
</return>
|
||||
@ -545,6 +554,9 @@
|
||||
<argument index="0" name="screen" type="int" default="-1">
|
||||
</argument>
|
||||
<description>
|
||||
Return the scale factor of the specified screen by index.
|
||||
[b]Note:[/b] On macOS returned value is [code]2.0[/code] for hiDPI (Retina) screen, and [code]1.0[/code] for all other cases.
|
||||
[b]Note:[/b] This method is implemented on macOS.
|
||||
</description>
|
||||
</method>
|
||||
<method name="screen_get_size" qualifiers="const">
|
||||
|
@ -5520,10 +5520,10 @@ EditorNode::EditorNode() {
|
||||
switch (display_scale) {
|
||||
case 0: {
|
||||
// Try applying a suitable display scale automatically
|
||||
const int screen = DisplayServer::get_singleton()->window_get_current_screen();
|
||||
#ifdef OSX_ENABLED
|
||||
editor_set_scale(DisplayServer::get_singleton()->screen_get_scale(screen));
|
||||
editor_set_scale(DisplayServer::get_singleton()->screen_get_max_scale());
|
||||
#else
|
||||
const int screen = DisplayServer::get_singleton()->window_get_current_screen();
|
||||
editor_set_scale(DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && DisplayServer::get_singleton()->screen_get_size(screen).x > 2000 ? 2.0 : 1.0);
|
||||
#endif
|
||||
} break;
|
||||
|
@ -108,24 +108,33 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L
|
||||
}
|
||||
|
||||
int window_placement = EditorSettings::get_singleton()->get("run/window_placement/rect");
|
||||
bool hidpi_proj = ProjectSettings::get_singleton()->get("display/window/dpi/allow_hidpi");
|
||||
int display_scale = 1;
|
||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_HIDPI)) {
|
||||
if (OS::get_singleton()->is_hidpi_allowed()) {
|
||||
if (hidpi_proj) {
|
||||
display_scale = 1; // Both editor and project runs in hiDPI mode, do not scale.
|
||||
} else {
|
||||
display_scale = DisplayServer::get_singleton()->screen_get_max_scale(); // Editor is in hiDPI mode, project is not, scale down.
|
||||
}
|
||||
} else {
|
||||
if (hidpi_proj) {
|
||||
display_scale = (1.f / DisplayServer::get_singleton()->screen_get_max_scale()); // Editor is not in hiDPI mode, project is, scale up.
|
||||
} else {
|
||||
display_scale = 1; // Both editor and project runs in lowDPI mode, do not scale.
|
||||
}
|
||||
}
|
||||
screen_rect.position /= display_scale;
|
||||
screen_rect.size /= display_scale;
|
||||
}
|
||||
|
||||
switch (window_placement) {
|
||||
case 0: { // top left
|
||||
|
||||
args.push_back("--position");
|
||||
args.push_back(itos(screen_rect.position.x) + "," + itos(screen_rect.position.y));
|
||||
} break;
|
||||
case 1: { // centered
|
||||
int display_scale = 1;
|
||||
#ifdef OSX_ENABLED
|
||||
display_scale = DisplayServer::get_singleton()->screen_get_scale(screen);
|
||||
#else
|
||||
if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && DisplayServer::get_singleton()->screen_get_size(screen).x > 2000) {
|
||||
display_scale = 2;
|
||||
}
|
||||
#endif
|
||||
|
||||
Vector2 pos = screen_rect.position + ((screen_rect.size / display_scale - desired_size) / 2).floor();
|
||||
Vector2 pos = (screen_rect.position) + ((screen_rect.size - desired_size) / 2).floor();
|
||||
args.push_back("--position");
|
||||
args.push_back(itos(pos.x) + "," + itos(pos.y));
|
||||
} break;
|
||||
@ -140,10 +149,8 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L
|
||||
args.push_back("--position");
|
||||
args.push_back(itos(pos.x) + "," + itos(pos.y));
|
||||
args.push_back("--maximized");
|
||||
|
||||
} break;
|
||||
case 4: { // force fullscreen
|
||||
|
||||
Vector2 pos = screen_rect.position;
|
||||
args.push_back("--position");
|
||||
args.push_back(itos(pos.x) + "," + itos(pos.y));
|
||||
|
@ -2336,10 +2336,10 @@ ProjectManager::ProjectManager() {
|
||||
switch (display_scale) {
|
||||
case 0: {
|
||||
// Try applying a suitable display scale automatically
|
||||
const int screen = DisplayServer::get_singleton()->window_get_current_screen();
|
||||
#ifdef OSX_ENABLED
|
||||
editor_set_scale(DisplayServer::get_singleton()->screen_get_scale(screen));
|
||||
editor_set_scale(DisplayServer::get_singleton()->screen_get_max_scale());
|
||||
#else
|
||||
const int screen = DisplayServer::get_singleton()->window_get_current_screen();
|
||||
editor_set_scale(DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && DisplayServer::get_singleton()->screen_get_size(screen).x > 2000 ? 2.0 : 1.0);
|
||||
#endif
|
||||
} break;
|
||||
@ -2371,11 +2371,8 @@ ProjectManager::ProjectManager() {
|
||||
// Define a minimum window size to prevent UI elements from overlapping or being cut off
|
||||
DisplayServer::get_singleton()->window_set_min_size(Size2(750, 420) * EDSCALE);
|
||||
|
||||
#ifndef OSX_ENABLED
|
||||
// The macOS platform implementation uses its own hiDPI window resizing code
|
||||
// TODO: Resize windows on hiDPI displays on Windows and Linux and remove the line below
|
||||
DisplayServer::get_singleton()->window_set_size(DisplayServer::get_singleton()->window_get_size() * MAX(1, EDSCALE));
|
||||
#endif
|
||||
}
|
||||
|
||||
FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files"));
|
||||
|
@ -132,6 +132,7 @@ public:
|
||||
bool on_top = false;
|
||||
bool borderless = false;
|
||||
bool resize_disabled = false;
|
||||
bool no_focus = false;
|
||||
};
|
||||
|
||||
Point2i im_selection;
|
||||
@ -150,7 +151,6 @@ public:
|
||||
|
||||
void _set_window_per_pixel_transparency_enabled(bool p_enabled, WindowID p_window);
|
||||
|
||||
float _display_scale(id screen) const;
|
||||
Point2i _get_screens_origin() const;
|
||||
Point2i _get_native_screen_position(int p_screen) const;
|
||||
|
||||
@ -224,6 +224,7 @@ public:
|
||||
virtual Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
|
||||
virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
|
||||
virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
|
||||
virtual float screen_get_max_scale() const;
|
||||
virtual Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
|
||||
|
||||
virtual Vector<int> get_window_list() const;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -338,6 +338,7 @@ void Window::_event_callback(DisplayServer::WindowEvent p_event) {
|
||||
emit_signal("go_back_requested");
|
||||
} break;
|
||||
case DisplayServer::WINDOW_EVENT_DPI_CHANGE: {
|
||||
_update_viewport_size();
|
||||
_propagate_window_notification(this, NOTIFICATION_WM_DPI_CHANGE);
|
||||
emit_signal("dpi_changed");
|
||||
} break;
|
||||
|
@ -392,6 +392,7 @@ void DisplayServer::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("screen_get_dpi", "screen"), &DisplayServer::screen_get_dpi, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
||||
ClassDB::bind_method(D_METHOD("screen_get_scale", "screen"), &DisplayServer::screen_get_scale, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
||||
ClassDB::bind_method(D_METHOD("screen_is_touchscreen", "screen"), &DisplayServer::screen_is_touchscreen, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
||||
ClassDB::bind_method(D_METHOD("screen_get_max_scale"), &DisplayServer::screen_get_max_scale);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("screen_set_orientation", "orientation", "screen"), &DisplayServer::screen_set_orientation, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
||||
ClassDB::bind_method(D_METHOD("screen_get_orientation", "screen"), &DisplayServer::screen_get_orientation, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
||||
|
@ -167,6 +167,14 @@ public:
|
||||
virtual Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
|
||||
virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
|
||||
virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
|
||||
virtual float screen_get_max_scale() const {
|
||||
float scale = 1.f;
|
||||
int screen_count = get_screen_count();
|
||||
for (int i = 0; i < screen_count; i++) {
|
||||
scale = fmax(scale, screen_get_scale(i));
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
|
||||
enum ScreenOrientation {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user