From 71edff74664c48da87e8da4cd1227be655f5b01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?W=C3=B6lfchen?= <115360611+W-lfchen@users.noreply.github.com> Date: Tue, 3 Sep 2024 14:40:05 +0200 Subject: [PATCH] fix: first attempt at fixing scopes for widgets with children --- crates/eww/src/state/scope_graph.rs | 3 +++ crates/eww/src/widgets/build_widget.rs | 14 ++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/eww/src/state/scope_graph.rs b/crates/eww/src/state/scope_graph.rs index 3af08faa..66ffb523 100644 --- a/crates/eww/src/state/scope_graph.rs +++ b/crates/eww/src/state/scope_graph.rs @@ -220,6 +220,9 @@ impl ScopeGraph { let listener = Rc::new(listener); for required_var in &listener.needed_variables { scope.listeners.entry(required_var.clone()).or_default().push(listener.clone()); + // debug print: if this number grows indefinetly, something is wrong, otherwise this shows that there is activity + // TODO: remove + log::info!("{:?} listeners for {required_var}", scope.listeners.get(&required_var.clone()).map(|x| x.len())); } let required_variables = self.lookup_variables_in_scope(scope_index, &listener.needed_variables)?; diff --git a/crates/eww/src/widgets/build_widget.rs b/crates/eww/src/widgets/build_widget.rs index 23e76ee7..5adf6600 100644 --- a/crates/eww/src/widgets/build_widget.rs +++ b/crates/eww/src/widgets/build_widget.rs @@ -288,6 +288,9 @@ fn build_children_special_widget( gtk_container: >k::Container, custom_widget_invocation: Rc, ) -> Result<()> { + // open a new scope for the children + // TODO this might be unnecessary, evaluate whether we can just use the calling_scope + let scope = tree.register_new_scope("children".into(), Some(calling_scope), calling_scope, HashMap::new())?; if let Some(nth) = widget_use.nth_expr { // TODORW this might not be necessary, if I can keep a copy of the widget I can destroy it directly, no need to go through the container. // This should be a custom gtk::Bin subclass,.. @@ -306,13 +309,8 @@ fn build_children_special_widget( .children .get(nth_value as usize) .with_context(|| format!("No child at index {}", nth_value))?; - let new_child_widget = build_gtk_widget( - tree, - widget_defs.clone(), - custom_widget_invocation.scope, - nth_child_widget_use.clone(), - None, - )?; + let new_child_widget = + build_gtk_widget(tree, widget_defs.clone(), scope, nth_child_widget_use.clone(), None)?; child_container.children().iter().for_each(|f| child_container.remove(f)); child_container.set_child(Some(&new_child_widget)); new_child_widget.show(); @@ -323,7 +321,7 @@ fn build_children_special_widget( )?; } else { for child in &custom_widget_invocation.children { - let child_widget = build_gtk_widget(tree, widget_defs.clone(), custom_widget_invocation.scope, child.clone(), None)?; + let child_widget = build_gtk_widget(tree, widget_defs.clone(), scope, child.clone(), None)?; gtk_container.add(&child_widget); } }