CGDisplayBounds() with stacked displays...

  • Hello all -

    I'm in the midst of adding support for multiple displays to my
    application and have come across something I can't get my head
    around.  If I open the System Preferences and move my secondary
    display either on top of or beneath my primary display in the
    Displays panel, CGDisplayBounds() always returns kCGNullDirectDisplay
    if I'm in the secondary display.  CGDisplayBounds() returns what I
    would expect for the secondary display when situated to either the
    left or right of the primary one however.  If the secondary display
    is significantly "vertically mis-aligned" with the primary one
    CGDisplayBounds() will only return the secondary display ID in a
    small portion of the device -- whichever portion is closest to the
    primary one.  Is this normal behavior?  I can't seem to find any
    documentation relating to the issue.  I don't think many people stack
    their displays nor have strange vertical offsets between displays,
    but I'd like to "do the right thing" in my application in any event.

    I don't know that it would make any difference, but this is in 10.4
    and using a 12 inch PowerBook and a 23 inch Cinema Display.  I've
    used both as primary / secondary and vice versa with the same
    results.  I don't have access to another multi-display setup
    unfortunately.

    Any insight would be most appreciated!

    Thanks!

    Mike
  • On 11/1/07, Mike McNamara <mike...> wrote:
    >
    > Hello all -
    >
    > I'm in the midst of adding support for multiple displays to my
    > application and have come across something I can't get my head
    > around.  If I open the System Preferences and move my secondary
    > display either on top of or beneath my primary display in the
    > Displays panel, CGDisplayBounds() always returns kCGNullDirectDisplay
    > if I'm in the secondary display.  CGDisplayBounds() returns what I
    > would expect for the secondary display when situated to either the
    > left or right of the primary one however.  If the secondary display
    > is significantly "vertically mis-aligned" with the primary one
    > CGDisplayBounds() will only return the secondary display ID in a
    > small portion of the device -- whichever portion is closest to the
    > primary one.  Is this normal behavior?

    I am confused by what you state in the above... CGDisplayBounds
    returns a CGRect that outlines the bounds in global coordinates for
    the display ID you supply it. It doesn't return display IDs nor
    kCGNullDirectDisplay.

    Maybe you are talking about CGGetDisplaysWithRect?

    -Shawn
  • At 6:57 PM -0700 11/1/07, Shawn Erickson wrote:

    > I am confused by what you state in the above... CGDisplayBounds
    > returns a CGRect that outlines the bounds in global coordinates for
    > the display ID you supply it. It doesn't return display IDs nor
    > kCGNullDirectDisplay.

    My apologies for not explaining properly...  I am getting a point
    from the current display the mouse is located on, calling
    CGGetDisplaysWithPoint() for the point and then passing the returned
    display ID to CGDisplayBounds().  In the case that the secondary
    display is above or below the primary one CGGetDisplaysWithPoint()
    returns null -- and of course my call to CGDisplayBounds as a result
    returns nothing.

    So I guess it's more the case that CGGetDisplaysWithPoint() doesn't
    appear to function as I would expect for stacked displays.
  • On Nov 1, 2007, at 7:56 PM, Mike McNamara wrote:

    > At 6:57 PM -0700 11/1/07, Shawn Erickson wrote:
    >
    >> I am confused by what you state in the above... CGDisplayBounds
    >> returns a CGRect that outlines the bounds in global coordinates for
    >> the display ID you supply it. It doesn't return display IDs nor
    >> kCGNullDirectDisplay.
    >
    > My apologies for not explaining properly...  I am getting a point
    > from the current display the mouse is located on, calling
    > CGGetDisplaysWithPoint() for the point and then passing the returned
    > display ID to CGDisplayBounds().  In the case that the secondary
    > display is above or below the primary one CGGetDisplaysWithPoint()
    > returns null -- and of course my call to CGDisplayBounds as a result
    > returns nothing.
    >
    > So I guess it's more the case that CGGetDisplaysWithPoint() doesn't
    > appear to function as I would expect for stacked displays.

    Are you sure the coordinate space of the mouse coordinates is correct?
    How are you getting the mouse coordinates?

    I suggest you use CG calls to get a list of active displays and
    iterate over that list to output the bounds for all of the displays.
    Then take a look at the mouse coordinates you are attempting to use
    and see if the fall in the rects you got.

    -Shawn
  • At 8:08 PM -0700 11/1/07, Shawn Erickson wrote:

    > Are you sure the coordinate space of the mouse coordinates is
    > correct? How are you getting the mouse coordinates?

    I'm 99.9% certain the mouse coordinates are correct.  I've tried using both:

    NSPoint windowPosition = [[self window] mouseLocationOutsideOfEventStream];
    NSPoint location = [[self window] convertBaseToScreen:windowPosition];

    and:

    [NSEvent mouseLocation]

    Of course I then convert the NSPoint to a CGPoint and pass it to
    CGGetDisplaysWithPoint() to get the display ID(s).

    > I suggest you use CG calls to get a list of active displays and
    > iterate over that list to output the bounds for all of the displays.
    > Then take a look at the mouse coordinates you are attempting to use
    > and see if the fall in the rects you got.

    Good advice.  Thank you.  In fact using CGGetActiveDisplayList() and
    passing those ID's to CGDisplayBounds() appears to return the
    expected bounds for each display.  So assuming my mouse coordinates
    are correct anyway, I can check the display vs. those bounds.

    Mike
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today