gardesk/gartray / d647280

Browse files

exit on X11 connection loss instead of spinning in error loop

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
d647280eaeff856f9b336f232ed5d2d618406366
Parents
234f417
Tree
95dd2a6

1 changed file

StatusFile+-
M gartray/src/daemon.rs 11 0
gartray/src/daemon.rsmodified
@@ -97,6 +97,8 @@ pub struct Daemon {
9797
     visibility: PanelVisibility,
9898
     /// Time when panel was last hidden (for debouncing toggle commands)
9999
     last_hide_time: Option<std::time::Instant>,
100
+    /// Consecutive panel event errors (for detecting dead X11 connection)
101
+    consecutive_errors: u32,
100102
 }
101103
 
102104
 impl Daemon {
@@ -129,6 +131,7 @@ impl Daemon {
129131
             running: true,
130132
             visibility,
131133
             last_hide_time: None,
134
+            consecutive_errors: 0,
132135
         })
133136
     }
134137
 
@@ -267,7 +270,15 @@ impl Daemon {
267270
         if let Some(ref mut panel) = self.panel {
268271
             let was_visible = panel.is_visible();
269272
             if let Err(e) = panel.process_events() {
273
+                self.consecutive_errors += 1;
274
+                if self.consecutive_errors >= 5 {
275
+                    warn!("X11 connection lost ({}+ errors), shutting down: {}", self.consecutive_errors, e);
276
+                    self.running = false;
277
+                    return Ok(());
278
+                }
270279
                 warn!("Panel event error: {}", e);
280
+            } else {
281
+                self.consecutive_errors = 0;
271282
             }
272283
             // Only update visibility if panel was closed by events (escape/click-outside)
273284
             let is_visible = panel.is_visible();