We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4518

Summary: Cocoa_GetDisplayUsableBounds returns incorrect bounds
Product: SDL Reporter: Tim McDaniel <tmcdaniel>
Component: videoAssignee: Alex Szpakowski <amaranth72>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.9   
Hardware: All   
OS: Mac OS X (All)   

Description Tim McDaniel 2019-02-20 23:06:16 UTC
Cocoa_GetDisplayUsableBounds is incorrectly calculating the usable bounds.  [NSScreen visibleFrame] returns a rect in global screen coords (same as [NSScreen frame], not coords relative to the origin of the particular screen.  Also the rect's origin needs to be converted to SDL's top-left convention instead of Cocoa's bottom-left.

This:
    const CGRect cgrect = CGDisplayBounds(cgdisplay);
    const NSRect frame = [screen visibleFrame];
    // !!! FIXME: I assume -[NSScreen visibleFrame] is relative to the origin of the screen in question and not the whole desktop.
    // !!! FIXME: The math vs CGDisplayBounds might be incorrect if that's not the case, though. Check this.
    rect->x = (int)(cgrect.origin.x + frame.origin.x);
    rect->y = (int)(cgrect.origin.y + frame.origin.y);
    rect->w = (int)frame.size.width;
    rect->h = (int)frame.size.height;

Should be:
    const NSRect frame = [screen visibleFrame];
    rect->x = (int)frame.origin.x;
    rect->y = (int)(CGDisplayPixelsHigh(kCGDirectMainDisplay) - frame.origin.y - frame.size.height);
    rect->w = (int)frame.size.width;
    rect->h = (int)frame.size.height;
Comment 1 Sam Lantinga 2019-03-17 01:51:29 UTC
Alex, can you take a look at this?
Comment 2 Alex Szpakowski 2019-06-12 22:58:28 UTC
I've applied and tested the change and it works well. Thanks! https://hg.libsdl.org/SDL/rev/e3213f8d6c16