Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_UtilsCocoa.m
- This file was added.
| /* | |||||
| * This program is free software; you can redistribute it and/or | |||||
| * modify it under the terms of the GNU General Public License | |||||
| * as published by the Free Software Foundation; either version 2 | |||||
| * of the License, or (at your option) any later version. | |||||
| * | |||||
| * This program is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with this program; if not, write to the Free Software Foundation, | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| * | |||||
| * The Original Code is Copyright (C) 2019 Blender Foundation. | |||||
| * All rights reserved. | |||||
| */ | |||||
| /** \file \ingroup GHOST | |||||
| */ | |||||
| #import "GHOST_UtilsCocoa.h" | |||||
| @implementation GHOST_UtilsCocoa | |||||
| #define SCREEN_SIZE(screen) (screen ? screen.frame.size.width * screen.frame.size.height : 0) | |||||
| #define SCREEN_ID(screen) [[[screen deviceDescription] valueForKey:@"NSScreenNumber"] intValue] | |||||
| // in appkit, the main screen refers to the screen containing the window that is | |||||
| // currently receiving keyboard events. this is variable, so for consistency with other | |||||
| // platforms we define our own 'main screen' here which doesn't change. | |||||
| + (NSScreen *)mainScreen | |||||
| { | |||||
| // let the main screen be the screen at origin (0,0). If there is no screen at (0,0), | |||||
| // use the largest screen. if there are two or more screens with the same size, | |||||
| // use the one with the lowest display id. | |||||
| NSScreen *main = NULL; | |||||
| int mainSize = 0; | |||||
| CGPoint originZero = CGPointMake(0, 0); | |||||
| for (NSScreen *screen in [NSScreen screens]) { | |||||
| int size = SCREEN_SIZE(screen); | |||||
| bool atZero = CGPointEqualToPoint(originZero, screen.frame.origin); | |||||
| if (atZero || main == NULL || | |||||
| (size > mainSize || | |||||
| (size == mainSize && SCREEN_ID(screen) < SCREEN_ID(main)))) { | |||||
| // bigger screen found, or screen at (0,0), | |||||
| // or same size screen with lower screen id | |||||
| main = screen; | |||||
| mainSize = size; | |||||
| // stop looking if we find a screen at 0,0 | |||||
| if (atZero) | |||||
| break; | |||||
| } | |||||
| } | |||||
| return main; | |||||
| } | |||||
| @end | |||||