@@ -244,16 +244,48 @@ impl App { |
| 244 | 244 | .map(|m| (m.name.as_str(), m)) |
| 245 | 245 | .collect(); |
| 246 | 246 | |
| 247 | + // Check if the profile's monitor set matches the current monitors |
| 248 | + let current_monitors: Vec<&str> = view.monitors().iter().map(|s| s.info.name.as_str()).collect(); |
| 249 | + let profile_monitors: Vec<&str> = profile.monitors.iter().map(|m| m.name.as_str()).collect(); |
| 250 | + |
| 251 | + let monitors_match = current_monitors.len() == profile_monitors.len() |
| 252 | + && current_monitors.iter().all(|m| profile_monitors.contains(m)); |
| 253 | + |
| 254 | + if !monitors_match { |
| 255 | + tracing::warn!( |
| 256 | + "profile monitors {:?} don't match current monitors {:?}, skipping position loading", |
| 257 | + profile_monitors, |
| 258 | + current_monitors |
| 259 | + ); |
| 260 | + // Still set primary if specified |
| 261 | + if let Some(ref primary) = profile.primary { |
| 262 | + view.set_primary(primary); |
| 263 | + } |
| 264 | + view.recalculate_layout(); |
| 265 | + return; |
| 266 | + } |
| 267 | + |
| 247 | 268 | // Update monitor positions from profile |
| 248 | 269 | for state in view.monitors_mut() { |
| 249 | 270 | if let Some(config) = config_map.get(state.info.name.as_str()) { |
| 250 | | - state.real_position = gartk_core::Point::new(config.x, config.y); |
| 251 | | - tracing::debug!( |
| 252 | | - "loaded {} at ({}, {})", |
| 253 | | - state.info.name, |
| 254 | | - config.x, |
| 255 | | - config.y |
| 256 | | - ); |
| 271 | + // Sanity check: don't apply positions that are clearly wrong |
| 272 | + // (negative positions or positions way outside screen bounds) |
| 273 | + if config.x >= 0 && config.y >= 0 && config.x < 10000 && config.y < 10000 { |
| 274 | + state.real_position = gartk_core::Point::new(config.x, config.y); |
| 275 | + tracing::debug!( |
| 276 | + "loaded {} at ({}, {})", |
| 277 | + state.info.name, |
| 278 | + config.x, |
| 279 | + config.y |
| 280 | + ); |
| 281 | + } else { |
| 282 | + tracing::warn!( |
| 283 | + "ignoring invalid position ({}, {}) for {}", |
| 284 | + config.x, |
| 285 | + config.y, |
| 286 | + state.info.name |
| 287 | + ); |
| 288 | + } |
| 257 | 289 | } |
| 258 | 290 | } |
| 259 | 291 | |