From 10539a4bab380015e612c0154e6d9c29d8671f82 Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Sat, 14 Dec 2024 10:46:44 +0000 Subject: [PATCH] fix(bar): prevent the bar from changing mff value This commit makes use of the new `send_batch` function to batch all the messages in one go when pressing the button to move between workspaces or when moving between stacked windows. Since we are creating this messages in one go we won't be mistakenly changing the value of mff for the user. It also only batches the mff messages when the mff value it's true, if it is already false there is no need to be sending those extra messages. --- komorebi-bar/src/komorebi.rs | 112 +++++++++++++++-------------------- 1 file changed, 48 insertions(+), 64 deletions(-) diff --git a/komorebi-bar/src/komorebi.rs b/komorebi-bar/src/komorebi.rs index 99e82836..e919f56c 100644 --- a/komorebi-bar/src/komorebi.rs +++ b/komorebi-bar/src/komorebi.rs @@ -220,53 +220,45 @@ impl BarWidget for Komorebi { .clicked() { update = Some(ws.to_string()); - let mut proceed = true; - if komorebi_client::send_message(&SocketMessage::MouseFollowsFocus( - false, - )) - .is_err() - { - tracing::error!( - "could not send message to komorebi: MouseFollowsFocus" - ); - proceed = false; - } - - if proceed - && komorebi_client::send_message( - &SocketMessage::FocusMonitorWorkspaceNumber( + if komorebi_notification_state.mouse_follows_focus { + if komorebi_client::send_batch([ + SocketMessage::MouseFollowsFocus(false), + SocketMessage::FocusMonitorWorkspaceNumber( komorebi_notification_state.monitor_index, i, ), - ) + SocketMessage::RetileWithResizeDimensions, + SocketMessage::MouseFollowsFocus(true), + ]) .is_err() + { + tracing::error!( + "could not send the following batch of messages to komorebi:\n + MouseFollowsFocus(false)\n + FocusMonitorWorkspaceNumber({}, {})\n + RetileWithResizeDimensions + MouseFollowsFocus(true)\n", + komorebi_notification_state.monitor_index, + i, + ); + } + } else if komorebi_client::send_batch([ + SocketMessage::FocusMonitorWorkspaceNumber( + komorebi_notification_state.monitor_index, + i, + ), + SocketMessage::RetileWithResizeDimensions, + ]) + .is_err() { tracing::error!( - "could not send message to komorebi: FocusWorkspaceNumber" + "could not send the following batch of messages to komorebi:\n + FocusMonitorWorkspaceNumber({}, {})\n + RetileWithResizeDimensions", + komorebi_notification_state.monitor_index, + i, ); - proceed = false; - } - - if proceed - && komorebi_client::send_message(&SocketMessage::MouseFollowsFocus( - komorebi_notification_state.mouse_follows_focus, - )) - .is_err() - { - tracing::error!( - "could not send message to komorebi: MouseFollowsFocus" - ); - proceed = false; - } - - if proceed - && komorebi_client::send_message( - &SocketMessage::RetileWithResizeDimensions, - ) - .is_err() - { - tracing::error!("could not send message to komorebi: Retile"); } } } @@ -426,35 +418,27 @@ impl BarWidget for Komorebi { return; } - if komorebi_client::send_message(&SocketMessage::MouseFollowsFocus( - false, - )) - .is_err() - { - tracing::error!( - "could not send message to komorebi: MouseFollowsFocus" - ); - } - - if komorebi_client::send_message(&SocketMessage::FocusStackWindow( - i, - )) - .is_err() - { + if komorebi_notification_state.mouse_follows_focus { + if komorebi_client::send_batch([ + SocketMessage::MouseFollowsFocus(false), + SocketMessage::FocusStackWindow(i), + SocketMessage::MouseFollowsFocus(true), + ]).is_err() { + tracing::error!( + "could not send the following batch of messages to komorebi:\n + MouseFollowsFocus(false)\n + FocusStackWindow({})\n + MouseFollowsFocus(true)\n", + i, + ); + } + } else if komorebi_client::send_message( + &SocketMessage::FocusStackWindow(i) + ).is_err() { tracing::error!( "could not send message to komorebi: FocusStackWindow" ); } - - if komorebi_client::send_message(&SocketMessage::MouseFollowsFocus( - komorebi_notification_state.mouse_follows_focus, - )) - .is_err() - { - tracing::error!( - "could not send message to komorebi: MouseFollowsFocus" - ); - } } } });