Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
0c5a6d565c
|
|||
|
4b30a1d260
|
+3
-2
@@ -30,9 +30,10 @@ type = "blank" # pure black (default, OLED-optimal)
|
||||
# ── Display settings ─────────────────────────────────────────────────────────
|
||||
|
||||
[display]
|
||||
monitor = 0 # monitor index (0 = primary). See: scr33ny monitors
|
||||
burn_shift = 2 # pixel shift for OLED burn-in prevention
|
||||
monitor = 0 # monitor index (0 = primary). See: scr33ny monitors
|
||||
burn_shift = 2 # pixel shift for OLED burn-in prevention
|
||||
shift_interval = 120 # seconds between shifts
|
||||
fps = 30 # max frames per second (blank/image auto-cap at 2)
|
||||
|
||||
# ── Idle daemon ───────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
+20
-4
@@ -1,10 +1,10 @@
|
||||
use std::num::NonZeroU32;
|
||||
use std::rc::Rc;
|
||||
use std::time::Instant;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use anyhow::Result;
|
||||
use winit::{
|
||||
event::{ElementState, Event, KeyEvent, WindowEvent},
|
||||
event::{ElementState, Event, KeyEvent, StartCause, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
keyboard::{KeyCode, PhysicalKey},
|
||||
window::{Fullscreen, WindowBuilder},
|
||||
@@ -55,8 +55,16 @@ pub fn run(config: Config, monitor_idx: usize) -> Result<()> {
|
||||
let mut screensaver: Box<dyn Screensaver> = build_screensaver(&config, font.clone())?;
|
||||
let mut widgets: Vec<Box<dyn Widget>> = build_widgets(&config, font)?;
|
||||
|
||||
// Adaptive FPS: blank/image need only 1–2 fps, animations up to config.display.fps
|
||||
let target_fps = match &config.screensaver {
|
||||
ScreensaverConfig::Blank | ScreensaverConfig::Image { .. } => {
|
||||
config.display.fps.min(2)
|
||||
}
|
||||
_ => config.display.fps,
|
||||
}.max(1);
|
||||
let frame_time = Duration::from_millis(1000 / target_fps as u64);
|
||||
|
||||
let event_loop = EventLoop::new()?;
|
||||
event_loop.set_control_flow(ControlFlow::Poll);
|
||||
|
||||
let monitors: Vec<_> = event_loop.available_monitors().collect();
|
||||
let monitor = monitors.get(monitor_idx).or_else(|| monitors.first()).cloned();
|
||||
@@ -131,7 +139,15 @@ pub fn run(config: Config, monitor_idx: usize) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
Event::AboutToWait => window.request_redraw(),
|
||||
// Timer expired or first run — schedule a redraw
|
||||
Event::NewEvents(StartCause::ResumeTimeReached { .. } | StartCause::Init) => {
|
||||
window.request_redraw();
|
||||
}
|
||||
|
||||
// All events processed — sleep until next frame
|
||||
Event::AboutToWait => {
|
||||
elwt.set_control_flow(ControlFlow::WaitUntil(Instant::now() + frame_time));
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
||||
+3
-1
@@ -147,11 +147,13 @@ pub struct DisplayConfig {
|
||||
/// Anti-burn-in pixel shift in pixels, applied every shift_interval seconds
|
||||
pub burn_shift: u32,
|
||||
pub shift_interval: u64,
|
||||
/// Target frames per second. Lower = less CPU. Blank/image need only 1–2.
|
||||
pub fps: u32,
|
||||
}
|
||||
|
||||
impl Default for DisplayConfig {
|
||||
fn default() -> Self {
|
||||
Self { monitor: 0, burn_shift: 2, shift_interval: 120 }
|
||||
Self { monitor: 0, burn_shift: 2, shift_interval: 120, fps: 30 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user