Skip to content

Commit 778e884

Browse files
authored
hyprland: Fixed active workspace selection with named workspaces (#36)
1 parent 1bf110c commit 778e884

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/wm_info_provider/hyprland.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,28 @@ fn hyprland_cb(conn: &mut Connection<State>, state: &mut State) -> io::Result<()
114114
match hyprland.ipc.next_event() {
115115
Ok(event) => {
116116
if let Some(active_ws) = event.strip_prefix("workspace>>") {
117-
hyprland.active_id = active_ws
118-
.parse()
119-
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
117+
let ws = hyprland
118+
.workspaces
119+
.iter()
120+
.find(|ws| ws.name == active_ws)
121+
.ok_or_else(|| {
122+
io::Error::new(io::ErrorKind::InvalidData, "Unknown workspace")
123+
})?;
124+
hyprland.active_id = ws.id;
120125
updated = true;
121126
} else if let Some(data) = event.strip_prefix("focusedmon>>") {
122127
let (_monitor, active_ws) = data.split_once(',').ok_or_else(|| {
123128
io::Error::new(io::ErrorKind::InvalidData, "Too few fields in data")
124129
})?;
125130

126-
hyprland.active_id = active_ws
127-
.parse()
128-
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
131+
let ws = hyprland
132+
.workspaces
133+
.iter()
134+
.find(|ws| ws.name == active_ws)
135+
.ok_or_else(|| {
136+
io::Error::new(io::ErrorKind::InvalidData, "Unknown workspace")
137+
})?;
138+
hyprland.active_id = ws.id;
129139
updated = true;
130140
} else if event.contains("workspace>>") {
131141
hyprland.workspaces = hyprland.ipc.query_sorted_workspaces()?;

0 commit comments

Comments
 (0)