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_DISPLAY_PRIVATE_H__
21 #define __GDK_MACOS_DISPLAY_PRIVATE_H__
22 
23 #include <AppKit/AppKit.h>
24 
25 #include "gdkdisplayprivate.h"
26 
27 #include "gdkmacosdisplay.h"
28 #include "gdkmacoskeymap.h"
29 #include "gdkmacossurface.h"
30 
31 G_BEGIN_DECLS
32 
33 /* Text Input Client */
34 #define TIC_MARKED_TEXT      "tic-marked-text"
35 #define TIC_SELECTED_POS     "tic-selected-pos"
36 #define TIC_SELECTED_LEN     "tic-selected-len"
37 #define TIC_INSERT_TEXT      "tic-insert-text"
38 #define TIC_IN_KEY_DOWN      "tic-in-key-down"
39 
40 /* GtkIMContext */
41 #define GIC_CURSOR_RECT      "gic-cursor-rect"
42 #define GIC_FILTER_KEY       "gic-filter-key"
43 #define GIC_FILTER_PASSTHRU  0
44 #define GIC_FILTER_FILTERED  1
45 
46 struct _GdkMacosDisplay
47 {
48   GdkDisplay parent_instance;
49 
50   char *name;
51   GdkMacosKeymap *keymap;
52 
53   /* An list of GdkMacosMonitor. The first instance is always the primary
54    * monitor. This contains the 0,0 coordinate in quartz coordinates, but may
55    * not be 0,0 in GDK coordinates.
56    */
57   GListStore *monitors;
58 
59   /* A queue of surfaces that have been made "main" so that we can update the
60    * main status to the next surface when a window has lost main status (such
61    * as when destroyed). This uses the GdkMacosSurface main link.
62    */
63   GQueue main_surfaces;
64 
65   /* A queue of surfaces sorted by their front-to-back ordering on the screen.
66    * This is updated occasionally when we know that the data we have cached
67    * has been invalidated. This uses the GdkMacosSurface.sorted link.
68    */
69   GQueue sorted_surfaces;
70 
71   /* Our CVDisplayLink based GSource which we use to freeze/thaw the
72    * GdkFrameClock for the surface.
73    */
74   GSource *frame_source;
75 
76   /* A queue of surfaces which we know are awaiting frames to be drawn. This
77    * uses the GdkMacosSurface.frame link.
78    */
79   GQueue awaiting_frames;
80 
81   /* The surface that is receiving keyboard events */
82   GdkMacosSurface *keyboard_surface;
83 
84   /* [NSDraggingInfo draggingSequenceNumber] to GdkMacosDr(ag,op) */
85   GHashTable *active_drags;
86   GHashTable *active_drops;
87 
88   /* Used to translate from quartz coordinate space to GDK */
89   int width;
90   int height;
91   int min_x;
92   int min_y;
93   int max_x;
94   int max_y;
95 };
96 
97 struct _GdkMacosDisplayClass
98 {
99   GdkDisplayClass parent_class;
100 };
101 
102 
103 GdkDisplay      *_gdk_macos_display_open                           (const char      *display_name);
104 int              _gdk_macos_display_get_fd                         (GdkMacosDisplay *self);
105 void             _gdk_macos_display_queue_events                   (GdkMacosDisplay *self);
106 void             _gdk_macos_display_to_display_coords              (GdkMacosDisplay *self,
107                                                                     int              x,
108                                                                     int              y,
109                                                                     int             *out_x,
110                                                                     int             *out_y);
111 void             _gdk_macos_display_from_display_coords            (GdkMacosDisplay *self,
112                                                                     int              x,
113                                                                     int              y,
114                                                                     int             *out_x,
115                                                                     int             *out_y);
116 NSScreen        *_gdk_macos_display_get_screen_at_display_coords   (GdkMacosDisplay *self,
117                                                                     int              x,
118                                                                     int              y);
119 GdkMonitor      *_gdk_macos_display_get_monitor_at_coords          (GdkMacosDisplay *self,
120                                                                     int              x,
121                                                                     int              y);
122 GdkMonitor      *_gdk_macos_display_get_monitor_at_display_coords  (GdkMacosDisplay *self,
123                                                                     int              x,
124                                                                     int              y);
125 GdkEvent        *_gdk_macos_display_translate                      (GdkMacosDisplay *self,
126                                                                     NSEvent         *event);
127 void             _gdk_macos_display_break_all_grabs                (GdkMacosDisplay *self,
128                                                                     guint32          time);
129 GdkModifierType  _gdk_macos_display_get_current_keyboard_modifiers (GdkMacosDisplay *self);
130 GdkModifierType  _gdk_macos_display_get_current_mouse_modifiers    (GdkMacosDisplay *self);
131 GdkMacosSurface *_gdk_macos_display_get_surface_at_display_coords  (GdkMacosDisplay *self,
132                                                                     double           x,
133                                                                     double           y,
134                                                                     int             *surface_x,
135                                                                     int             *surface_y);
136 void             _gdk_macos_display_reload_monitors                (GdkMacosDisplay *self);
137 void             _gdk_macos_display_surface_removed                (GdkMacosDisplay *self,
138                                                                     GdkMacosSurface *surface);
139 void             _gdk_macos_display_add_frame_callback             (GdkMacosDisplay *self,
140                                                                     GdkMacosSurface *surface);
141 void             _gdk_macos_display_remove_frame_callback          (GdkMacosDisplay *self,
142                                                                     GdkMacosSurface *surface);
143 NSWindow        *_gdk_macos_display_find_native_under_pointer      (GdkMacosDisplay *self,
144                                                                     int             *x,
145                                                                     int             *y);
146 gboolean         _gdk_macos_display_get_setting                    (GdkMacosDisplay *self,
147                                                                     const char      *setting,
148                                                                     GValue          *value);
149 void             _gdk_macos_display_reload_settings                (GdkMacosDisplay *self);
150 void             _gdk_macos_display_surface_resigned_main          (GdkMacosDisplay *self,
151                                                                     GdkMacosSurface *surface);
152 void             _gdk_macos_display_surface_became_main            (GdkMacosDisplay *self,
153                                                                     GdkMacosSurface *surface);
154 void             _gdk_macos_display_surface_resigned_key           (GdkMacosDisplay *self,
155                                                                     GdkMacosSurface *surface);
156 void             _gdk_macos_display_surface_became_key             (GdkMacosDisplay *self,
157                                                                     GdkMacosSurface *surface);
158 int              _gdk_macos_display_get_nominal_refresh_rate       (GdkMacosDisplay *self);
159 void             _gdk_macos_display_clear_sorting                  (GdkMacosDisplay *self);
160 const GList     *_gdk_macos_display_get_surfaces                   (GdkMacosDisplay *self);
161 void             _gdk_macos_display_send_button_event              (GdkMacosDisplay *self,
162                                                                     NSEvent         *nsevent);
163 void             _gdk_macos_display_warp_pointer                   (GdkMacosDisplay *self,
164                                                                     int              x,
165                                                                     int              y);
166 NSEvent         *_gdk_macos_display_get_nsevent                    (GdkEvent        *event);
167 GdkDrag         *_gdk_macos_display_find_drag                      (GdkMacosDisplay *self,
168                                                                     NSInteger        sequence_number);
169 GdkDrop         *_gdk_macos_display_find_drop                      (GdkMacosDisplay *self,
170                                                                     NSInteger        sequence_number);
171 void             _gdk_macos_display_set_drag                       (GdkMacosDisplay *self,
172                                                                     NSInteger        sequence_number,
173                                                                     GdkDrag         *drag);
174 void             _gdk_macos_display_set_drop                       (GdkMacosDisplay *self,
175                                                                     NSInteger        sequence_number,
176                                                                     GdkDrop         *drop);
177 
178 G_END_DECLS
179 
180 #endif /* __GDK_MACOS_DISPLAY_PRIVATE_H__ */
181