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 {
return match tree.get(&id).unwrap().data() {
Data::Mapped { mapped, .. } => {
if mapped.is_stack() {
mapped.stack_ref().unwrap().focus_stack();
if let Some(stack) = mapped.stack_ref() {
stack.focus_stack();
}
FocusResult::Some(mapped.clone().into())
}
@ -1986,11 +1986,11 @@ impl TilingLayout {
}))
}
Data::Mapped { mapped, .. } => {
if mapped.is_stack()
if let Some(stack) = mapped.stack_ref()
&& desc.stack_window.is_none()
&& replacement_id == &desc.node
{
mapped.stack_ref().unwrap().focus_stack();
stack.focus_stack();
}
FocusResult::Some(KeyboardFocusTarget::Element(mapped.clone()))
}
@ -2062,7 +2062,7 @@ impl TilingLayout {
});
}
Data::Mapped { mapped, .. } => {
if mapped.is_stack()
if let Some(stack) = mapped.stack_ref()
&& swap_desc
.as_ref()
.map(|desc| {
@ -2071,7 +2071,7 @@ impl TilingLayout {
})
.unwrap_or(false)
{
mapped.stack_ref().unwrap().focus_stack();
stack.focus_stack();
}
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();
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)
{
focused.stack_ref().unwrap().add_window(window, None, None);
stack.add_window(window, None, None);
if was_activated {
workspace_state.add_workspace_state(&workspace_handle, WState::Urgent);
}
@ -2985,8 +2987,8 @@ impl Shell {
.map(|idx| (idx, m.clone()))
});
let surface = if let Some((idx, mapped)) = sticky_res {
if mapped.is_stack() {
mapped.stack_ref().unwrap().remove_idx(idx)
if let Some(stack) = mapped.stack_ref() {
stack.remove_idx(idx)
} else {
set.sticky_layer.unmap(&mapped, None);
Some(mapped.active_window())
@ -2996,20 +2998,13 @@ impl Shell {
.iter()
.position(|w| w.windows().any(|s| &s == surface))
{
if set
if let Some(stack) = set
.minimized_windows
.get(idx)
.get_mut(idx)
.unwrap()
.mapped()
.is_some_and(CosmicMapped::is_stack)
.mapped_mut()
.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);
idx.and_then(|idx| stack.remove_idx(idx))
} else {
@ -4796,12 +4791,9 @@ impl Shell {
{
let mut from = set.sticky_layer.element_geometry(&mapped).unwrap();
let mut was_maximized = false;
window = if mapped
.stack_ref()
.map(|stack| stack.len() > 1)
.unwrap_or(false)
window = if let Some(stack) = mapped.stack_ref()
&& stack.len() > 1
{
let stack = mapped.stack_ref().unwrap();
let surface = stack.surfaces().find(|s| s == surface).unwrap();
stack.remove_window(&surface);
surface

View file

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

View file

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