macOS: Fix monitors connected via certain Thunderbolt hubs (#4207)

Instead of panicking, raise a warning and return `None` or similar.

Co-authored-by: RJ <rj@metabrew.com>
This commit is contained in:
Mads Marquart 2025-04-29 13:25:46 +02:00 committed by GitHub
parent 1800fa1670
commit aa83726c72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 9 deletions

View file

@ -1756,8 +1756,14 @@ impl WindowDelegate {
// Allow directly accessing the current monitor internally without unwrapping.
pub(crate) fn current_monitor_inner(&self) -> Option<MonitorHandle> {
let display_id = get_display_id(&*self.window().screen()?);
// Display ID just fetched from live NSScreen, should be fine to unwrap.
Some(MonitorHandle::new(display_id).expect("invalid display ID"))
if let Some(monitor) = MonitorHandle::new(display_id) {
Some(monitor)
} else {
// NOTE: Display ID was just fetched from live NSScreen, but can still result in `None`
// with certain Thunderbolt docked monitors.
warn!(display_id, "got screen with invalid display ID");
None
}
}
#[inline]