| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/screen.h" | 5 #include "ui/gfx/screen.h" |
| 6 | 6 |
| 7 #import <ApplicationServices/ApplicationServices.h> |
| 7 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 8 | 9 |
| 9 namespace gfx { | 10 namespace gfx { |
| 10 | 11 |
| 11 // static | 12 // static |
| 12 gfx::Point Screen::GetCursorScreenPoint() { | 13 gfx::Point Screen::GetCursorScreenPoint() { |
| 13 NSPoint mouseLocation = [NSEvent mouseLocation]; | 14 NSPoint mouseLocation = [NSEvent mouseLocation]; |
| 14 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. | 15 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. |
| 15 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 16 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 16 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; | 17 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; |
| 17 return gfx::Point(mouseLocation.x, mouseLocation.y); | 18 return gfx::Point(mouseLocation.x, mouseLocation.y); |
| 18 } | 19 } |
| 19 | 20 |
| 21 // static |
| 22 gfx::Size Screen::GetPrimaryMonitorSize() { |
| 23 CGDirectDisplayID main_display = CGMainDisplayID(); |
| 24 return gfx::Size(CGDisplayPixelsWide(main_display), |
| 25 CGDisplayPixelsHigh(main_display)); |
| 26 } |
| 27 |
| 28 // static |
| 29 int Screen::GetNumMonitors() { |
| 30 // Don't just return the number of online displays. It includes displays |
| 31 // that mirror other displays, which are not desired in the count. It's |
| 32 // tempting to use the count returned by CGGetActiveDisplayList, but active |
| 33 // displays exclude sleeping displays, and those are desired in the count. |
| 34 |
| 35 // It would be ridiculous to have this many displays connected, but |
| 36 // CGDirectDisplayID is just an integer, so supporting up to this many |
| 37 // doesn't hurt. |
| 38 CGDirectDisplayID online_displays[128]; |
| 39 CGDisplayCount online_display_count = 0; |
| 40 if (CGGetOnlineDisplayList(arraysize(online_displays), |
| 41 online_displays, |
| 42 &online_display_count) != kCGErrorSuccess) { |
| 43 // 1 is a reasonable assumption. |
| 44 return 1; |
| 45 } |
| 46 |
| 47 int display_count = 0; |
| 48 for (CGDisplayCount online_display_index = 0; |
| 49 online_display_index < online_display_count; |
| 50 ++online_display_index) { |
| 51 CGDirectDisplayID online_display = online_displays[online_display_index]; |
| 52 if (CGDisplayMirrorsDisplay(online_display) == kCGNullDirectDisplay) { |
| 53 // If this display doesn't mirror any other, include it in the count. |
| 54 // The primary display in a mirrored set will be counted, but those that |
| 55 // mirror it will not be. |
| 56 ++display_count; |
| 57 } |
| 58 } |
| 59 |
| 60 return display_count; |
| 61 } |
| 62 |
| 20 } // namespace gfx | 63 } // namespace gfx |
| OLD | NEW |