@@ -118,18 +118,35 @@ impl Connection { |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | pub fn become_wm(&self) -> Result<(), Error> { |
| 121 | | - let change = ChangeWindowAttributesAux::new().event_mask( |
| 122 | | - EventMask::SUBSTRUCTURE_REDIRECT |
| 123 | | - | EventMask::SUBSTRUCTURE_NOTIFY |
| 124 | | - | EventMask::STRUCTURE_NOTIFY |
| 125 | | - | EventMask::PROPERTY_CHANGE, |
| 126 | | - ); |
| 121 | + // Set root window background to black and subscribe to events |
| 122 | + // The background ensures old window pixels are cleared when windows close |
| 123 | + let change = ChangeWindowAttributesAux::new() |
| 124 | + .event_mask( |
| 125 | + EventMask::SUBSTRUCTURE_REDIRECT |
| 126 | + | EventMask::SUBSTRUCTURE_NOTIFY |
| 127 | + | EventMask::STRUCTURE_NOTIFY |
| 128 | + | EventMask::PROPERTY_CHANGE, |
| 129 | + ) |
| 130 | + .background_pixel(self.screen().black_pixel); |
| 127 | 131 | |
| 128 | 132 | let result = self |
| 129 | 133 | .conn |
| 130 | 134 | .change_window_attributes(self.root, &change)? |
| 131 | 135 | .check(); |
| 132 | 136 | |
| 137 | + // Clear the root window to apply the background |
| 138 | + if result.is_ok() { |
| 139 | + self.conn.clear_area( |
| 140 | + false, |
| 141 | + self.root, |
| 142 | + 0, |
| 143 | + 0, |
| 144 | + self.screen_width, |
| 145 | + self.screen_height, |
| 146 | + )?; |
| 147 | + self.conn.flush()?; |
| 148 | + } |
| 149 | + |
| 133 | 150 | match result { |
| 134 | 151 | Ok(_) => { |
| 135 | 152 | tracing::info!("Successfully became window manager"); |
@@ -260,6 +277,12 @@ impl Connection { |
| 260 | 277 | Ok(()) |
| 261 | 278 | } |
| 262 | 279 | |
| 280 | + /// Clear an area of the root window (fills with background color). |
| 281 | + pub fn clear_root_area(&self, x: i16, y: i16, width: u16, height: u16) -> Result<(), Error> { |
| 282 | + self.conn.clear_area(false, self.root, x, y, width, height)?; |
| 283 | + Ok(()) |
| 284 | + } |
| 285 | + |
| 263 | 286 | /// Configure a window's geometry. |
| 264 | 287 | pub fn configure_window( |
| 265 | 288 | &self, |