diff options
author | kobewi <kobewi4e@gmail.com> | 2022-05-23 23:00:29 +0200 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2022-09-26 13:44:25 +0200 |
commit | a4c3551dc6582a9cfe25655a0119a73a099ea8bc (patch) | |
tree | 7854982555c09551cd4e42e2b0c7c41f4d830373 | |
parent | 3472bdd6b6dd7c085b716caabdda16f88e6f167e (diff) |
Force window position if spawned outside screen
-rw-r--r-- | scene/main/window.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/scene/main/window.cpp b/scene/main/window.cpp index cf30ca259d..73f278bb50 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -1251,6 +1251,15 @@ void Window::popup(const Rect2i &p_screen_rect) { set_transient(true); set_visible(true); + + int screen_id = DisplayServer::get_singleton()->window_get_current_screen(get_window_id()); + Rect2i screen_rect = DisplayServer::get_singleton()->screen_get_usable_rect(screen_id); + if (screen_rect != Rect2i() && !screen_rect.intersects(Rect2i(position, size))) { + ERR_PRINT(vformat("Window %d spawned at invalid position: %s.", get_window_id(), position)); + // Window appeared on unavailable screen area, so force it to the center. + set_position(screen_rect.size / 2 - size / 2); + } + _post_popup(); notification(NOTIFICATION_POST_POPUP); } |