From eb11c29e6a478fc5d18d03396d8913de65588e6e Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Thu, 12 Aug 2021 18:17:17 +0200 Subject: [PATCH] fix some hot-reloading issues --- crates/eww/src/app.rs | 24 +++++++++++++++--------- crates/eww/src/opts.rs | 8 ++++---- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/crates/eww/src/app.rs b/crates/eww/src/app.rs index af34c15..579a0c5 100644 --- a/crates/eww/src/app.rs +++ b/crates/eww/src/app.rs @@ -1,7 +1,4 @@ -use crate::{ - config, daemon_response::DaemonResponseSender, display_backend, error_handling_ctx, eww_state, script_var_handler::*, - EwwPaths, -}; +use crate::{EwwPaths, config, daemon_response::DaemonResponseSender, display_backend, error_handling_ctx, eww_state::{self, EwwState}, script_var_handler::*}; use anyhow::*; use debug_stub_derive::*; use eww_shared_util::VarName; @@ -32,7 +29,7 @@ pub enum DaemonCommand { pos: Option, size: Option, anchor: Option, - monitor: Option, + screen: Option, should_toggle: bool, sender: DaemonResponseSender, }, @@ -133,7 +130,7 @@ impl App { let result = windows.iter().try_for_each(|w| self.open_window(w, None, None, None, None)); respond_with_error(sender, result)?; } - DaemonCommand::OpenWindow { window_name, pos, size, anchor, monitor, should_toggle, sender } => { + DaemonCommand::OpenWindow { window_name, pos, size, anchor, screen: monitor, should_toggle, sender } => { let result = if should_toggle && self.open_windows.contains_key(&window_name) { self.close_window(&window_name) } else { @@ -196,8 +193,10 @@ impl App { self.script_var_handler.stop_for_variable(unused_var.clone()); } - let window = - self.open_windows.remove(window_name).context(format!("No window with name '{}' is running.", window_name))?; + let window = self + .open_windows + .remove(window_name) + .with_context(|| format!("Tried to close window named '{}', but no such window was open", window_name))?; window.close(); self.eww_state.clear_window_state(window_name); @@ -250,7 +249,14 @@ impl App { self.script_var_handler.stop_all(); self.eww_config = config; - self.eww_state.clear_all_window_states(); + + let new_state = EwwState::from_default_vars(self.eww_config.generate_initial_state()?); + let old_state = std::mem::replace(&mut self.eww_state, new_state); + for (key, value) in old_state.get_variables() { + if self.eww_state.get_variables().contains_key(key) { + self.eww_state.update_variable(key.clone(), value.clone()) + } + } let windows = self.open_windows.clone(); for (window_name, _) in windows { diff --git a/crates/eww/src/opts.rs b/crates/eww/src/opts.rs index 01550a3..636d660 100644 --- a/crates/eww/src/opts.rs +++ b/crates/eww/src/opts.rs @@ -78,8 +78,8 @@ pub enum ActionWithServer { window_name: String, /// Monitor-index the window should open on - #[structopt(short, long)] - monitor: Option, + #[structopt(long)] + screen: Option, /// The position of the window, where it should open. #[structopt(short, long)] @@ -175,13 +175,13 @@ impl ActionWithServer { ActionWithServer::OpenMany { windows } => { return with_response_channel(|sender| app::DaemonCommand::OpenMany { windows, sender }); } - ActionWithServer::OpenWindow { window_name, pos, size, monitor, anchor, should_toggle } => { + ActionWithServer::OpenWindow { window_name, pos, size, screen, anchor, should_toggle } => { return with_response_channel(|sender| app::DaemonCommand::OpenWindow { window_name, pos, size, anchor, - monitor, + screen, should_toggle, sender, })