gardesk/gar / 11160b2

Browse files

Add configurable screen timeout via init.lua

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
11160b25757cd7da0b74feeb409bcc46c333b75c
Parents
2af2ced
Tree
a40c22d

4 changed files

StatusFile+-
M gar/src/config/lua.rs 13 0
M gar/src/config/mod.rs 66 0
M gar/src/core/mod.rs 3 0
M gar/src/x11/events.rs 3 0
gar/src/config/lua.rsmodified
@@ -506,6 +506,19 @@ impl LuaConfig {
506506
                         }
507507
                     }
508508
                 }
509
+                // Screen timeout settings
510
+                "screen_timeout_enabled" => {
511
+                    if let Value::Boolean(v) = value {
512
+                        state.config.screen_timeout_enabled = v;
513
+                        tracing::info!("Screen timeout enabled: {}", v);
514
+                    }
515
+                }
516
+                "screen_timeout" => {
517
+                    if let Value::Integer(v) = value {
518
+                        state.config.screen_timeout_seconds = v as u32;
519
+                        tracing::info!("Screen timeout set to {} seconds", v);
520
+                    }
521
+                }
509522
                 _ => {
510523
                     tracing::warn!("Unknown config key: {}", key);
511524
                 }
gar/src/config/mod.rsmodified
@@ -38,6 +38,9 @@ pub struct Config {
3838
     // Monitor ordering: list of monitor names in desired left-to-right order
3939
     // If empty, monitors are sorted by X position (default)
4040
     pub monitor_order: Vec<String>,
41
+    // Screen timeout/DPMS settings
42
+    pub screen_timeout_enabled: bool,
43
+    pub screen_timeout_seconds: u32,
4144
     // Compositor visual settings (picom)
4245
     // These are stored for reference and potential dynamic picom config generation
4346
     pub corner_radius: u32,
@@ -345,6 +348,66 @@ wintypes:
345348
         Ok(())
346349
     }
347350
 
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
+
348411
     /// Restart picom to apply new configuration.
349412
     /// Picom doesn't support config reload via signal, so we kill and restart it.
350413
     fn reload_picom() {
@@ -415,6 +478,9 @@ impl Default for Config {
415478
             bar_enabled: false,
416479
             // Monitor order: empty = sort by X position
417480
             monitor_order: Vec::new(),
481
+            // Screen timeout: enabled by default with 10 minute timeout
482
+            screen_timeout_enabled: true,
483
+            screen_timeout_seconds: 600,
418484
             // Compositor settings (picom) - matching picom.conf defaults
419485
             corner_radius: 12,
420486
             blur_enabled: true,
gar/src/core/mod.rsmodified
@@ -78,6 +78,9 @@ impl WindowManager {
7878
             tracing::warn!("Failed to generate picom config: {}", e);
7979
         }
8080
 
81
+        // Apply screen timeout/DPMS settings
82
+        config.apply_screen_timeout();
83
+
8184
         // Initialize IPC server (optional - graceful failure)
8285
         let ipc_server = match IpcServer::new() {
8386
             Ok(server) => Some(server),
gar/src/x11/events.rsmodified
@@ -2196,6 +2196,9 @@ impl WindowManager {
21962196
             tracing::warn!("Failed to regenerate picom config: {}", e);
21972197
         }
21982198
 
2199
+        // Apply screen timeout/DPMS settings
2200
+        self.config.apply_screen_timeout();
2201
+
21992202
         // Re-register keybinds
22002203
         self.setup_grabs()?;
22012204