From db53e9ed4f6a893f0d690c7bf41e0275a4b76d6f Mon Sep 17 00:00:00 2001 From: Florian Straubinger Date: Sat, 5 Oct 2024 14:41:31 +0200 Subject: [PATCH] Fixed hyprland active workspace selection with named workspaces --- src/wm_info_provider/hyprland.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/wm_info_provider/hyprland.rs b/src/wm_info_provider/hyprland.rs index a59a68f..4925cb2 100644 --- a/src/wm_info_provider/hyprland.rs +++ b/src/wm_info_provider/hyprland.rs @@ -114,19 +114,25 @@ fn hyprland_cb(conn: &mut Connection, state: &mut State) -> io::Result<() match hyprland.ipc.next_event() { Ok(event) => { if let Some(active_ws) = event.strip_prefix("workspace>>") { - hyprland.active_id = active_ws - .parse() - .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; - updated = true; + match hyprland.workspaces.iter().find(|ws| ws.name == active_ws) { + Some(ws) => { + hyprland.active_id = ws.id; + updated = true; + } + None => return Err(io::Error::new(io::ErrorKind::InvalidData, "Unknown workspace")) + } } else if let Some(data) = event.strip_prefix("focusedmon>>") { let (_monitor, active_ws) = data.split_once(',').ok_or_else(|| { io::Error::new(io::ErrorKind::InvalidData, "Too few fields in data") })?; - hyprland.active_id = active_ws - .parse() - .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; - updated = true; + match hyprland.workspaces.iter().find(|ws| ws.name == active_ws) { + Some(ws) => { + hyprland.active_id = ws.id; + updated = true; + } + None => return Err(io::Error::new(io::ErrorKind::InvalidData, "Unknown workspace")) + } } else if event.contains("workspace>>") { hyprland.workspaces = hyprland.ipc.query_sorted_workspaces()?; updated = true;