From 00da2bbcb6b549ca866b0edf86a1f27c62c52dad Mon Sep 17 00:00:00 2001 From: Exidex <16986685+Exidex@users.noreply.github.com> Date: Tue, 30 Jan 2024 19:19:12 +0100 Subject: [PATCH] Implement client window closing on unfocus --- rust/client/src/ui/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rust/client/src/ui/mod.rs b/rust/client/src/ui/mod.rs index 18deeaf..4e3cc31 100644 --- a/rust/client/src/ui/mod.rs +++ b/rust/client/src/ui/mod.rs @@ -38,6 +38,7 @@ pub struct AppModel { search_results: Vec, request_rx: Arc>>, search_field_id: text_input::Id, + waiting_for_next_unfocus: bool } enum NavState { @@ -135,6 +136,7 @@ impl Application for AppModel { state: vec![NavState::SearchView { prompt: None }], search_results: vec![], search_field_id: search_field_id.clone(), + waiting_for_next_unfocus: false, }, Command::batch([ Command::perform(async {}, |_| AppMsg::PromptChanged("".to_owned())), @@ -248,6 +250,16 @@ impl Application for AppModel { _ => Command::none() } } + AppMsg::IcedEvent(Event::Window(iced::window::Event::Unfocused)) => { + // for some reason Unfocused fires right at the application start + // and second time on actual window unfocus + if self.waiting_for_next_unfocus { + iced::window::close() + } else { + self.waiting_for_next_unfocus = true; + Command::none() + } + } AppMsg::IcedEvent(_) => Command::none(), AppMsg::WidgetEvent { widget_event: ComponentWidgetEvent::PreviousView, .. } => self.previous_view(), AppMsg::WidgetEvent { widget_event, plugin_id } => {