Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/ratty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ width = 960
height = 620
opacity = 0.8
# scale_factor = 1.0
# 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
Expand Down
19 changes: 19 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ pub struct WindowConfig {
pub scale_factor: Option<f32>,
/// 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 {
Expand All @@ -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)]
Expand Down
22 changes: 16 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down
Loading