Explain runtime invariants and avoid redundant unwraps
This commit is contained in:
1 parent
34f2f07301
commit
1b51ba83b4
116 files changed
+1643
-515
No files matched your search
@@ -200,9 +200,9 @@ impl Ferese {
|
||||
let swipe = self
|
||||
.viewports
|
||||
.get_mut(&workspace)
|
||||
.unwrap()
|
||||
.expect("an active workspace gesture retains its viewport state")
|
||||
.end_gesture(None)
|
||||
.unwrap();
|
||||
.expect("an active workspace gesture retains its viewport state");
|
||||
self.presentation_dependencies
|
||||
.restore_viewport(swipe.workspace, swipe.dependencies);
|
||||
self.release_presentation_dependencies();
|
||||
@@ -360,10 +360,12 @@ impl Ferese {
|
||||
}
|
||||
}
|
||||
}
|
||||
let expired = self
|
||||
.windows
|
||||
.resizing()
|
||||
.any(|id| self.windows.transaction(id).unwrap().expired(now));
|
||||
let expired = self.windows.resizing().any(|id| {
|
||||
self.windows
|
||||
.transaction(id)
|
||||
.expect("the resize candidate retains its active presentation transaction")
|
||||
.expired(now)
|
||||
});
|
||||
self.windows.expire_transactions(now);
|
||||
if expired {
|
||||
self.release_presentation_dependencies();
|
||||
|
||||
@@ -30,7 +30,9 @@ impl Ferese {
|
||||
let Some(data) = states.data_map.get::<XdgToplevelSurfaceData>() else {
|
||||
return (true, None);
|
||||
};
|
||||
let data = data.lock().unwrap();
|
||||
let data = data
|
||||
.lock()
|
||||
.expect("window metadata must remain consistent during privacy checks");
|
||||
let rule = crate::window_rules::resolve(
|
||||
&self.window_rules,
|
||||
data.app_id.as_deref(),
|
||||
|
||||
@@ -156,7 +156,10 @@ impl Ferese {
|
||||
self.windows.update(window, |w| w.maximized = false);
|
||||
}
|
||||
if self.workspaces.placement(window) == Some(WindowPlacement::Tiled) {
|
||||
let workspace_id = self.workspaces.workspace_for_window(window).unwrap();
|
||||
let workspace_id = self
|
||||
.workspaces
|
||||
.workspace_for_window(window)
|
||||
.expect("a tiled window belongs to a workspace");
|
||||
if let Some(workspace) = self.workspaces.workspace_mut(workspace_id)
|
||||
&& let WorkspaceLayout::Scrolling(layout) = &mut workspace.layout
|
||||
{
|
||||
|
||||
@@ -657,7 +657,11 @@ impl Ferese {
|
||||
self.resize_metrics.begin(
|
||||
id,
|
||||
self.workspaces.workspace_for_window(id),
|
||||
&self.windows.record(id).unwrap().app_id,
|
||||
&self
|
||||
.windows
|
||||
.record(id)
|
||||
.expect("the selected window has a registered lifecycle record")
|
||||
.app_id,
|
||||
now,
|
||||
);
|
||||
self.windows.set_transaction(
|
||||
|
||||
@@ -57,8 +57,13 @@ impl Ferese {
|
||||
let Some(mut presentation) = self.current_window_presentation(id) else {
|
||||
return;
|
||||
};
|
||||
let record = self.windows.record(id).unwrap();
|
||||
let geometry = record.geometry.unwrap();
|
||||
let record = self
|
||||
.windows
|
||||
.record(id)
|
||||
.expect("the selected window has a registered lifecycle record");
|
||||
let geometry = record
|
||||
.geometry
|
||||
.expect("presented windows retain their resolved geometry");
|
||||
let decorations = geometry.decorations.clamp(0.0, 1.0);
|
||||
let handoff_size = (!presentation.scale_content).then(|| {
|
||||
presentation
|
||||
|
||||
@@ -112,7 +112,7 @@ impl Ferese {
|
||||
if let Some(workspace) = self.focus_swipe().map(|swipe| swipe.workspace) {
|
||||
self.viewports
|
||||
.get_mut(&workspace)
|
||||
.unwrap()
|
||||
.expect("an active workspace gesture retains its viewport state")
|
||||
.update_gesture(progress);
|
||||
}
|
||||
|
||||
@@ -145,9 +145,9 @@ impl Ferese {
|
||||
let swipe = self
|
||||
.viewports
|
||||
.get_mut(&workspace)
|
||||
.unwrap()
|
||||
.expect("an active workspace gesture retains its viewport state")
|
||||
.end_gesture(velocity)
|
||||
.unwrap();
|
||||
.expect("an active workspace gesture retains its viewport state");
|
||||
self.presentation_dependencies
|
||||
.restore_viewport(workspace, swipe.dependencies.clone());
|
||||
let neighbor = self.output_bounds().and_then(|bounds| {
|
||||
@@ -653,7 +653,10 @@ impl Ferese {
|
||||
{
|
||||
slide.release_with_velocity(true, self.swipe.release_velocity / self.animation_speed);
|
||||
self.last_animation_tick = Instant::now();
|
||||
self.workspace_slides.insert(owner, previous_slide.unwrap());
|
||||
self.workspace_slides.insert(
|
||||
owner,
|
||||
previous_slide.expect("the reversal branch requires an existing workspace slide"),
|
||||
);
|
||||
return;
|
||||
}
|
||||
let slide_direction = slide_direction.or_else(|| {
|
||||
|
||||
@@ -119,7 +119,11 @@ fn tree_reflow_groups(
|
||||
groups.insert(*id, group);
|
||||
let mut frontier = vec![*id];
|
||||
while let Some(id) = frontier.pop() {
|
||||
let bounds = moving.iter().find(|(window, _)| *window == id).unwrap().1;
|
||||
let bounds = moving
|
||||
.iter()
|
||||
.find(|(window, _)| *window == id)
|
||||
.expect("the dependency frontier contains only moving window IDs")
|
||||
.1;
|
||||
for (other, candidate) in &moving {
|
||||
if !groups.contains_key(other)
|
||||
&& bounds[0].max(candidate[0]) + 0.001 < bounds[2].min(candidate[2])
|
||||
@@ -448,7 +452,10 @@ impl Ferese {
|
||||
if self.workspaces.workspace_for_window(*slow) != Some(workspace_id) {
|
||||
continue;
|
||||
}
|
||||
let transaction = *self.windows.transaction(slow).unwrap();
|
||||
let transaction = *self
|
||||
.windows
|
||||
.transaction(slow)
|
||||
.expect("the resize candidate retains its active presentation transaction");
|
||||
let commit = ClientCommit {
|
||||
window: *slow,
|
||||
serial: transaction.serial(),
|
||||
@@ -504,7 +511,14 @@ impl Ferese {
|
||||
self.workspaces.workspace_for_window(**id) == Some(workspace.id)
|
||||
&& layout.contains(**id)
|
||||
})
|
||||
.map(|id| (*id, *self.windows.transaction(id).unwrap()))
|
||||
.map(|id| {
|
||||
(
|
||||
*id,
|
||||
*self.windows.transaction(id).expect(
|
||||
"the resize candidate retains its active presentation transaction",
|
||||
),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
previous_viewport.remove(&workspace.id).unwrap_or_default(),
|
||||
);
|
||||
|
||||
@@ -101,7 +101,12 @@ impl Ferese {
|
||||
layout: !plan.affected_outputs.is_empty(),
|
||||
focus: plan.focus_changed,
|
||||
shell: !plan.affected_outputs.is_empty(),
|
||||
outputs: self.desktop_transition.as_ref().unwrap().redraw.clone(),
|
||||
outputs: self
|
||||
.desktop_transition
|
||||
.as_ref()
|
||||
.expect("desktop transition must be started before publication or retirement")
|
||||
.redraw
|
||||
.clone(),
|
||||
};
|
||||
let floats = self
|
||||
.windows
|
||||
@@ -213,7 +218,10 @@ impl Ferese {
|
||||
}
|
||||
|
||||
pub(crate) fn finish_desktop_transition(&mut self, mut changes: DesktopChanges) {
|
||||
self.desktop_transition.as_mut().unwrap().publishing = true;
|
||||
self.desktop_transition
|
||||
.as_mut()
|
||||
.expect("desktop transition must be started before publication or retirement")
|
||||
.publishing = true;
|
||||
let activity_output = self.space.outputs().next().map(|output| output.name());
|
||||
if let Some(output) = activity_output
|
||||
&& (self.activities.store.attach_output(&output)
|
||||
@@ -230,7 +238,10 @@ impl Ferese {
|
||||
self.reconcile_layer_keyboard_focus();
|
||||
self.refresh_lock_outputs();
|
||||
self.refresh_idle_inhibition();
|
||||
let batch = self.desktop_transition.take().unwrap();
|
||||
let batch = self
|
||||
.desktop_transition
|
||||
.take()
|
||||
.expect("desktop transition must be started before publication or retirement");
|
||||
changes.outputs.extend(batch.redraw);
|
||||
// Animation/layout helpers may request snapshots, but only this point
|
||||
// can emit the complete topology generation.
|
||||
|
||||
@@ -236,7 +236,10 @@ impl WindowRegistry<Window> {
|
||||
|
||||
if let Some(surface) = surface {
|
||||
self.surface_ids.insert(surface.clone(), id);
|
||||
self.records.get_mut(&id).unwrap().surface = Some(surface.clone());
|
||||
self.records
|
||||
.get_mut(&id)
|
||||
.expect("the selected window has a registered lifecycle record")
|
||||
.surface = Some(surface.clone());
|
||||
self.refresh_metadata(&surface);
|
||||
}
|
||||
}
|
||||
@@ -245,14 +248,17 @@ impl WindowRegistry<Window> {
|
||||
let Some(id) = self.id_for_surface(surface) else {
|
||||
return false;
|
||||
};
|
||||
let record = self.records.get_mut(&id).unwrap();
|
||||
let record = self
|
||||
.records
|
||||
.get_mut(&id)
|
||||
.expect("the selected window has a registered lifecycle record");
|
||||
with_states(surface, |states| {
|
||||
let attributes = states
|
||||
.data_map
|
||||
.get::<XdgToplevelSurfaceData>()
|
||||
.unwrap()
|
||||
.expect("an XDG toplevel must retain its Smithay surface data")
|
||||
.lock()
|
||||
.unwrap();
|
||||
.expect("Smithay surface state must remain consistent across callbacks");
|
||||
let app_id = attributes.app_id.as_deref().unwrap_or_default();
|
||||
let title = attributes.title.as_deref().unwrap_or_default();
|
||||
let changed = record.app_id != app_id || record.title != title;
|
||||
|
||||
@@ -28,9 +28,9 @@ impl Ferese {
|
||||
let attributes = states
|
||||
.data_map
|
||||
.get::<XdgToplevelSurfaceData>()
|
||||
.unwrap()
|
||||
.expect("an XDG toplevel must retain its Smithay surface data")
|
||||
.lock()
|
||||
.unwrap();
|
||||
.expect("Smithay surface state must remain consistent across callbacks");
|
||||
(
|
||||
attributes.app_id.clone(),
|
||||
attributes.title.clone(),
|
||||
@@ -350,9 +350,9 @@ impl Ferese {
|
||||
let attributes = states
|
||||
.data_map
|
||||
.get::<XdgToplevelSurfaceData>()
|
||||
.unwrap()
|
||||
.expect("an XDG toplevel must retain its Smithay surface data")
|
||||
.lock()
|
||||
.unwrap();
|
||||
.expect("Smithay surface state must remain consistent across callbacks");
|
||||
(
|
||||
attributes.app_id.clone(),
|
||||
attributes.title.clone(),
|
||||
|
||||
Reference in new issue
Block a user