Window "snapping" to main screen

  • Hi everybody,

    I have two screens on my MacPro (10.7.3)

    When opening a window with the following code :

        // create a reference rect
        NSRect  contentSize = NSMakeRect( iX, iY, iW, iH );

        // allocate window
        NSUInteger  styleMask          NSTitledWindowMask |
            NSClosableWindowMask |
            NSMiniaturizableWindowMask |
            NSResizableWindowMask;

        mWindow = [[NSWindow alloc] initWithContentRect: contentSize styleMask: styleMask backing: NSBackingStoreBuffered defer: YES];
        Cocoa_WindowDelegate*  delegate = [[Cocoa_WindowDelegate  alloc]  init];
        [mWindow  setDelegate: delegate];

        // show window
        [mWindow  makeKeyAndOrderFront: mWindow];
        [mWindow  makeMainWindow];

    where iX,iY,iW,iH are the wanted position and w/h of the window, the window always "snaps" to the main screen.
    It's y,w,h are correct, but x is adjusted so the window either fits entirely on the main screen (flush at the right border), or if
    it's too wide, x is set to 0.  Even if the asked for position is entirely on the second screen and doesn't straddle the boundary
    between the screens.
    Other apps don't have this problem.

    What am I doing wrong or what did I forget to do ?

    Thanks for your help.

    --
    Eric M.
  • Hello,

    nobody has an idea ?

    On 03/05/12 10:27, Eric Matecki wrote:
    > Hi everybody,
    >
    > I have two screens on my MacPro (10.7.3)
    >
    > When opening a window with the following code :
    >
    > // create a reference rect
    > NSRect contentSize = NSMakeRect( iX, iY, iW, iH );
    >
    > // allocate window
    > NSUInteger styleMask > NSTitledWindowMask |
    > NSClosableWindowMask |
    > NSMiniaturizableWindowMask |
    > NSResizableWindowMask;
    >
    > mWindow = [[NSWindow alloc] initWithContentRect: contentSize styleMask: styleMask backing: NSBackingStoreBuffered defer: YES];
    > Cocoa_WindowDelegate* delegate = [[Cocoa_WindowDelegate alloc] init];
    > [mWindow setDelegate: delegate];
    >
    > // show window
    > [mWindow makeKeyAndOrderFront: mWindow];
    > [mWindow makeMainWindow];
    >
    > where iX,iY,iW,iH are the wanted position and w/h of the window, the window always "snaps" to the main screen.
    > It's y,w,h are correct, but x is adjusted so the window either fits entirely on the main screen (flush at the right border), or if
    > it's too wide, x is set to 0. Even if the asked for position is entirely on the second screen and doesn't straddle the boundary
    > between the screens.
    > Other apps don't have this problem.
    >
    > What am I doing wrong or what did I forget to do ?
    >
    > Thanks for your help.
    >

    --
    Keep intel OUTSIDE my Mac !
    Hiii !!! I can see Intel chips creeping around my G5 !

    Eric M.
  • On May 7, 2012, at 00:14 , Eric Matecki wrote:

    >> mWindow = [[NSWindow alloc] initWithContentRect: contentSize styleMask: styleMask backing: NSBackingStoreBuffered defer: YES];

    I would assume that the content rect is here assumed to be relative to the main screen. Have you tried 'initWithContentRect:styleMask:backing:defer:screen:' instead?
  • On May 7, 2012, at 00:30 , Quincey Morris wrote:

    > On May 7, 2012, at 00:14 , Eric Matecki wrote:
    >
    >>> mWindow = [[NSWindow alloc] initWithContentRect: contentSize styleMask: styleMask backing: NSBackingStoreBuffered defer: YES];
    >
    > I would assume that the content rect is here assumed to be relative to the main screen. Have you tried 'initWithContentRect:styleMask:backing:defer:screen:' instead?

    Er…having trouble saying what I mean today…

    I meant to say that the content rect is assumed to be relative to the main screen, and windows are constrained to the boundaries of their screen. Presumably specifying the screen via the alternative initializer will cause it to constrain to that screen, and you can use a different contentRect if you want to position it directly.

    If you want to defeat the constraining, for a specific screen, you have to subclass NSWindow and override 'constrainFrameRect:toScreen:' to do whatever you want.
  • On 07/05/12 09:39, Quincey Morris wrote:
    > On May 7, 2012, at 00:30 , Quincey Morris wrote:
    >
    >> On May 7, 2012, at 00:14 , Eric Matecki wrote:
    >>
    >>>> mWindow = [[NSWindow alloc] initWithContentRect: contentSize styleMask: styleMask backing: NSBackingStoreBuffered defer: YES];
    >>
    >> I would assume that the content rect is here assumed to be relative to the main screen. Have you tried
    >> 'initWithContentRect:styleMask:backing:defer:screen:' instead?
    >
    > Er…having trouble saying what I mean today…
    >
    > I meant to say that the content rect is assumed to be relative to the main screen, and windows are constrained to the boundaries
    > of their screen. Presumably specifying the screen via the alternative initializer will cause it to constrain to that screen, and
    > you can use a different contentRect if you want to position it directly.
    >
    > If you want to defeat the constraining, for a specific screen, you have to subclass NSWindow and override
    > 'constrainFrameRect:toScreen:' to do whatever you want.

    Thanks Quincey, I will look at overriding constrainFrameRect:toScreen:

    The content rect is relative to the main screen, that's what I want and what I get anyhow when calling:
    [mWindow  contentRectForFrameRect: [mWindow  frame]].

    So I assumed passing it back to the window initialization method will put my window back where it was.

    --
    Keep intel OUTSIDE my Mac !
    Hiii !!! I can see Intel chips creeping around my G5 !

    Eric M.
  • Thanks Quincy, this works !

    On 07/05/12 11:56, Eric Matecki wrote:
    > On 07/05/12 09:39, Quincey Morris wrote:
    >> On May 7, 2012, at 00:30 , Quincey Morris wrote:
    >>
    >>> On May 7, 2012, at 00:14 , Eric Matecki wrote:
    >>>
    >>>>> mWindow = [[NSWindow alloc] initWithContentRect: contentSize styleMask: styleMask backing: NSBackingStoreBuffered defer: YES];
    >>>
    >>> I would assume that the content rect is here assumed to be relative to the main screen. Have you tried
    >>> 'initWithContentRect:styleMask:backing:defer:screen:' instead?
    >>
    >> Er…having trouble saying what I mean today…
    >>
    >> I meant to say that the content rect is assumed to be relative to the main screen, and windows are constrained to the boundaries
    >> of their screen. Presumably specifying the screen via the alternative initializer will cause it to constrain to that screen, and
    >> you can use a different contentRect if you want to position it directly.
    >>
    >> If you want to defeat the constraining, for a specific screen, you have to subclass NSWindow and override
    >> 'constrainFrameRect:toScreen:' to do whatever you want.
    >
    > Thanks Quincey, I will look at overriding constrainFrameRect:toScreen:
    >
    > The content rect is relative to the main screen, that's what I want and what I get anyhow when calling:
    > [mWindow contentRectForFrameRect: [mWindow frame]].
    >
    > So I assumed passing it back to the window initialization method will put my window back where it was.
    >

    --
    Keep intel OUTSIDE my Mac !
    Hiii !!! I can see Intel chips creeping around my G5 !

    Eric M.
previous month may 2012 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 31      
Go to today