aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-04-25 10:36:59 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-04-25 10:54:09 +0300
commit74b016202b1989f400f536d3837c8e1259c42c33 (patch)
tree7011819ac028d8b3938c52c18dcbae825ec4a3ae /src
parent6ab055a4b968ccf115a1be3b65b0d5ec4d7c33f1 (diff)
downloadniri-74b016202b1989f400f536d3837c8e1259c42c33.tar.gz
niri-74b016202b1989f400f536d3837c8e1259c42c33.tar.bz2
niri-74b016202b1989f400f536d3837c8e1259c42c33.zip
Add missing bounds checks to move-workspace actions
Fixes panics.
Diffstat (limited to 'src')
-rw-r--r--src/layout/mod.rs12
-rw-r--r--src/layout/monitor.rs4
2 files changed, 15 insertions, 1 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 317ad0f6..5ade9d01 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -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.
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs
index 009e2860..74c83317 100644
--- a/src/layout/monitor.rs
+++ b/src/layout/monitor.rs
@@ -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;