Debian Codegraph @

gdk/quartz/gdkmonitor-quartz.c

raw
1 /*
2 * Copyright © 2017 Tom Schoonjans
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "config.h"
19
20 #include <glib.h>
21 #include <gio/gio.h>
22
23 #include "gdkmonitor-quartz.h"
24 #include "gdkdisplay-quartz.h"
25 #include "gdkinternal-quartz.h"
26
27 G_DEFINE_TYPE (GdkQuartzMonitor, gdk_quartz_monitor, GDK_TYPE_MONITOR)
28
29 static void
30 gdk_quartz_monitor_get_workarea (GdkMonitor *monitor,
31 GdkRectangle *dest)
32 {
33 GDK_QUARTZ_ALLOC_POOL;
34
35 NSArray *array = [NSScreen screens];
36 NSScreen* screen = NULL;
37 for (id obj in array)
38 {
39 CGDirectDisplayID screen_id =
40 [[[obj deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
41 GdkQuartzMonitor *q_mon = GDK_QUARTZ_MONITOR (monitor);
42 if (screen_id == q_mon->id)
43 {
44 screen = obj;
45 break;
46 }
47 }
48
49 if (screen)
50 {
51 GdkQuartzDisplay *display =
52 GDK_QUARTZ_DISPLAY (gdk_monitor_get_display (monitor));
53 NSRect rect = [screen visibleFrame];
54 dest->x = (int)trunc (display->geometry.origin.x + rect.origin.x);
55 dest->y = (int)trunc (display->geometry.origin.y -
56 rect.origin.y - rect.size.height);
57 dest->width = rect.size.width;
58 dest->height = rect.size.height;
59 }
60 else
61 *dest = monitor->geometry;
62
63 GDK_QUARTZ_RELEASE_POOL;
64 }
65
66 static void
67 gdk_quartz_monitor_init (GdkQuartzMonitor *monitor)
68 {
69 }
70
71 static void
72 gdk_quartz_monitor_class_init (GdkQuartzMonitorClass *class)
73 {
74 GDK_MONITOR_CLASS (class)->get_workarea = gdk_quartz_monitor_get_workarea;
75 }
76