From a1ec4b640349c51f4b9c5c6c7a2d4c38d20a6742 Mon Sep 17 00:00:00 2001 From: John Axel Eriksson Date: Tue, 11 Apr 2023 23:59:54 +0200 Subject: [PATCH] Fix missing previously_focused_id --- src/server/event_handlers/misc/window_focus.rs | 16 +++++++++++++--- src/server/message_handler.rs | 8 +++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/server/event_handlers/misc/window_focus.rs b/src/server/event_handlers/misc/window_focus.rs index 1691867..835d284 100644 --- a/src/server/event_handlers/misc/window_focus.rs +++ b/src/server/event_handlers/misc/window_focus.rs @@ -16,22 +16,32 @@ impl WindowFocus { event: Box, window_focus_cmd: Option, window_focus_leave_cmd: Option, - ) { - if let Ok(mut manager) = Self::new(window_focus_cmd, window_focus_leave_cmd).await { + previously_focused_id: Option, + ) -> Option { + if let Ok(mut manager) = Self::new( + window_focus_cmd, + window_focus_leave_cmd, + previously_focused_id, + ) + .await + { manager.handle(event).await; + return manager.previously_focused_id; } + None } pub async fn new( window_focus_cmd: Option, window_focus_leave_cmd: Option, + previously_focused_id: Option, ) -> Result { let connection = Connection::new().await?; Ok(Self { connection, window_focus_cmd, window_focus_leave_cmd, - previously_focused_id: None, + previously_focused_id, }) } diff --git a/src/server/message_handler.rs b/src/server/message_handler.rs index 6f781a2..7bd5e69 100644 --- a/src/server/message_handler.rs +++ b/src/server/message_handler.rs @@ -21,6 +21,7 @@ pub struct MessageHandler { workspace_renaming: bool, on_window_focus: Option, on_window_focus_leave: Option, + previously_focused_id: Option, } impl MessageHandler { @@ -36,6 +37,7 @@ impl MessageHandler { workspace_renaming, on_window_focus, on_window_focus_leave, + previously_focused_id: None, } } @@ -71,12 +73,16 @@ impl MessageHandler { if self.workspace_renaming { event_handlers::misc::workspace_renamer::WorkspaceRenamer::handle(event.clone()).await; } - event_handlers::misc::window_focus::WindowFocus::handle( + let previously_focused_id = event_handlers::misc::window_focus::WindowFocus::handle( event.clone(), self.on_window_focus.clone(), self.on_window_focus_leave.clone(), + self.previously_focused_id, ) .await; + if let Some(previously_focused_id) = previously_focused_id { + self.previously_focused_id = Some(previously_focused_id); + } Ok(()) } pub async fn handle_command(&mut self, cmd: PerswayCommand) -> Result<()> {