shell: Allow active workspace to be None

This commit is contained in:
Victoria Brekenfeld 2025-01-06 19:23:06 +01:00 committed by Victoria Brekenfeld
parent 23570ea9f4
commit db13eea91c
13 changed files with 230 additions and 167 deletions

View file

@ -408,6 +408,7 @@ impl State {
let new_target = shell
.workspaces
.active(&next_output)
.unwrap()
.1
.focus_stack
.get(&seat)
@ -495,6 +496,7 @@ impl State {
let new_target = shell
.workspaces
.active(&next_output)
.unwrap()
.1
.focus_stack
.get(&seat)
@ -554,6 +556,7 @@ impl State {
let new_target = shell
.workspaces
.active(&prev_output)
.unwrap()
.1
.focus_stack
.get(&seat)
@ -765,7 +768,7 @@ impl State {
.next()
.cloned();
(shell.active_space(&active_output).handle, output)
(shell.active_space(&active_output).unwrap().handle, output)
};
if let Some(next_output) = next_output {
self.common
@ -785,7 +788,7 @@ impl State {
.next()
.cloned();
(shell.active_space(&active_output).handle, output)
(shell.active_space(&active_output).unwrap().handle, output)
};
if let Some(prev_output) = prev_output {
self.common
@ -799,7 +802,7 @@ impl State {
let shell = self.common.shell.read().unwrap();
(
shell.active_space(&active_output).handle,
shell.active_space(&active_output).unwrap().handle,
shell.next_output(&active_output, direction).cloned(),
)
};
@ -865,7 +868,7 @@ impl State {
_ => {
let current_output = seat.active_output();
let mut shell = self.common.shell.write().unwrap();
let workspace = shell.active_space(&current_output);
let workspace = shell.active_space(&current_output).unwrap();
if let Some(focused_window) = workspace.focus_stack.get(seat).last() {
if workspace.is_tiled(focused_window) {
shell.set_overview_mode(
@ -884,7 +887,7 @@ impl State {
};
let mut shell = self.common.shell.write().unwrap();
let workspace = shell.active_space_mut(&focused_output);
let workspace = shell.active_space_mut(&focused_output).unwrap();
if workspace.get_fullscreen().is_some() {
return; // TODO, is this what we want? Maybe disengage fullscreen instead?
}
@ -909,7 +912,7 @@ impl State {
return;
};
let mut shell = self.common.shell.write().unwrap();
let workspace = shell.active_space_mut(&focused_output);
let workspace = shell.active_space_mut(&focused_output).unwrap();
let focus_stack = workspace.focus_stack.get(seat);
let focused_window = focus_stack.last().cloned();
if let Some(window) = focused_window {
@ -922,7 +925,7 @@ impl State {
return;
};
let mut shell = self.common.shell.write().unwrap();
let workspace = shell.active_space(&focused_output);
let workspace = shell.active_space(&focused_output).unwrap();
let focus_stack = workspace.focus_stack.get(seat);
let focused_window = focus_stack.last().cloned();
if let Some(window) = focused_window {
@ -940,14 +943,14 @@ impl State {
Action::ToggleOrientation => {
let output = seat.active_output();
let mut shell = self.common.shell.write().unwrap();
let workspace = shell.active_space_mut(&output);
let workspace = shell.active_space_mut(&output).unwrap();
workspace.tiling_layer.update_orientation(None, &seat);
}
Action::Orientation(orientation) => {
let output = seat.active_output();
let mut shell = self.common.shell.write().unwrap();
let workspace = shell.active_space_mut(&output);
let workspace = shell.active_space_mut(&output).unwrap();
workspace
.tiling_layer
.update_orientation(Some(orientation), &seat);
@ -991,7 +994,7 @@ impl State {
} else {
let output = seat.active_output();
let mut shell = self.common.shell.write().unwrap();
let workspace = shell.workspaces.active_mut(&output);
let workspace = shell.workspaces.active_mut(&output).unwrap();
let mut guard = self.common.workspace_state.update();
workspace.toggle_tiling(seat, &mut guard);
}
@ -1002,7 +1005,7 @@ impl State {
return;
};
let mut shell = self.common.shell.write().unwrap();
let workspace = shell.active_space_mut(&output);
let workspace = shell.active_space_mut(&output).unwrap();
workspace.toggle_floating_window_focused(seat);
}
@ -1035,7 +1038,7 @@ impl State {
let (token, data) = (token.clone(), data.clone());
let output = shell.seats.last_active().active_output();
let workspace = shell.active_space_mut(&output);
let workspace = shell.active_space_mut(&output).unwrap();
workspace.pending_tokens.insert(token.clone());
let handle = workspace.handle;
std::mem::drop(shell);

View file

@ -1760,8 +1760,12 @@ impl State {
focused_output: &Output,
) {
if let Some(focus) = current_focus {
if let Some(new_descriptor) =
shell.workspaces.active(&focused_output).1.node_desc(focus)
if let Some(new_descriptor) = shell
.workspaces
.active(&focused_output)
.unwrap()
.1
.node_desc(focus)
{
let mut spaces = shell.workspaces.spaces_mut();
if old_descriptor.handle != new_descriptor.handle {
@ -1822,7 +1826,7 @@ impl State {
}
}
} else {
let new_workspace = shell.workspaces.active(&focused_output).1.handle;
let new_workspace = shell.workspaces.active(&focused_output).unwrap().1.handle;
if new_workspace != old_descriptor.handle {
let spaces = shell.workspaces.spaces_mut();
let (mut old_w, mut other_w) =
@ -1867,7 +1871,7 @@ impl State {
output: &Output,
shell: &Shell,
) -> Option<KeyboardFocusTarget> {
let (previous_workspace, workspace) = shell.workspaces.active(output);
let (previous_workspace, workspace) = shell.workspaces.active(output)?;
let (previous_idx, idx) = shell.workspaces.active_num(output);
let previous_workspace = previous_workspace
.zip(previous_idx)
@ -1990,7 +1994,7 @@ impl State {
output: &Output,
shell: &Shell,
) -> Option<(PointerFocusTarget, Point<f64, Global>)> {
let (previous_workspace, workspace) = shell.workspaces.active(output);
let (previous_workspace, workspace) = shell.workspaces.active(output)?;
let (previous_idx, idx) = shell.workspaces.active_num(output);
let previous_workspace = previous_workspace
.zip(previous_idx)
@ -2122,22 +2126,26 @@ impl State {
}
}
fn cursor_sessions_for_output(
shell: &Shell,
output: &Output,
) -> impl Iterator<Item = CursorSession> {
let workspace = shell.active_space(&output);
let maybe_fullscreen = workspace.get_fullscreen();
workspace
.cursor_sessions()
fn cursor_sessions_for_output<'a>(
shell: &'a Shell,
output: &'a Output,
) -> impl Iterator<Item = CursorSession> + 'a {
shell
.active_space(&output)
.into_iter()
.chain(
maybe_fullscreen
.map(|w| w.cursor_sessions())
.flat_map(|workspace| {
let maybe_fullscreen = workspace.get_fullscreen();
workspace
.cursor_sessions()
.into_iter()
.flatten(),
)
.chain(output.cursor_sessions().into_iter())
.chain(
maybe_fullscreen
.map(|w| w.cursor_sessions())
.into_iter()
.flatten(),
)
.chain(output.cursor_sessions().into_iter())
})
}
fn transform_output_mapped_position<'a, B, E>(output: &Output, event: &E) -> Point<f64, Global>