cocoa: Slightly better display hotplugging detection.

Fixes #12016.
This commit is contained in:
Ryan C. Gordon
2025-01-18 17:01:46 -05:00
parent 19f42094bb
commit 5da9d4ecc2

View File

@@ -405,8 +405,15 @@ static void Cocoa_DisplayReconfigurationCallback(CGDirectDisplayID displayid, CG
}
if ((flags & kCGDisplayAddFlag) && (flags & kCGDisplayRemoveFlag)) {
// both adding _and_ removing? Treat it as a remove exclusively. This can happen if a display is unmirroring because it's being disabled, etc.
flags &= ~kCGDisplayAddFlag;
// sometimes you get a removed device that gets Add and Remove flags at the same time but the display dimensions are 0x0 or 1x1, hence the `> 1` test.
// Mirrored things are always removed, since they don't represent a discrete display in this state.
if (((flags & kCGDisplayMirrorFlag) == 0) && (CGDisplayPixelsWide(displayid) > 1)) {
// Final state is connected
flags &= ~kCGDisplayRemoveFlag;
} else {
// Final state is disconnected
flags &= ~kCGDisplayAddFlag;
}
}
if (flags & kCGDisplayAddFlag) {