From 4c522b0eeea3f0b583688bdf2f738445f012dfcd Mon Sep 17 00:00:00 2001 From: Jason Rodney Hansen Date: Sat, 11 Jan 2025 14:01:29 -0700 Subject: [PATCH] Close context menu when window loses focus --- src/app.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/app.rs b/src/app.rs index e348122..0606d90 100644 --- a/src/app.rs +++ b/src/app.rs @@ -352,6 +352,7 @@ pub enum Message { WindowClose, WindowCloseRequested(window::Id), WindowNew, + WindowUnfocus, ZoomDefault(Option), ZoomIn(Option), ZoomOut(Option), @@ -3025,6 +3026,12 @@ impl Application for App { ]); } } + Message::WindowUnfocus => { + let tab_entity = self.tab_model.active(); + if let Some(tab) = self.tab_model.data_mut::(tab_entity) { + tab.context_menu = None; + } + } Message::WindowCloseRequested(id) => { self.remove_window(&id); } @@ -4370,6 +4377,7 @@ impl Application for App { Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => { Some(Message::Modifiers(modifiers)) } + Event::Window(WindowEvent::Unfocused) => Some(Message::WindowUnfocus), Event::Window(WindowEvent::CloseRequested) => Some(Message::WindowClose), Event::Window(WindowEvent::Opened { position: _, size }) => { Some(Message::Size(size))