Skip to content

Commit

Permalink
cocoa: Slightly better display hotplugging detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jan 18, 2025
1 parent 19f4209 commit 5da9d4e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/video/cocoa/SDL_cocoamodes.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5da9d4e

Please sign in to comment.