1 /*
2 * Copyright © 2020 Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 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 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * SPDX-License-Identifier: LGPL-2.1-or-later
18 */
19
20 #ifndef __GDK_MACOS_UTILS_PRIVATE_H__
21 #define __GDK_MACOS_UTILS_PRIVATE_H__
22
23 #include <AppKit/AppKit.h>
24 #include <gdk/gdk.h>
25
26 #define GDK_BEGIN_MACOS_ALLOC_POOL NSAutoreleasePool *_pool = [[NSAutoreleasePool alloc] init]
27 #define GDK_END_MACOS_ALLOC_POOL [_pool release]
28
29 static inline gboolean
queue_contains(GQueue * queue,GList * link_)30 queue_contains (GQueue *queue,
31 GList *link_)
32 {
33 return queue->head == link_ || link_->prev || link_->next;
34 }
35
36 struct _GdkPoint
37 {
38 int x;
39 int y;
40 };
41 typedef struct _GdkPoint GdkPoint;
42
43 static inline NSPoint
convert_nspoint_from_screen(NSWindow * window,NSPoint point)44 convert_nspoint_from_screen (NSWindow *window,
45 NSPoint point)
46 {
47 #ifdef AVAILABLE_MAC_OS_X_VERSION_10_15_AND_LATER
48 return [window convertPointFromScreen:point];
49 #else
50 /* Apple documentation claims that convertPointFromScreen is available
51 * on 10.12+. However, that doesn't seem to be the case when using it.
52 * Instead, we'll just use it on modern 10.15 systems and fallback to
53 * converting using rects on older systems.
54 */
55 return [window convertRectFromScreen:NSMakeRect (point.x, point.y, 0, 0)].origin;
56 #endif
57 }
58
59 static inline NSPoint
convert_nspoint_to_screen(NSWindow * window,NSPoint point)60 convert_nspoint_to_screen (NSWindow *window,
61 NSPoint point)
62 {
63 #ifdef AVAILABLE_MAC_OS_X_VERSION_10_15_AND_LATER
64 return [window convertPointToScreen:point];
65 #else
66 /* Apple documentation claims that convertPointToScreen is available
67 * on 10.12+. However, that doesn't seem to be the case when using it.
68 * Instead, we'll just use it on modern 10.15 systems and fallback to
69 * converting using rects on older systems.
70 */
71 return [window convertRectToScreen:NSMakeRect (point.x, point.y, 0, 0)].origin;
72 #endif
73 }
74
75 #endif /* __GDK_MACOS_UTILS_PRIVATE_H__ */
76