mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Add missing bounds checks to move-workspace actions
Fixes panics.
This commit is contained in:
+11
-1
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user