1
0
Fork 0
forked from wry/wry

container: switch to event-based damage

This commit is contained in:
atagen 2026-04-07 19:16:30 +10:00
parent 18a0c78657
commit 5657f45668

View file

@ -1,6 +1,5 @@
use { use {
crate::{ crate::{
async_engine::SpawnedFuture,
backend::ButtonState, backend::ButtonState,
cursor::KnownCursor, cursor::KnownCursor,
cursor_user::CursorUser, cursor_user::CursorUser,
@ -139,8 +138,6 @@ pub struct ContainerNode {
scroller: Scroller, scroller: Scroller,
toplevel_data: ToplevelData, toplevel_data: ToplevelData,
attention_requests: ThresholdCounter, attention_requests: ThresholdCounter,
pending_layout_damage: Cell<bool>,
layout_damage_timeout: Cell<Option<SpawnedFuture<()>>>,
pub layout_complete: Rc<LazyEventSource>, pub layout_complete: Rc<LazyEventSource>,
pub child_added: Rc<LazyEventSource>, pub child_added: Rc<LazyEventSource>,
pub child_removed: Rc<LazyEventSource>, pub child_removed: Rc<LazyEventSource>,
@ -261,8 +258,6 @@ impl ContainerNode {
weak, weak,
), ),
attention_requests: Default::default(), attention_requests: Default::default(),
pending_layout_damage: Cell::new(false),
layout_damage_timeout: Cell::new(None),
layout_complete: state.post_layout_event_sources.create_source(), layout_complete: state.post_layout_event_sources.create_source(),
child_added: state.lazy_event_sources.create_source(), child_added: state.lazy_event_sources.create_source(),
child_removed: state.lazy_event_sources.create_source(), child_removed: state.lazy_event_sources.create_source(),
@ -454,20 +449,12 @@ impl ContainerNode {
if !self.layout_scheduled.replace(true) { if !self.layout_scheduled.replace(true) {
self.state.pending_container_layout.push(self.clone()); self.state.pending_container_layout.push(self.clone());
} }
if self.toplevel_data.visible.get() {
self.pending_layout_damage.set(true);
}
} }
fn schedule_layout_immediate(self: &Rc<Self>) { fn schedule_layout_immediate(self: &Rc<Self>) {
self.schedule_layout(); self.schedule_layout();
self.flush_layout_damage(); if self.toplevel_data.visible.get() {
}
fn flush_layout_damage(&self) {
if self.pending_layout_damage.replace(false) {
self.damage(); self.damage();
self.layout_damage_timeout.take();
} }
} }
@ -502,13 +489,9 @@ impl ContainerNode {
self.schedule_render_titles(); self.schedule_render_titles();
self.schedule_compute_render_positions(); self.schedule_compute_render_positions();
self.layout_complete.trigger(); self.layout_complete.trigger();
if self.pending_layout_damage.get() { if self.toplevel_data.visible.get() && self.all_children_match_body() {
let slf = self.clone(); self.all_children_resized.trigger();
let timeout = self.state.eng.spawn("layout damage timeout", async move { self.damage();
slf.state.wheel.timeout(16).await.ok();
slf.flush_layout_damage();
});
self.layout_damage_timeout.set(Some(timeout));
} }
} }
@ -1859,10 +1842,12 @@ impl Node for ContainerNode {
if let Some(node) = cn.get(&child.node_id()) { if let Some(node) = cn.get(&child.node_id()) {
self.update_child_size(node, width, height); self.update_child_size(node, width, height);
} }
if self.pending_layout_damage.get() && self.all_children_match_body() { if self.all_children_match_body() {
self.all_children_resized.trigger(); self.all_children_resized.trigger();
if self.toplevel_data.visible.get() {
self.damage();
}
} }
self.flush_layout_damage();
} }
fn node_child_active_changed(self: Rc<Self>, child: &dyn Node, active: bool, depth: u32) { fn node_child_active_changed(self: Rc<Self>, child: &dyn Node, active: bool, depth: u32) {