@@ -38,6 +38,9 @@ pub struct Config { |
| 38 | 38 | // Monitor ordering: list of monitor names in desired left-to-right order |
| 39 | 39 | // If empty, monitors are sorted by X position (default) |
| 40 | 40 | pub monitor_order: Vec<String>, |
| 41 | + // Screen timeout/DPMS settings |
| 42 | + pub screen_timeout_enabled: bool, |
| 43 | + pub screen_timeout_seconds: u32, |
| 41 | 44 | // Compositor visual settings (picom) |
| 42 | 45 | // These are stored for reference and potential dynamic picom config generation |
| 43 | 46 | pub corner_radius: u32, |
@@ -345,6 +348,66 @@ wintypes: |
| 345 | 348 | Ok(()) |
| 346 | 349 | } |
| 347 | 350 | |
| 351 | + /// Apply screen timeout/DPMS settings using xset |
| 352 | + pub fn apply_screen_timeout(&self) { |
| 353 | + use std::process::Command; |
| 354 | + |
| 355 | + if self.screen_timeout_enabled { |
| 356 | + // Enable DPMS and set timeout |
| 357 | + let timeout = self.screen_timeout_seconds.to_string(); |
| 358 | + match Command::new("xset") |
| 359 | + .args(["dpms", &timeout, &timeout, &timeout]) |
| 360 | + .status() |
| 361 | + { |
| 362 | + Ok(status) if status.success() => { |
| 363 | + tracing::info!("Set DPMS timeout to {} seconds", self.screen_timeout_seconds); |
| 364 | + } |
| 365 | + Ok(_) => tracing::warn!("xset dpms command failed"), |
| 366 | + Err(e) => tracing::warn!("Failed to run xset: {}", e), |
| 367 | + } |
| 368 | + |
| 369 | + // Enable screen saver with same timeout |
| 370 | + match Command::new("xset") |
| 371 | + .args(["s", &timeout, &timeout]) |
| 372 | + .status() |
| 373 | + { |
| 374 | + Ok(status) if status.success() => { |
| 375 | + tracing::debug!("Set screen saver timeout to {} seconds", self.screen_timeout_seconds); |
| 376 | + } |
| 377 | + Ok(_) => tracing::warn!("xset s command failed"), |
| 378 | + Err(e) => tracing::warn!("Failed to run xset: {}", e), |
| 379 | + } |
| 380 | + |
| 381 | + // Make sure DPMS is enabled |
| 382 | + match Command::new("xset").args(["+dpms"]).status() { |
| 383 | + Ok(_) => {} |
| 384 | + Err(e) => tracing::warn!("Failed to enable DPMS: {}", e), |
| 385 | + } |
| 386 | + } else { |
| 387 | + // Disable DPMS and screen saver |
| 388 | + match Command::new("xset").args(["dpms", "0", "0", "0"]).status() { |
| 389 | + Ok(status) if status.success() => { |
| 390 | + tracing::info!("Disabled DPMS timeout"); |
| 391 | + } |
| 392 | + Ok(_) => tracing::warn!("xset dpms 0 command failed"), |
| 393 | + Err(e) => tracing::warn!("Failed to run xset: {}", e), |
| 394 | + } |
| 395 | + |
| 396 | + match Command::new("xset").args(["s", "off"]).status() { |
| 397 | + Ok(status) if status.success() => { |
| 398 | + tracing::debug!("Disabled screen saver"); |
| 399 | + } |
| 400 | + Ok(_) => tracing::warn!("xset s off command failed"), |
| 401 | + Err(e) => tracing::warn!("Failed to run xset: {}", e), |
| 402 | + } |
| 403 | + |
| 404 | + match Command::new("xset").args(["-dpms"]).status() { |
| 405 | + Ok(_) => {} |
| 406 | + Err(e) => tracing::warn!("Failed to disable DPMS: {}", e), |
| 407 | + } |
| 408 | + } |
| 409 | + } |
| 410 | + |
| 348 | 411 | /// Restart picom to apply new configuration. |
| 349 | 412 | /// Picom doesn't support config reload via signal, so we kill and restart it. |
| 350 | 413 | fn reload_picom() { |
@@ -415,6 +478,9 @@ impl Default for Config { |
| 415 | 478 | bar_enabled: false, |
| 416 | 479 | // Monitor order: empty = sort by X position |
| 417 | 480 | monitor_order: Vec::new(), |
| 481 | + // Screen timeout: enabled by default with 10 minute timeout |
| 482 | + screen_timeout_enabled: true, |
| 483 | + screen_timeout_seconds: 600, |
| 418 | 484 | // Compositor settings (picom) - matching picom.conf defaults |
| 419 | 485 | corner_radius: 12, |
| 420 | 486 | blur_enabled: true, |