@@ -167,6 +167,25 @@ impl WindowManager { |
| 167 | 167 | self.monitors[self.focused_monitor].geometry |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | + /// Get the work area for the focused monitor (accounting for struts and outer gaps). |
| 171 | + pub fn work_area(&self) -> Rect { |
| 172 | + let screen = self.screen_rect(); |
| 173 | + let gap_outer = self.config.gap_outer as i16; |
| 174 | + |
| 175 | + // Calculate struts for focused monitor |
| 176 | + let (strut_left, strut_right, strut_top, strut_bottom) = |
| 177 | + self.calculate_struts(self.focused_monitor); |
| 178 | + |
| 179 | + Rect::new( |
| 180 | + screen.x + gap_outer + strut_left as i16, |
| 181 | + screen.y + gap_outer + strut_top as i16, |
| 182 | + screen.width |
| 183 | + .saturating_sub(2 * gap_outer as u16 + strut_left as u16 + strut_right as u16), |
| 184 | + screen.height |
| 185 | + .saturating_sub(2 * gap_outer as u16 + strut_top as u16 + strut_bottom as u16), |
| 186 | + ) |
| 187 | + } |
| 188 | + |
| 170 | 189 | /// Get the rectangle for a specific workspace's monitor. |
| 171 | 190 | pub fn workspace_rect(&self, workspace_idx: usize) -> Rect { |
| 172 | 191 | self.monitor_for_workspace(workspace_idx) |
@@ -184,6 +203,27 @@ impl WindowManager { |
| 184 | 203 | self.monitors.iter().position(|m| m.active_workspace == workspace_idx) |
| 185 | 204 | } |
| 186 | 205 | |
| 206 | + /// Calculate struts (reserved space for panels/docks) for a monitor. |
| 207 | + fn calculate_struts(&self, _monitor_idx: usize) -> (u32, u32, u32, u32) { |
| 208 | + if self.config.bar_height > 0 { |
| 209 | + // Manual bar height overrides struts (assumes bar at top) |
| 210 | + (0, 0, self.config.bar_height, 0) |
| 211 | + } else { |
| 212 | + // Accumulate struts from dock windows |
| 213 | + let mut left: u32 = 0; |
| 214 | + let mut right: u32 = 0; |
| 215 | + let mut top: u32 = 0; |
| 216 | + let mut bottom: u32 = 0; |
| 217 | + for strut in self.dock_struts.values() { |
| 218 | + left = left.max(strut.left); |
| 219 | + right = right.max(strut.right); |
| 220 | + top = top.max(strut.top); |
| 221 | + bottom = bottom.max(strut.bottom); |
| 222 | + } |
| 223 | + (left, right, top, bottom) |
| 224 | + } |
| 225 | + } |
| 226 | + |
| 187 | 227 | /// Refresh monitors (called on RandR screen change). |
| 188 | 228 | pub fn refresh_monitors(&mut self) -> Result<()> { |
| 189 | 229 | tracing::info!("Refreshing monitor configuration"); |