From 8aa501c0e05ac94248cd1692424206292fbb8c35 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Wed, 9 Jul 2025 13:04:35 -0700 Subject: [PATCH] shell: Make `activate`/`end_workspace_swipe` return `Err` if no set It doesn't seem like there's really a need to have `Err(_)` and `Ok(None)`. `Err(_)` means the set exists for the output, but doesn't have the appropriate workspace index. It's a bit odd that the set not even existing becomes `Ok(None)`. Instead, just return `Err(InvalidWorkspaceIndex)` in either case. --- src/input/actions.rs | 6 ++--- src/shell/mod.rs | 28 ++++++++++----------- src/wayland/handlers/toplevel_management.rs | 5 +--- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/input/actions.rs b/src/input/actions.rs index 398df542..218dded9 100644 --- a/src/input/actions.rs +++ b/src/input/actions.rs @@ -539,7 +539,7 @@ impl State { res }; - if let Ok(Some(new_pos)) = res { + if let Ok(new_pos) = res { let workspace = shell.workspaces.active(&next_output).unwrap().1; let new_target = workspace .focus_stack @@ -1080,7 +1080,7 @@ fn to_next_workspace( seat: &Seat, gesture: bool, workspace_state: &mut WorkspaceUpdateGuard<'_, State>, -) -> Result>, InvalidWorkspaceIndex> { +) -> Result, InvalidWorkspaceIndex> { let current_output = seat.active_output(); let workspace = shell .workspaces @@ -1106,7 +1106,7 @@ fn to_previous_workspace( seat: &Seat, gesture: bool, workspace_state: &mut WorkspaceUpdateGuard<'_, State>, -) -> Result>, InvalidWorkspaceIndex> { +) -> Result, InvalidWorkspaceIndex> { let current_output = seat.active_output(); let workspace = shell .workspaces diff --git a/src/shell/mod.rs b/src/shell/mod.rs index c4397dca..227dfec0 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -1512,7 +1512,7 @@ impl Shell { idx: usize, workspace_delta: WorkspaceDelta, workspace_state: &mut WorkspaceUpdateGuard<'_, State>, - ) -> Result>, InvalidWorkspaceIndex> { + ) -> Result, InvalidWorkspaceIndex> { match &mut self.workspaces.mode { WorkspaceMode::OutputBound => { if let Some(set) = self.workspaces.sets.get_mut(output) { @@ -1525,12 +1525,12 @@ impl Shell { set.activate(idx, workspace_delta, workspace_state)?; let output_geo = output.geometry(); - Ok(Some( + Ok( output_geo.loc + Point::from((output_geo.size.w / 2, output_geo.size.h / 2)), - )) + ) } else { - Ok(None) + Err(InvalidWorkspaceIndex) } } WorkspaceMode::Global => { @@ -1538,9 +1538,7 @@ impl Shell { set.activate(idx, workspace_delta, workspace_state)?; } let output_geo = output.geometry(); - Ok(Some( - output_geo.loc + Point::from((output_geo.size.w / 2, output_geo.size.h / 2)), - )) + Ok(output_geo.loc + Point::from((output_geo.size.w / 2, output_geo.size.h / 2))) } } } @@ -1565,7 +1563,7 @@ impl Shell { output: &Output, velocity: f64, workspace_state: &mut WorkspaceUpdateGuard<'_, State>, - ) -> Result>, InvalidWorkspaceIndex> { + ) -> Result, InvalidWorkspaceIndex> { match &mut self.workspaces.mode { WorkspaceMode::OutputBound => { if let Some(set) = self.workspaces.sets.get_mut(output) { @@ -1605,12 +1603,12 @@ impl Shell { } let output_geo = output.geometry(); - Ok(Some( + Ok( output_geo.loc + Point::from((output_geo.size.w / 2, output_geo.size.h / 2)), - )) + ) } else { - Ok(None) + Err(InvalidWorkspaceIndex) } } WorkspaceMode::Global => { @@ -1644,7 +1642,7 @@ impl Shell { } } } - Ok(None) + Err(InvalidWorkspaceIndex) } } } @@ -2942,7 +2940,7 @@ impl Shell { WorkspaceDelta::new_shortcut(), workspace_state, ) - .unwrap() + .ok() }) } else { None @@ -3099,7 +3097,7 @@ impl Shell { WorkspaceDelta::new_shortcut(), workspace_state, ) - .unwrap() + .ok() }) } else { None @@ -3209,7 +3207,7 @@ impl Shell { WorkspaceDelta::new_shortcut(), workspace_state, ) - .unwrap() + .ok() }) } else { None diff --git a/src/wayland/handlers/toplevel_management.rs b/src/wayland/handlers/toplevel_management.rs index 8017ad04..2a39328e 100644 --- a/src/wayland/handlers/toplevel_management.rs +++ b/src/wayland/handlers/toplevel_management.rs @@ -90,7 +90,7 @@ impl ToplevelManagementHandler for State { if seat.active_output() != *output { match res { - Ok(Some(new_pos)) => { + Ok(new_pos) => { seat.set_active_output(&output); if let Some(ptr) = seat.get_pointer() { let serial = SERIAL_COUNTER.next_serial(); @@ -106,9 +106,6 @@ impl ToplevelManagementHandler for State { ptr.frame(self); } } - Ok(None) => { - seat.set_active_output(&output); - } _ => {} } }