From 29fa1587c3a4704a2bee0778099aca945d486e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?bbb651=20=F0=9F=87=AE=F0=9F=87=B1?= <53972231+bbb651@users.noreply.github.com> Date: Mon, 10 Feb 2025 14:43:46 +0200 Subject: [PATCH] Force recreating windows on config change (#1284) Fixes the regression from #1236 preventing hot reload. This can be made granular, e.g. for changes that don't effect all windows or css chnages not requiring a full window restart --- crates/eww/src/app.rs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/crates/eww/src/app.rs b/crates/eww/src/app.rs index 9494a9d..b7c37d5 100644 --- a/crates/eww/src/app.rs +++ b/crates/eww/src/app.rs @@ -217,7 +217,10 @@ impl App { .filter(|(win_id, ..)| win_id.is_empty() || win_id == id) .map(|(_, n, v)| (n.clone(), v.clone())) .collect(); - self.open_window(&WindowArguments::new_from_args(id.to_string(), config_name.clone(), window_args)?) + self.open_window( + &WindowArguments::new_from_args(id.to_string(), config_name.clone(), window_args)?, + false, + ) } }) .filter_map(Result::err); @@ -242,16 +245,19 @@ impl App { let result = if should_toggle && is_open { self.close_window(&instance_id) } else { - self.open_window(&WindowArguments { - instance_id, - window_name, - pos, - size, - monitor, - anchor, - duration, - args: args.unwrap_or_default().into_iter().collect(), - }) + self.open_window( + &WindowArguments { + instance_id, + window_name, + pos, + size, + monitor, + anchor, + duration, + args: args.unwrap_or_default().into_iter().collect(), + }, + false, + ) }; sender.respond_with_result(result)?; @@ -385,13 +391,13 @@ impl App { Ok(()) } - fn open_window(&mut self, window_args: &WindowArguments) -> Result<()> { + fn open_window(&mut self, window_args: &WindowArguments, dirty: bool) -> Result<()> { let instance_id = &window_args.instance_id; self.failed_windows.remove(instance_id); log::info!("Opening window {} as '{}'", window_args.window_name, instance_id); // if an instance of this is already running and arguments haven't change, only update duration - let reuse_window = if self.open_windows.contains_key(instance_id) { + let reuse_window = if !dirty && self.open_windows.contains_key(instance_id) { if self.instance_id_to_args.get(instance_id).is_some_and(|args| window_args.can_reuse_window_with_args(args)) { true } else { @@ -530,7 +536,7 @@ impl App { let window_arguments = self.instance_id_to_args.get(instance_id).with_context(|| { format!("Cannot reopen window, initial parameters were not saved correctly for {instance_id}") })?; - self.open_window(&window_arguments.clone())?; + self.open_window(&window_arguments.clone(), true)?; } Ok(()) }