diff --git a/src/info.rs b/src/info.rs index 8c0d633..8983e0f 100644 --- a/src/info.rs +++ b/src/info.rs @@ -22,6 +22,8 @@ use tokio::{ use crate::{Message, State}; +use regex::Regex; + #[derive(Subcommand, Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] pub enum InfoCommand { WaybarActivityStatus, @@ -450,6 +452,11 @@ impl InfoCommand { focused: false, named_focus: focii.get(w).cloned().unwrap_or_default(), }; + // w comes with a $ in the monitor position + // name comes with a number there + // so to compare them, we have to... do something about that + let re = Regex::new(r"\d+\)").unwrap(); + let name = re.replace(&name,"$)"); if w == &name { ws.focused = true; } diff --git a/src/state.rs b/src/state.rs index 2d001f9..b31cd71 100644 --- a/src/state.rs +++ b/src/state.rs @@ -18,6 +18,8 @@ use crate::{ Message, }; +use regex::Regex; + #[derive(Debug)] pub struct State { pub focused: HashMap, @@ -51,7 +53,7 @@ impl State { .map(|name| { raw_workspaces .clone() - .map(|(x, y)| format!("{name}:({x} {y}$)")) + .map(|(x, y)| format!("{name}:({x} {y} $)")) .collect::>() }) .collect::>(); @@ -75,6 +77,12 @@ impl State { pub fn get_indices(&self, name: impl AsRef) -> Option<(usize, Option)> { let name = name.as_ref(); let activity_index = self.get_activity_index(name)?; + // w comes with a $ in the monitor position + // name comes with a number there + // so to compare them, we have to... do something about that + let re = Regex::new(r"\d+\)").unwrap(); + let binding = re.replace(&name,"$)"); + let name = binding.as_ref(); let workspace_index = self.workspaces[activity_index] .iter() .position(|w| w == name); @@ -113,39 +121,50 @@ impl State { let res = set_workspace_anim(anim).await; let name = name.as_ref(); - let mut window = None; + let monitors = Monitors::get_async().await?; + let mut monitors = monitors.into_iter().collect::>(); + monitors.sort_by(|a, b| { + if a.focused { + Ordering::Greater + } else if b.focused { + Ordering::Less + } else { + Ordering::Equal + } + }); + if move_window { - window = Client::get_active_async().await?; - } - if window.is_some() { - Dispatch::call_async(DispatchType::MoveToWorkspaceSilent( - WorkspaceIdentifierWithSpecial::Name(name), - None, - )) - .await?; + for m in monitors.iter() { + if m.focused { + let wsname = name.replace("$", &m.id.to_string()); + Dispatch::call_async(DispatchType::MoveToWorkspaceSilent( + WorkspaceIdentifierWithSpecial::Name(&wsname), + None, + )) + .await?; + } + } } + let re = Regex::new(r"\d+\)").unwrap(); + let name = re.replace(name,"$)"); match self.config.multi_monitor_strategy { MultiMonitorStrategy::SeparateWorkspaces => { // get x y for current monitor and switch all monitors to x y w - let monitors = Monitors::get_async().await?; - let mut monitors = monitors.into_iter().collect::>(); - monitors.sort_by(|a, b| { - if a.focused { - Ordering::Greater - } else if b.focused { - Ordering::Less - } else { - Ordering::Equal - } - }); + let cursor = CursorPosition::get_async().await?; for m in monitors.iter() { - let name = name.replace("$", &m.id.to_string()); + let wsname = name.replace("$", &m.id.to_string()); Dispatch::call_async(DispatchType::Custom( - "moveworkspacetomonitor", - &format!("special:{} {}", name, m.id), + "focusmonitor", + &m.id.to_string() + )) + .await?; + Dispatch::call_async(DispatchType::Custom( + "workspace", + &format!("name:{}", wsname) )) .await?; } + Dispatch::call_async(DispatchType::MoveCursor(cursor.x, cursor.y)).await?; } MultiMonitorStrategy::SharedWorkspacesSyncActivities => { // switch all monitors to their corresponding ws in activity mentioned in their current ws @@ -201,14 +220,6 @@ impl State { .await?; } } - if let Some(w) = window { - let cursor = CursorPosition::get_async().await?; - Dispatch::call_async(DispatchType::FocusWindow(WindowIdentifier::Address( - w.address, - ))) - .await?; - Dispatch::call_async(DispatchType::MoveCursor(cursor.x, cursor.y)).await?; - } res }