gardesk/garchomp / fd1f785

Browse files

add startup retry for root pixmap loading

Authored by espadonne
SHA
fd1f785b6d1f984c09e0c90ce41dd299b13c3049
Parents
b3f2049
Tree
f4db49f

2 changed files

StatusFile+-
M garchomp/src/compositor/mod.rs 27 1
M garchomp/src/main.rs 3 0
garchomp/src/compositor/mod.rsmodified
@@ -66,6 +66,8 @@ pub struct Compositor {
6666
     root_pixmap: Option<u32>,
6767
     /// Monitor configuration from RandR.
6868
     pub monitors: Vec<MonitorInfo>,
69
+    /// Startup retry counter for root pixmap loading.
70
+    root_pixmap_retry_count: u32,
6971
 }
7072
 
7173
 impl Compositor {
@@ -153,6 +155,7 @@ impl Compositor {
153155
             lua_config,
154156
             root_pixmap,
155157
             monitors,
158
+            root_pixmap_retry_count: if root_pixmap.is_none() { 10 } else { 0 },
156159
         };
157160
 
158161
         // Get initial active window
@@ -613,10 +616,12 @@ impl Compositor {
613616
             && (event.atom == self.conn.atoms._XROOTPMAP_ID
614617
                 || event.atom == self.conn.atoms.ESETROOT_PMAP_ID)
615618
         {
619
+            tracing::debug!("Received PropertyNotify for root pixmap");
616620
             let new_pixmap = self.conn.get_root_pixmap();
617621
             if new_pixmap != self.root_pixmap {
618622
                 tracing::info!("Root pixmap changed: {:?} -> {:?}", self.root_pixmap, new_pixmap);
619623
                 self.root_pixmap = new_pixmap;
624
+                self.root_pixmap_retry_count = 0; // Stop startup retries
620625
                 // Tell renderer about new background
621626
                 self.renderer.set_root_pixmap(new_pixmap);
622627
                 self.needs_redraw = true;
@@ -1077,7 +1082,28 @@ impl Compositor {
10771082
 
10781083
     /// Check if a redraw is needed.
10791084
     pub fn needs_redraw(&self) -> bool {
1080
-        self.needs_redraw
1085
+        self.needs_redraw || self.root_pixmap_retry_count > 0
1086
+    }
1087
+
1088
+    /// Try to load the root pixmap if we haven't found one yet.
1089
+    /// Called during startup to handle race condition with garbg.
1090
+    pub fn try_load_root_pixmap(&mut self) {
1091
+        if self.root_pixmap_retry_count > 0 {
1092
+            self.root_pixmap_retry_count -= 1;
1093
+            let new_pixmap = self.conn.get_root_pixmap();
1094
+            if new_pixmap.is_some() && new_pixmap != self.root_pixmap {
1095
+                tracing::info!(
1096
+                    "Root pixmap found on startup retry: {:?} (retries left: {})",
1097
+                    new_pixmap, self.root_pixmap_retry_count
1098
+                );
1099
+                self.root_pixmap = new_pixmap;
1100
+                self.renderer.set_root_pixmap(new_pixmap);
1101
+                self.root_pixmap_retry_count = 0; // Success, stop retrying
1102
+                self.needs_redraw = true;
1103
+            } else if self.root_pixmap_retry_count == 0 {
1104
+                tracing::debug!("Root pixmap startup retry exhausted, pixmap={:?}", self.root_pixmap);
1105
+            }
1106
+        }
10811107
     }
10821108
 
10831109
     /// Resize the renderer surface.
garchomp/src/main.rsmodified
@@ -143,6 +143,9 @@ async fn main() -> Result<()> {
143143
             }
144144
         }
145145
 
146
+        // Try to load root pixmap on startup if not found initially
147
+        compositor.try_load_root_pixmap();
148
+
146149
         // Render if needed
147150
         if compositor.needs_redraw() {
148151
             if let Err(e) = compositor.render() {