daemon: Make X11 connection optional
Authored by
mfwolffe <wolffemf@dukes.jmu.edu>
- SHA
321cba345bbafdade6f6c82f48ada7f870eea335- Parents
-
c91da3b - Tree
f12acea
321cba3
321cba345bbafdade6f6c82f48ada7f870eea335c91da3b
f12acea| Status | File | + | - |
|---|---|---|---|
| M |
garbg/src/daemon/state.rs
|
13 | 3 |
garbg/src/daemon/state.rsmodified@@ -155,8 +155,8 @@ impl ActiveAnimation { | ||
| 155 | 155 | |
| 156 | 156 | /// Main daemon struct |
| 157 | 157 | pub struct Daemon { |
| 158 | - /// X11 connection | |
| 159 | - conn: Connection, | |
| 158 | + /// X11 connection (None if disconnected, will attempt reconnect) | |
| 159 | + conn: Option<Connection>, | |
| 160 | 160 | |
| 161 | 161 | /// Daemon state |
| 162 | 162 | state: DaemonState, |
@@ -206,13 +206,23 @@ impl Daemon { | ||
| 206 | 206 | let state = DaemonState::new(config); |
| 207 | 207 | |
| 208 | 208 | Ok(Self { |
| 209 | - conn, | |
| 209 | + conn: Some(conn), | |
| 210 | 210 | state, |
| 211 | 211 | animation: None, |
| 212 | 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 | 226 | /// Run the daemon event loop |
| 217 | 227 | pub async fn run(&mut self) -> Result<()> { |
| 218 | 228 | // Check for stale PID file and clean up |