2 * MACDRV Cocoa display settings
4 * Copyright 2011, 2012 Ken Thomases for CodeWeavers Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #import <AppKit/AppKit.h>
22 #include "macdrv_cocoa.h"
25 /***********************************************************************
26 * convert_display_rect
28 * Converts an NSRect in Cocoa's y-goes-up-from-bottom coordinate system
29 * to a CGRect in y-goes-down-from-top coordinates.
31 static inline void convert_display_rect(CGRect* out_rect, NSRect in_rect,
34 *out_rect = NSRectToCGRect(in_rect);
35 out_rect->origin.y = NSMaxY(primary_frame) - NSMaxY(in_rect);
39 /***********************************************************************
42 * Returns information about the displays.
44 * Returns 0 on success and *displays contains a newly-allocated array
45 * of macdrv_display structures and *count contains the number of
46 * elements in that array. The first element of the array is the
47 * primary display. When the caller is done with the array, it should
48 * use macdrv_free_displays() to deallocate it.
50 * Returns non-zero on failure and *displays and *count are unchanged.
52 int macdrv_get_displays(struct macdrv_display** displays, int* count)
55 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
57 NSArray* screens = [NSScreen screens];
60 NSUInteger num_screens = [screens count];
61 struct macdrv_display* disps = malloc(num_screens * sizeof(disps[0]));
68 for (i = 0; i < num_screens; i++)
70 NSScreen* screen = [screens objectAtIndex:i];
71 NSRect frame = [screen frame];
72 NSRect visible_frame = [screen visibleFrame];
75 primary_frame = frame;
77 disps[i].displayID = [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
78 convert_display_rect(&disps[i].frame, frame, primary_frame);
79 convert_display_rect(&disps[i].work_frame, visible_frame,
94 /***********************************************************************
95 * macdrv_free_displays
97 * Deallocates an array of macdrv_display structures previously returned
98 * from macdrv_get_displays().
100 void macdrv_free_displays(struct macdrv_display* displays)