Skip to content

Commit

Permalink
PopupWindow: Fix escape with the Qt backend
Browse files Browse the repository at this point in the history
With the Qt backend, the PopupWindow has it's own Window, so we need to
make sure we close the popup on the right Window

Fixes #7332
  • Loading branch information
ogoffart committed Jan 13, 2025
1 parent 36381c5 commit d17d5dd
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions internal/core/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,15 +746,26 @@ impl WindowInner {
&& event.text.starts_with(key_codes::Escape)
{
// Closes top most popup on esc key pressed when policy is not no-auto-close
let close_on_escape = if let Some(popup) = self.active_popups.borrow().last() {

// Try to get the parent window in case `self` is the popup itself
let mut adapter = self.window_adapter();
let item_tree = self.component();
let mut a = None;
ItemTreeRc::borrow_pin(&item_tree).as_ref().window_adapter(false, &mut a);
if let Some(a) = a {
adapter = a;
}
let window = WindowInner::from_pub(adapter.window());

let close_on_escape = if let Some(popup) = window.active_popups.borrow().last() {
popup.close_policy == PopupClosePolicy::CloseOnClick
|| popup.close_policy == PopupClosePolicy::CloseOnClickOutside
} else {
false
};

if close_on_escape {
self.close_top_popup();
window.close_top_popup();
}
}
crate::properties::ChangeTracker::run_change_handlers();
Expand Down

0 comments on commit d17d5dd

Please sign in to comment.