Skip to content

Commit

Permalink
fix: first attempt at fixing scopes for widgets with children
Browse files Browse the repository at this point in the history
  • Loading branch information
w-lfchen committed Sep 3, 2024
1 parent 8661abf commit 71edff7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 3 additions & 0 deletions crates/eww/src/state/scope_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
14 changes: 6 additions & 8 deletions crates/eww/src/widgets/build_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ fn build_children_special_widget(
gtk_container: &gtk::Container,
custom_widget_invocation: Rc<CustomWidgetInvocation>,
) -> 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,..
Expand All @@ -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();
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 71edff7

Please sign in to comment.