gardesk/garbg / 10354f7

Browse files

daemon: Add X11 reconnection helpers

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
10354f7c302b65ed975b39a256093509842ada49
Parents
321cba3
Tree
32ff18e

1 changed file

StatusFile+-
M garbg/src/daemon/state.rs 43 0
garbg/src/daemon/state.rsmodified
@@ -223,6 +223,49 @@ impl Daemon {
223
         self.conn.as_mut().ok_or_else(|| anyhow::anyhow!("X11 connection not available"))
223
         self.conn.as_mut().ok_or_else(|| anyhow::anyhow!("X11 connection not available"))
224
     }
224
     }
225
 
225
 
226
+    /// Attempt to establish/re-establish X11 connection
227
+    fn try_connect_x11(&mut self) -> bool {
228
+        match Connection::new() {
229
+            Ok(conn) => {
230
+                let (width, height) = conn.screen_dimensions();
231
+                tracing::info!("X11 connection established (screen: {}x{})", width, height);
232
+                self.conn = Some(conn);
233
+                true
234
+            }
235
+            Err(e) => {
236
+                tracing::debug!("X11 connection failed: {}", e);
237
+                false
238
+            }
239
+        }
240
+    }
241
+
242
+    /// Check if X11 connection is alive
243
+    fn x11_is_alive(&self) -> bool {
244
+        self.conn.as_ref().map(|c| c.is_alive()).unwrap_or(false)
245
+    }
246
+
247
+    /// Re-apply current wallpaper after X11 reconnection
248
+    fn reapply_wallpaper(&mut self) -> Result<()> {
249
+        // Stop any animation (it had the old connection's renderer)
250
+        self.animation = None;
251
+
252
+        // Re-apply from playlist if we have one
253
+        if let Some(ref playlist) = self.state.playlist {
254
+            if let Some(current) = playlist.current() {
255
+                let source = current.to_string();
256
+                let mode = playlist.mode;
257
+                return self.set_wallpaper(&source, mode);
258
+            }
259
+        }
260
+
261
+        // Otherwise try to re-apply default wallpaper
262
+        if !self.state.config.default.source.is_empty() {
263
+            return self.apply_default_wallpaper();
264
+        }
265
+
266
+        Ok(())
267
+    }
268
+
226
     /// Run the daemon event loop
269
     /// Run the daemon event loop
227
     pub async fn run(&mut self) -> Result<()> {
270
     pub async fn run(&mut self) -> Result<()> {
228
         // Check for stale PID file and clean up
271
         // Check for stale PID file and clean up