Add missing bounds checks to move-workspace actions

Fixes panics.
This commit is contained in:
Ivan Molodetskikh
2025-04-25 10:36:59 +03:00
parent 6ab055a4b9
commit 74b016202b
2 changed files with 15 additions and 1 deletions
+11 -1
View File
@@ -3218,7 +3218,13 @@ impl<W: LayoutElement> Layout<W> {
if mon_idx == new_idx && ws_idx == workspace_idx {
return;
}
let ws_id = monitors[new_idx].workspaces[workspace_idx].id();
let mon = &monitors[new_idx];
if mon.workspaces.len() <= workspace_idx {
return;
}
let ws_id = mon.workspaces[workspace_idx].id();
let mon = &mut monitors[mon_idx];
let activate = activate.map_smart(|| {
@@ -3389,6 +3395,10 @@ impl<W: LayoutElement> Layout<W> {
let current = &mut monitors[current_idx];
if current.workspaces.len() <= old_idx {
return false;
}
// Do not do anything if the output is already correct
if current_idx == target_idx {
// Just update the original output since this is an explicit movement action.
+4
View File
@@ -772,6 +772,10 @@ impl<W: LayoutElement> Monitor<W> {
}
pub fn move_workspace_to_idx(&mut self, old_idx: usize, new_idx: usize) {
if self.workspaces.len() <= old_idx {
return;
}
let mut new_idx = new_idx.clamp(0, self.workspaces.len() - 1);
if old_idx == new_idx {
return;