From da2f9b4dc15212c73482e1a3eb465f2b6ee87817 Mon Sep 17 00:00:00 2001 From: carltenzler-ctrl Date: Wed, 15 Jul 2026 18:12:11 -0400 Subject: [PATCH 1/2] feat(config): add window update_mode option Expose the winit UpdateMode used while the window is focused via `[window] update_mode` and `[window] frame_interval_ms`. The default (`Continuous`) takes the same `WinitSettings::continuous()` path as before, so existing behavior is unchanged. `LowPower` restores 0.4.2's settings: reactive_low_power while focused, continuous while unfocused, so background PTY output is still not delayed. Co-Authored-By: Claude Opus 4.8 --- config/ratty.toml | 2 ++ src/config.rs | 19 +++++++++++++++++++ src/main.rs | 22 ++++++++++++++++------ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/config/ratty.toml b/config/ratty.toml index a624622..d77b255 100644 --- a/config/ratty.toml +++ b/config/ratty.toml @@ -3,6 +3,8 @@ width = 960 height = 620 opacity = 0.8 # scale_factor = 1.0 +# update_mode = "Continuous" # or "LowPower" to redraw reactively while focused +# frame_interval_ms = 33 # frame rate cap in "LowPower" mode [terminal] default_cols = 104 diff --git a/src/config.rs b/src/config.rs index 050cfc3..d50350d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -136,6 +136,11 @@ pub struct WindowConfig { pub scale_factor: Option, /// Window opacity from `0.0` to `1.0`. pub opacity: f32, + /// How the window schedules redraws while focused. + pub update_mode: UpdateModeConfig, + /// Minimum time between redraws while focused, in milliseconds. + /// Only applies when `update_mode` is `LowPower`. + pub frame_interval_ms: u64, } impl Default for WindowConfig { @@ -145,10 +150,24 @@ impl Default for WindowConfig { height: 620, scale_factor: None, opacity: 1.0, + update_mode: UpdateModeConfig::Continuous, + frame_interval_ms: 33, } } } +/// How the window schedules redraws while focused. +#[derive(Debug, Clone, Copy, Deserialize, Default)] +pub enum UpdateModeConfig { + /// Redraw continuously, regardless of input. + #[serde(rename = "Continuous")] + #[default] + Continuous, + /// Redraw in response to events, rate-limited to `frame_interval_ms`. + #[serde(rename = "LowPower")] + LowPower, +} + /// Terminal grid configuration. #[derive(Debug, Clone, Deserialize)] #[serde(default)] diff --git a/src/main.rs b/src/main.rs index 6800850..efc65b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,15 +5,16 @@ use bevy::prelude::*; use bevy::render::RenderPlugin; use bevy::render::settings::{WgpuSettings, WgpuSettingsPriority}; use bevy::window::{PrimaryWindow, WindowCreated, WindowResizeConstraints, WindowResolution}; -use bevy::winit::{WINIT_WINDOWS, WinitSettings}; +use bevy::winit::{UpdateMode, WINIT_WINDOWS, WinitSettings}; use clap::Parser; +use std::time::Duration; #[cfg(target_os = "windows")] use winit::platform::windows::{IconExtWindows, WindowExtWindows}; use winit::window::Icon; use ratty::cli::Cli; -use ratty::config::AppConfig; +use ratty::config::{AppConfig, UpdateModeConfig}; use ratty::paths::runtime_asset_root; use ratty::plugin::TerminalPlugin; use ratty::runtime::{RuntimeOptions, TerminalRuntime}; @@ -66,10 +67,19 @@ fn main() -> anyhow::Result<()> { .insert_resource(runtime) .insert_resource(terminal) .insert_non_send(AppWindowIcon { icon: window_icon }) - // Always update continuously, focused or not. Bevy's default switches - // unfocused windows to a reactive mode, which would delay background - // PTY output. - .insert_resource(WinitSettings::continuous()) + // Unfocused windows always update continuously. Bevy's default switches + // them to a reactive mode, which would delay background PTY output. + // While focused, `update_mode` picks between updating continuously and + // updating reactively at a capped frame rate to reduce idle CPU usage. + .insert_resource(match app_config.window.update_mode { + UpdateModeConfig::Continuous => WinitSettings::continuous(), + UpdateModeConfig::LowPower => WinitSettings { + focused_mode: UpdateMode::reactive_low_power(Duration::from_millis( + app_config.window.frame_interval_ms, + )), + unfocused_mode: UpdateMode::Continuous, + }, + }) .add_plugins( DefaultPlugins .set(WindowPlugin { From 05f27b90970b0656152400e500d04335d5e28c27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Fri, 17 Jul 2026 21:42:01 +0200 Subject: [PATCH 2/2] docs: improve comment --- config/ratty.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/ratty.toml b/config/ratty.toml index d77b255..58c9545 100644 --- a/config/ratty.toml +++ b/config/ratty.toml @@ -3,8 +3,8 @@ width = 960 height = 620 opacity = 0.8 # scale_factor = 1.0 -# update_mode = "Continuous" # or "LowPower" to redraw reactively while focused -# frame_interval_ms = 33 # frame rate cap in "LowPower" mode +# update_mode = "Continuous" # Use "LowPower" to redraw only after input or terminal output. +# frame_interval_ms = 33 # Minimum milliseconds between LowPower redraws. [terminal] default_cols = 104