Skip to content

Commit 5da9d4e

Browse files
committed
cocoa: Slightly better display hotplugging detection.
Fixes #12016.
1 parent 19f4209 commit 5da9d4e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/video/cocoa/SDL_cocoamodes.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,15 @@ static void Cocoa_DisplayReconfigurationCallback(CGDirectDisplayID displayid, CG
405405
}
406406

407407
if ((flags & kCGDisplayAddFlag) && (flags & kCGDisplayRemoveFlag)) {
408-
// both adding _and_ removing? Treat it as a remove exclusively. This can happen if a display is unmirroring because it's being disabled, etc.
409-
flags &= ~kCGDisplayAddFlag;
408+
// 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.
409+
// Mirrored things are always removed, since they don't represent a discrete display in this state.
410+
if (((flags & kCGDisplayMirrorFlag) == 0) && (CGDisplayPixelsWide(displayid) > 1)) {
411+
// Final state is connected
412+
flags &= ~kCGDisplayRemoveFlag;
413+
} else {
414+
// Final state is disconnected
415+
flags &= ~kCGDisplayAddFlag;
416+
}
410417
}
411418

412419
if (flags & kCGDisplayAddFlag) {

0 commit comments

Comments
 (0)