Merge pull request #1636 from atom/ns-mainscreen

Don't use [NSScreen mainScreen]
This commit is contained in:
Cheng Zhao 2015-05-10 20:52:46 +08:00
commit 18780487c2
2 changed files with 4 additions and 4 deletions

View file

@ -303,7 +303,7 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
options.Get(switches::kWidth, &width); options.Get(switches::kWidth, &width);
options.Get(switches::kHeight, &height); options.Get(switches::kHeight, &height);
NSRect main_screen_rect = [[NSScreen mainScreen] frame]; NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame];
NSRect cocoa_bounds = NSMakeRect( NSRect cocoa_bounds = NSMakeRect(
round((NSWidth(main_screen_rect) - width) / 2) , round((NSWidth(main_screen_rect) - width) / 2) ,
round((NSHeight(main_screen_rect) - height) / 2), round((NSHeight(main_screen_rect) - height) / 2),
@ -463,7 +463,7 @@ void NativeWindowMac::SetBounds(const gfx::Rect& bounds) {
bounds.width(), bounds.width(),
bounds.height()); bounds.height());
// Flip coordinates based on the primary screen. // Flip coordinates based on the primary screen.
NSScreen* screen = [NSScreen mainScreen]; NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
cocoa_bounds.origin.y = cocoa_bounds.origin.y =
NSHeight([screen frame]) - bounds.height() - bounds.y(); NSHeight([screen frame]) - bounds.height() - bounds.y();
@ -473,7 +473,7 @@ void NativeWindowMac::SetBounds(const gfx::Rect& bounds) {
gfx::Rect NativeWindowMac::GetBounds() { gfx::Rect NativeWindowMac::GetBounds() {
NSRect frame = [window_ frame]; NSRect frame = [window_ frame];
gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame)); gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
NSScreen* screen = [NSScreen mainScreen]; NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame)); bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
return bounds; return bounds;
} }

View file

@ -30,7 +30,7 @@
NSRect frame = [NSApp currentEvent].window.frame; NSRect frame = [NSApp currentEvent].window.frame;
gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame)); gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
// Flip coordinates to gfx (0,0 in top-left corner) using current screen. // Flip coordinates to gfx (0,0 in top-left corner) using current screen.
NSScreen* screen = [NSScreen mainScreen]; NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame)); bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
trayIcon_->NotifyClicked(bounds); trayIcon_->NotifyClicked(bounds);