@@ -66,6 +66,8 @@ pub struct Compositor { |
| 66 | 66 | root_pixmap: Option<u32>, |
| 67 | 67 | /// Monitor configuration from RandR. |
| 68 | 68 | pub monitors: Vec<MonitorInfo>, |
| 69 | + /// Startup retry counter for root pixmap loading. |
| 70 | + root_pixmap_retry_count: u32, |
| 69 | 71 | } |
| 70 | 72 | |
| 71 | 73 | impl Compositor { |
@@ -153,6 +155,7 @@ impl Compositor { |
| 153 | 155 | lua_config, |
| 154 | 156 | root_pixmap, |
| 155 | 157 | monitors, |
| 158 | + root_pixmap_retry_count: if root_pixmap.is_none() { 10 } else { 0 }, |
| 156 | 159 | }; |
| 157 | 160 | |
| 158 | 161 | // Get initial active window |
@@ -613,10 +616,12 @@ impl Compositor { |
| 613 | 616 | && (event.atom == self.conn.atoms._XROOTPMAP_ID |
| 614 | 617 | || event.atom == self.conn.atoms.ESETROOT_PMAP_ID) |
| 615 | 618 | { |
| 619 | + tracing::debug!("Received PropertyNotify for root pixmap"); |
| 616 | 620 | let new_pixmap = self.conn.get_root_pixmap(); |
| 617 | 621 | if new_pixmap != self.root_pixmap { |
| 618 | 622 | tracing::info!("Root pixmap changed: {:?} -> {:?}", self.root_pixmap, new_pixmap); |
| 619 | 623 | self.root_pixmap = new_pixmap; |
| 624 | + self.root_pixmap_retry_count = 0; // Stop startup retries |
| 620 | 625 | // Tell renderer about new background |
| 621 | 626 | self.renderer.set_root_pixmap(new_pixmap); |
| 622 | 627 | self.needs_redraw = true; |
@@ -1077,7 +1082,28 @@ impl Compositor { |
| 1077 | 1082 | |
| 1078 | 1083 | /// Check if a redraw is needed. |
| 1079 | 1084 | 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 | + } |
| 1081 | 1107 | } |
| 1082 | 1108 | |
| 1083 | 1109 | /// Resize the renderer surface. |