From bfa7497c1bf1073a2fcaaa9badd6f312a7e9bc28 Mon Sep 17 00:00:00 2001 From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com> Date: Thu, 6 Jul 2023 01:04:16 +0200 Subject: [PATCH] Revert "Fix focusloss of non-exclusive `AcceptDialog` with `close_on_escape`" This reverts commit 7f547fcf09e7af0e2443356fe7a003c3c8335cd6. --- scene/gui/dialogs.cpp | 35 ++++++++++++++++++++++++++++++++--- scene/gui/dialogs.h | 3 +++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 9e99bda60b4b..0860bf39682b 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -44,6 +44,12 @@ void AcceptDialog::_input_from_window(const Ref &p_event) { } } +void AcceptDialog::_parent_focused() { + if (close_on_escape && !is_exclusive()) { + _cancel_pressed(); + } +} + void AcceptDialog::_update_theme_item_cache() { Window::_update_theme_item_cache(); @@ -64,6 +70,16 @@ void AcceptDialog::_notification(int p_what) { get_ok_button()->grab_focus(); } _update_child_rects(); + + parent_visible = get_parent_visible_window(); + if (parent_visible) { + parent_visible->connect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + } + } else { + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible = nullptr; + } } } break; @@ -76,9 +92,10 @@ void AcceptDialog::_notification(int p_what) { } } break; - case NOTIFICATION_WM_WINDOW_FOCUS_OUT: { - if (close_on_escape && !is_exclusive()) { - _cancel_pressed(); + case NOTIFICATION_EXIT_TREE: { + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible = nullptr; } } break; @@ -112,9 +129,21 @@ void AcceptDialog::_ok_pressed() { } void AcceptDialog::_cancel_pressed() { + Window *parent_window = parent_visible; + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible = nullptr; + } + call_deferred(SNAME("hide")); + emit_signal(SNAME("canceled")); + cancel_pressed(); + + if (parent_window) { + //parent_window->grab_focus(); + } set_input_as_handled(); } diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h index ebe5ce326a65..1821a886c069 100644 --- a/scene/gui/dialogs.h +++ b/scene/gui/dialogs.h @@ -44,6 +44,8 @@ class LineEdit; class AcceptDialog : public Window { GDCLASS(AcceptDialog, Window); + Window *parent_visible = nullptr; + Panel *bg_panel = nullptr; Label *message_label = nullptr; HBoxContainer *buttons_hbox = nullptr; @@ -63,6 +65,7 @@ class AcceptDialog : public Window { static bool swap_cancel_ok; void _input_from_window(const Ref &p_event); + void _parent_focused(); protected: virtual Size2 _get_contents_minimum_size() const override;