Avoid unnecessarily unwrapping stack_ref() after is_stack()

In a lot of cases, matching on `stack_ref()` also works.
This commit is contained in:
Ian Douglas Scott 2026-06-18 19:43:45 -07:00 committed by Ian Douglas Scott
parent 26ee83aaa7
commit f765696834
4 changed files with 20 additions and 30 deletions

View file

@ -1877,8 +1877,8 @@ impl TilingLayout {
if let Some(id) = id { if let Some(id) = id {
return match tree.get(&id).unwrap().data() { return match tree.get(&id).unwrap().data() {
Data::Mapped { mapped, .. } => { Data::Mapped { mapped, .. } => {
if mapped.is_stack() { if let Some(stack) = mapped.stack_ref() {
mapped.stack_ref().unwrap().focus_stack(); stack.focus_stack();
} }
FocusResult::Some(mapped.clone().into()) FocusResult::Some(mapped.clone().into())
} }
@ -1986,11 +1986,11 @@ impl TilingLayout {
})) }))
} }
Data::Mapped { mapped, .. } => { Data::Mapped { mapped, .. } => {
if mapped.is_stack() if let Some(stack) = mapped.stack_ref()
&& desc.stack_window.is_none() && desc.stack_window.is_none()
&& replacement_id == &desc.node && replacement_id == &desc.node
{ {
mapped.stack_ref().unwrap().focus_stack(); stack.focus_stack();
} }
FocusResult::Some(KeyboardFocusTarget::Element(mapped.clone())) FocusResult::Some(KeyboardFocusTarget::Element(mapped.clone()))
} }
@ -2062,7 +2062,7 @@ impl TilingLayout {
}); });
} }
Data::Mapped { mapped, .. } => { Data::Mapped { mapped, .. } => {
if mapped.is_stack() if let Some(stack) = mapped.stack_ref()
&& swap_desc && swap_desc
.as_ref() .as_ref()
.map(|desc| { .map(|desc| {
@ -2071,7 +2071,7 @@ impl TilingLayout {
}) })
.unwrap_or(false) .unwrap_or(false)
{ {
mapped.stack_ref().unwrap().focus_stack(); stack.focus_stack();
} }
return FocusResult::Some(mapped.clone().into()); return FocusResult::Some(mapped.clone().into());
} }

View file

@ -2856,10 +2856,12 @@ impl Shell {
let maybe_focused = workspace.focus_stack.get(&seat).iter().next().cloned(); let maybe_focused = workspace.focus_stack.get(&seat).iter().next().cloned();
if let Some(FocusTarget::Window(focused)) = maybe_focused if let Some(FocusTarget::Window(focused)) = maybe_focused
&& (focused.is_stack() && !is_dialog && !should_be_maximized) && let Some(stack) = focused.stack_ref()
&& !is_dialog
&& !should_be_maximized
&& !(workspace.is_tiled(&focused.active_window()) && floating_exception) && !(workspace.is_tiled(&focused.active_window()) && floating_exception)
{ {
focused.stack_ref().unwrap().add_window(window, None, None); stack.add_window(window, None, None);
if was_activated { if was_activated {
workspace_state.add_workspace_state(&workspace_handle, WState::Urgent); workspace_state.add_workspace_state(&workspace_handle, WState::Urgent);
} }
@ -2985,8 +2987,8 @@ impl Shell {
.map(|idx| (idx, m.clone())) .map(|idx| (idx, m.clone()))
}); });
let surface = if let Some((idx, mapped)) = sticky_res { let surface = if let Some((idx, mapped)) = sticky_res {
if mapped.is_stack() { if let Some(stack) = mapped.stack_ref() {
mapped.stack_ref().unwrap().remove_idx(idx) stack.remove_idx(idx)
} else { } else {
set.sticky_layer.unmap(&mapped, None); set.sticky_layer.unmap(&mapped, None);
Some(mapped.active_window()) Some(mapped.active_window())
@ -2996,20 +2998,13 @@ impl Shell {
.iter() .iter()
.position(|w| w.windows().any(|s| &s == surface)) .position(|w| w.windows().any(|s| &s == surface))
{ {
if set if let Some(stack) = set
.minimized_windows .minimized_windows
.get(idx) .get_mut(idx)
.unwrap() .unwrap()
.mapped() .mapped_mut()
.is_some_and(CosmicMapped::is_stack) .and_then(|m| m.stack_ref())
{ {
let window = set
.minimized_windows
.get_mut(idx)
.unwrap()
.mapped_mut()
.unwrap();
let stack = window.stack_ref().unwrap();
let idx = stack.surfaces().position(|s| &s == surface); let idx = stack.surfaces().position(|s| &s == surface);
idx.and_then(|idx| stack.remove_idx(idx)) idx.and_then(|idx| stack.remove_idx(idx))
} else { } else {
@ -4796,12 +4791,9 @@ impl Shell {
{ {
let mut from = set.sticky_layer.element_geometry(&mapped).unwrap(); let mut from = set.sticky_layer.element_geometry(&mapped).unwrap();
let mut was_maximized = false; let mut was_maximized = false;
window = if mapped window = if let Some(stack) = mapped.stack_ref()
.stack_ref() && stack.len() > 1
.map(|stack| stack.len() > 1)
.unwrap_or(false)
{ {
let stack = mapped.stack_ref().unwrap();
let surface = stack.surfaces().find(|s| s == surface).unwrap(); let surface = stack.surfaces().find(|s| s == surface).unwrap();
stack.remove_window(&surface); stack.remove_window(&surface);
surface surface

View file

@ -713,8 +713,7 @@ impl Workspace {
} }
let mapped = self.element_for_surface(surface)?; let mapped = self.element_for_surface(surface)?;
let maybe_stack = mapped.stack_ref().filter(|s| s.len() > 1); if let Some(stack) = mapped.stack_ref()
if let Some(stack) = maybe_stack
&& stack.len() > 1 && stack.len() > 1
{ {
let idx = stack.surfaces().position(|s| &s == surface); let idx = stack.surfaces().position(|s| &s == surface);

View file

@ -314,8 +314,7 @@ impl CompositorHandler for State {
.then(|| state.element()) .then(|| state.element())
}); });
if let Some(window) = moved_window { if let Some(window) = moved_window {
if window.is_stack() { if let Some(stack) = window.stack_ref() {
let stack = window.stack_ref().unwrap();
if let Some(i) = stack.surfaces().position(|s| { if let Some(i) = stack.surfaces().position(|s| {
s.wl_surface() s.wl_surface()
.as_deref() .as_deref()