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 - Cocoa_GetDisplayUsableBounds returns incorrect bounds
Summary: Cocoa_GetDisplayUsableBounds returns incorrect bounds
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.9
Hardware: All Mac OS X (All)
: P2 normal
Assignee: Alex Szpakowski
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-20 23:06 UTC by Tim McDaniel
Modified: 2019-06-12 22:58 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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