Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Mac: Brackets window opens on monitor with focus #10755

Open
redmunds opened this issue Mar 17, 2015 · 7 comments
Open

Mac: Brackets window opens on monitor with focus #10755

redmunds opened this issue Mar 17, 2015 · 7 comments

Comments

@redmunds
Copy link
Contributor

I am seeing this with Brackets 1.2 on Yosemite. I have a MacBook Pro with a secondary monitor.

It doesn't matter which monitor Brackets window was positioned in when I shutdown, Brackets is opened in whichever monitor has focus. Works either way between laptop monitor and external monitor.

@redmunds redmunds changed the title Mac: Brackets opens on monitor with focus Mac: Brackets window opens on monitor with focus Mar 17, 2015
@nethip
Copy link
Contributor

nethip commented Mar 18, 2015

@redmunds I will try to repro this and dig more into it.

@redmunds
Copy link
Contributor Author

This may be a fact of life on Yosemite as I see it happen in other apps, too.

@nethip
Copy link
Contributor

nethip commented Mar 18, 2015

@redmunds Good catch! 😄 I am able to repro this too. I tried with some Apple apps(iTunes, safari) and non Apple apps(Chrome, Kontakt). The above behaviour is specific to Brackets. I will debug and figure out why the window is getting moved to the active screen.

@peterflynn
Copy link
Member

@redmunds Is this a regression in 1.2, or has it been around for a while? That has a bearing on priority...

@redmunds
Copy link
Contributor Author

I also see this in Brackets 1.0, so not a new regression.

@nethip
Copy link
Contributor

nethip commented Mar 19, 2015

@redmunds I could debug the problem and the problem lies in the following code in cefclient_mac.mm.

Create the main application window.
  NSUInteger styleMask = (NSTitledWindowMask |
                          NSClosableWindowMask |
                          NSMiniaturizableWindowMask |
                          NSResizableWindowMask |
                          NSTexturedBackgroundWindowMask );

  // Get the available screen space
  NSRect screen_rect = [[NSScreen mainScreen] visibleFrame];
  // Start out with the content being as big as possible
  NSRect content_rect = [NSWindow contentRectForFrameRect:screen_rect styleMask:styleMask];

  // Determine the maximum height
  const int maxHeight = kWindowHeight;
  // Make the content rect fit into maxHeight and kWindowWidth
  if (content_rect.size.height > maxHeight) {
    // First move the window up as much as we reduce it's height so it opens in the top left corner
    content_rect.origin.y += content_rect.size.height - maxHeight;
    content_rect.size.height = maxHeight;
  }
  if (content_rect.size.width > kWindowWidth) {
    content_rect.size.width = kWindowWidth;
  }

  // Initialize the window with the adjusted default size
  NSWindow* mainWnd = [[UnderlayOpenGLHostingWindow alloc]
                       initWithContentRect:content_rect
                       styleMask:styleMask
                       backing:NSBackingStoreBuffered
                       defer:NO];

and

  // "Preclude the window controller from changing a window’s position from the
  // one saved in the defaults system" (NSWindow Class Reference)
  [[mainWnd windowController] setShouldCascadeWindows: NO];

  // Set the "autosave" name for the window. If there is a previously stored
  // size for the window, it will be loaded here and used to resize the window.
  // It appears that if the stored size is too big for the screen,
  // it is automatically adjusted to fit.
  [mainWnd setFrameAutosaveName:APP_NAME @"MainWindow"];

On substituting the first part with

   // Create the main application window.
    NSRect screen_rect = [[NSScreen mainScreen] visibleFrame];
    NSRect window_rect = { {0, screen_rect.size.height - kWindowHeight},
        {kWindowWidth, kWindowHeight} };
    NSWindow* mainWnd = [[UnderlayOpenGLHostingWindow alloc]
                         initWithContentRect:window_rect
                         styleMask:(NSTitledWindowMask |
                                    NSClosableWindowMask |
                                    NSMiniaturizableWindowMask |
                                    NSResizableWindowMask )
                         backing:NSBackingStoreBuffered
                         defer:NO];

and disabling the setShouldCascadeWindows part, the bug seems to go away. But if I disable setFrameAutosaveName, Brackets window is appearing on the primary monitor but is not remembering the position of the window any more.

@redmunds
Copy link
Contributor Author

From @dsotirescu in #10669: "I reproduced your issue. In my case Brackets doesn't always open on the focused monitor, 50% of the time. I have 2 external monitors, thunderbolt + 4K monitor by Dell. Running on latest Mac Book Pro."

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants