From 783f445c57da5100fe251d520eea33c60bad7964 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 3 Mar 2021 19:58:46 -0800 Subject: [PATCH] allow changing status_update_interval dynamically We were using the value that was active when the window was created, and never updating it. This commit sweeps the interval check into the existing periodic window maintenance routine. refs: https://github.com/wez/wezterm/issues/500 --- wezterm-gui/src/termwindow/mod.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 5eb7d5f47..e3f9fefde 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -138,6 +138,7 @@ pub struct TermWindow { RefCell>>>>>, last_blink_paint: Instant, + last_status_call: Instant, palette: Option, } @@ -269,6 +270,7 @@ impl WindowCallbacks for TermWindow { current_highlight: self.current_highlight.clone(), shape_cache: RefCell::new(LruCache::new(65536)), last_blink_paint: Instant::now(), + last_status_call: Instant::now(), }); prior_window.close(); @@ -482,6 +484,7 @@ impl TermWindow { current_highlight: None, shape_cache: RefCell::new(LruCache::new(65536)), last_blink_paint: Instant::now(), + last_status_call: Instant::now(), }), )?; @@ -552,19 +555,6 @@ impl TermWindow { }) .detach(); } - - let interval = configuration().status_update_interval; - let interval = std::time::Duration::from_millis(interval); - Connection::get() - .unwrap() - .schedule_timer(interval, move || { - window.apply(move |myself, window| { - if let Some(myself) = myself.downcast_mut::() { - myself.emit_status_event(window)?; - } - Ok(()) - }); - }); } fn emit_status_event(&mut self, _window: &dyn WindowOps) -> anyhow::Result<()> { @@ -615,6 +605,14 @@ impl TermWindow { return Ok(()); } + let now = Instant::now(); + if now.duration_since(self.last_status_call) + > Duration::from_millis(self.config.status_update_interval) + { + self.last_status_call = now; + self.schedule_status_update(); + } + for pos in panes { // If blinking is permitted, and the cursor shape is set // to a blinking variant, and it's been longer than the @@ -629,7 +627,6 @@ impl TermWindow { .default_cursor_style .effective_shape(pos.pane.get_cursor_position().shape); if shape.is_blinking() { - let now = Instant::now(); if now.duration_since(self.last_blink_paint) > Duration::from_millis(self.config.cursor_blink_rate) {