From 041ef5731c060bc94ed1c64384fcda3e4b7f8d50 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 19 Nov 2024 20:44:46 -0800 Subject: [PATCH] refactor(bar): use monitor idx when switching ws This commit follows up on a point made by @notTamion in #1128 - since we have the monitor index, we can use it in the bar's workspace widget to more accurately target workspaces via SocketMessage::FocusMonitorWorkspaceNumber. --- komorebi-bar/src/komorebi.rs | 14 +++++++++++--- komorebi-bar/src/main.rs | 4 ++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/komorebi-bar/src/komorebi.rs b/komorebi-bar/src/komorebi.rs index ad95c0989..17d60904f 100644 --- a/komorebi-bar/src/komorebi.rs +++ b/komorebi-bar/src/komorebi.rs @@ -4,6 +4,7 @@ use crate::render::RenderConfig; use crate::ui::CustomUi; use crate::widget::BarWidget; use crate::MAX_LABEL_WIDTH; +use crate::MONITOR_INDEX; use crossbeam_channel::Receiver; use crossbeam_channel::TryRecvError; use eframe::egui::text::LayoutJob; @@ -103,6 +104,7 @@ impl From<&KomorebiConfig> for Komorebi { work_area_offset: None, focused_container_information: (vec![], vec![], 0), stack_accent: None, + monitor_index: MONITOR_INDEX.load(Ordering::SeqCst), })), workspaces: value.workspaces, layout: value.layout, @@ -154,9 +156,12 @@ impl BarWidget for Komorebi { } if proceed - && komorebi_client::send_message(&SocketMessage::FocusWorkspaceNumber( - i, - )) + && komorebi_client::send_message( + &SocketMessage::FocusMonitorWorkspaceNumber( + komorebi_notification_state.monitor_index, + i, + ), + ) .is_err() { tracing::error!( @@ -435,6 +440,7 @@ pub struct KomorebiNotificationState { pub mouse_follows_focus: bool, pub work_area_offset: Option, pub stack_accent: Option, + pub monitor_index: usize, } #[derive(Copy, Clone, Debug)] @@ -497,6 +503,8 @@ impl KomorebiNotificationState { }, } + self.monitor_index = monitor_index; + self.mouse_follows_focus = notification.state.mouse_follows_focus; let monitor = ¬ification.state.monitors.elements()[monitor_index]; diff --git a/komorebi-bar/src/main.rs b/komorebi-bar/src/main.rs index 4d30c4d78..771589c13 100644 --- a/komorebi-bar/src/main.rs +++ b/komorebi-bar/src/main.rs @@ -29,6 +29,7 @@ use std::io::BufReader; use std::io::Read; use std::path::PathBuf; use std::sync::atomic::AtomicI32; +use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::sync::Arc; use std::time::Duration; @@ -47,6 +48,7 @@ pub static MAX_LABEL_WIDTH: AtomicI32 = AtomicI32::new(400); pub static MONITOR_LEFT: AtomicI32 = AtomicI32::new(0); pub static MONITOR_TOP: AtomicI32 = AtomicI32::new(0); pub static MONITOR_RIGHT: AtomicI32 = AtomicI32::new(0); +pub static MONITOR_INDEX: AtomicUsize = AtomicUsize::new(0); pub static BAR_HEIGHT: f32 = 50.0; #[derive(Parser)] @@ -233,6 +235,8 @@ fn main() -> color_eyre::Result<()> { Ordering::SeqCst, ); + MONITOR_INDEX.store(config.monitor.index, Ordering::SeqCst); + match config.position { None => { config.position = Some(PositionConfig {