gardesk/garbg / 321cba3

Browse files

daemon: Make X11 connection optional

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
321cba345bbafdade6f6c82f48ada7f870eea335
Parents
c91da3b
Tree
f12acea

1 changed file

StatusFile+-
M garbg/src/daemon/state.rs 13 3
garbg/src/daemon/state.rsmodified
@@ -155,8 +155,8 @@ impl ActiveAnimation {
155
 
155
 
156
 /// Main daemon struct
156
 /// Main daemon struct
157
 pub struct Daemon {
157
 pub struct Daemon {
158
-    /// X11 connection
158
+    /// X11 connection (None if disconnected, will attempt reconnect)
159
-    conn: Connection,
159
+    conn: Option<Connection>,
160
 
160
 
161
     /// Daemon state
161
     /// Daemon state
162
     state: DaemonState,
162
     state: DaemonState,
@@ -206,13 +206,23 @@ impl Daemon {
206
         let state = DaemonState::new(config);
206
         let state = DaemonState::new(config);
207
 
207
 
208
         Ok(Self {
208
         Ok(Self {
209
-            conn,
209
+            conn: Some(conn),
210
             state,
210
             state,
211
             animation: None,
211
             animation: None,
212
             cache,
212
             cache,
213
         })
213
         })
214
     }
214
     }
215
 
215
 
216
+    /// Get a reference to the X11 connection, or error if disconnected
217
+    fn conn(&self) -> Result<&Connection> {
218
+        self.conn.as_ref().ok_or_else(|| anyhow::anyhow!("X11 connection not available"))
219
+    }
220
+
221
+    /// Get a mutable reference to the X11 connection, or error if disconnected
222
+    fn conn_mut(&mut self) -> Result<&mut Connection> {
223
+        self.conn.as_mut().ok_or_else(|| anyhow::anyhow!("X11 connection not available"))
224
+    }
225
+
216
     /// Run the daemon event loop
226
     /// Run the daemon event loop
217
     pub async fn run(&mut self) -> Result<()> {
227
     pub async fn run(&mut self) -> Result<()> {
218
         // Check for stale PID file and clean up
228
         // Check for stale PID file and clean up