1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 2019 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 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 
18 /* Uninstalled header defining types and functions internal to GDK */
19 
20 #ifndef __GDK_SURFACE_PRIVATE_H__
21 #define __GDK_SURFACE_PRIVATE_H__
22 
23 #include <gdk-pixbuf/gdk-pixbuf.h>
24 #include "gdkenumtypes.h"
25 #include "gdksurface.h"
26 #include "gdktoplevel.h"
27 
28 G_BEGIN_DECLS
29 
30 typedef enum
31 {
32   GDK_SURFACE_TOPLEVEL,
33   GDK_SURFACE_TEMP,
34   GDK_SURFACE_POPUP
35 } GdkSurfaceType;
36 
37 struct _GdkSurface
38 {
39   GObject parent_instance;
40 
41   GdkDisplay *display;
42 
43   GdkSurface *transient_for; /* for toplevels */
44   GdkSurface *parent;        /* for popups */
45   GList *children;           /* popups */
46 
47   guint set_is_mapped_source_id;
48   gboolean pending_is_mapped;
49   gboolean is_mapped;
50 
51   gpointer widget;
52 
53   int x;
54   int y;
55 
56   GdkGLContext *gl_paint_context;
57 
58   cairo_region_t *update_area;
59   guint update_freeze_count;
60   GdkFrameClockPhase pending_phases;
61   /* This is the update_area that was in effect when the current expose
62      started. It may be smaller than the expose area if we'e painting
63      more than we have to, but it represents the "true" damage. */
64   cairo_region_t *active_update_area;
65 
66   GdkToplevelState pending_set_flags;
67   GdkToplevelState pending_unset_flags;
68   GdkToplevelState state;
69 
70   guint8 resize_count;
71 
72   guint8 alpha;
73   guint8 fullscreen_mode;
74 
75   guint modal_hint : 1;
76   guint destroyed : 2;
77   guint in_update : 1;
78   guint frame_clock_events_paused : 1;
79   guint autohide : 1;
80   guint shortcuts_inhibited : 1;
81   guint request_motion : 1;
82 
83   guint request_motion_id;
84 
85   struct {
86     GdkGravity surface_anchor;
87     GdkGravity rect_anchor;
88   } popup;
89 
90   guint update_and_descendants_freeze_count;
91 
92   int width, height;
93 
94   GdkCursor *cursor;
95   GHashTable *device_cursor;
96 
97   cairo_region_t *input_region;
98 
99   GList *devices_inside;
100 
101   GdkFrameClock *frame_clock; /* NULL to use from parent or default */
102 
103   GSList *draw_contexts;
104   GdkDrawContext *paint_context;
105 
106   cairo_region_t *opaque_region;
107 
108   GdkSeat *current_shortcuts_inhibited_seat;
109 };
110 
111 struct _GdkSurfaceClass
112 {
113   GObjectClass parent_class;
114 
115   cairo_surface_t *
116                (* ref_cairo_surface)    (GdkSurface      *surface);
117   void         (* hide)                 (GdkSurface      *surface);
118   void         (* get_geometry)         (GdkSurface      *surface,
119                                          int             *x,
120                                          int             *y,
121                                          int             *width,
122                                          int             *height);
123   void         (* get_root_coords)      (GdkSurface      *surface,
124                                          int              x,
125                                          int              y,
126                                          int             *root_x,
127                                          int             *root_y);
128   gboolean     (* get_device_state)     (GdkSurface      *surface,
129                                          GdkDevice       *device,
130                                          double          *x,
131                                          double          *y,
132                                          GdkModifierType *mask);
133   void         (* set_input_region)     (GdkSurface      *surface,
134                                          cairo_region_t  *shape_region);
135 
136   /* Called to do the windowing system specific part of gdk_surface_destroy(),
137    *
138    * surface: The window being destroyed
139    * foreign_destroy: If TRUE, the surface or a parent was destroyed by some
140    *     external agency. The surface has already been destroyed and no
141    *     windowing system calls should be made. (This may never happen
142    *     for some windowing systems.)
143    */
144   void         (* destroy)              (GdkSurface       *surface,
145                                          gboolean         foreign_destroy);
146 
147 
148   /* optional */
149   gboolean     (* beep)                 (GdkSurface       *surface);
150 
151   void         (* destroy_notify)       (GdkSurface *surface);
152   GdkDrag *    (* drag_begin)           (GdkSurface         *surface,
153                                          GdkDevice          *device,
154                                          GdkContentProvider *content,
155                                          GdkDragAction       actions,
156                                          double              dx,
157                                          double              dy);
158 
159   int          (* get_scale_factor)       (GdkSurface      *surface);
160 
161   void         (* set_opaque_region)      (GdkSurface      *surface,
162                                            cairo_region_t *region);
163   void         (* request_layout)         (GdkSurface     *surface);
164   gboolean     (* compute_size)           (GdkSurface     *surface);
165 };
166 
167 #define GDK_SURFACE_DESTROYED(d) (((GdkSurface *)(d))->destroyed)
168 
169 #define GDK_SURFACE_IS_MAPPED(surface) ((surface)->pending_is_mapped)
170 
171 void gdk_surface_set_state (GdkSurface      *surface,
172                             GdkToplevelState  new_state);
173 
174 void gdk_surface_set_is_mapped (GdkSurface *surface,
175                                 gboolean    is_mapped);
176 
177 GdkMonitor * gdk_surface_get_layout_monitor (GdkSurface      *surface,
178                                              GdkPopupLayout  *layout,
179                                              void           (*get_bounds) (GdkMonitor   *monitor,
180                                                                            GdkRectangle *bounds));
181 
182 void gdk_surface_layout_popup_helper (GdkSurface     *surface,
183                                       int             width,
184                                       int             height,
185                                       int             shadow_left,
186                                       int             shadow_right,
187                                       int             shadow_top,
188                                       int             shadow_bottom,
189                                       GdkMonitor     *monitor,
190                                       GdkRectangle   *bounds,
191                                       GdkPopupLayout *layout,
192                                       GdkRectangle   *out_final_rect);
193 
194 static inline GdkGravity
gdk_gravity_flip_horizontally(GdkGravity anchor)195 gdk_gravity_flip_horizontally (GdkGravity anchor)
196 {
197   switch (anchor)
198     {
199     default:
200     case GDK_GRAVITY_STATIC:
201     case GDK_GRAVITY_NORTH_WEST:
202       return GDK_GRAVITY_NORTH_EAST;
203     case GDK_GRAVITY_NORTH:
204       return GDK_GRAVITY_NORTH;
205     case GDK_GRAVITY_NORTH_EAST:
206       return GDK_GRAVITY_NORTH_WEST;
207     case GDK_GRAVITY_WEST:
208       return GDK_GRAVITY_EAST;
209     case GDK_GRAVITY_CENTER:
210       return GDK_GRAVITY_CENTER;
211     case GDK_GRAVITY_EAST:
212       return GDK_GRAVITY_WEST;
213     case GDK_GRAVITY_SOUTH_WEST:
214       return GDK_GRAVITY_SOUTH_EAST;
215     case GDK_GRAVITY_SOUTH:
216       return GDK_GRAVITY_SOUTH;
217     case GDK_GRAVITY_SOUTH_EAST:
218       return GDK_GRAVITY_SOUTH_WEST;
219     }
220 
221   g_assert_not_reached ();
222 }
223 
224 static inline GdkGravity
gdk_gravity_flip_vertically(GdkGravity anchor)225 gdk_gravity_flip_vertically (GdkGravity anchor)
226 {
227   switch (anchor)
228     {
229     default:
230     case GDK_GRAVITY_STATIC:
231     case GDK_GRAVITY_NORTH_WEST:
232       return GDK_GRAVITY_SOUTH_WEST;
233     case GDK_GRAVITY_NORTH:
234       return GDK_GRAVITY_SOUTH;
235     case GDK_GRAVITY_NORTH_EAST:
236       return GDK_GRAVITY_SOUTH_EAST;
237     case GDK_GRAVITY_WEST:
238       return GDK_GRAVITY_WEST;
239     case GDK_GRAVITY_CENTER:
240       return GDK_GRAVITY_CENTER;
241     case GDK_GRAVITY_EAST:
242       return GDK_GRAVITY_EAST;
243     case GDK_GRAVITY_SOUTH_WEST:
244       return GDK_GRAVITY_NORTH_WEST;
245     case GDK_GRAVITY_SOUTH:
246       return GDK_GRAVITY_NORTH;
247     case GDK_GRAVITY_SOUTH_EAST:
248       return GDK_GRAVITY_NORTH_EAST;
249     }
250 
251   g_assert_not_reached ();
252 }
253 
254 void       _gdk_surface_destroy           (GdkSurface      *surface,
255                                            gboolean        foreign_destroy);
256 void       gdk_surface_invalidate_rect    (GdkSurface           *surface,
257                                            const GdkRectangle   *rect);
258 void       gdk_surface_invalidate_region  (GdkSurface           *surface,
259                                            const cairo_region_t *region);
260 void       _gdk_surface_clear_update_area (GdkSurface      *surface);
261 void       _gdk_surface_update_size       (GdkSurface      *surface);
262 
263 GdkGLContext * gdk_surface_get_paint_gl_context (GdkSurface *surface,
264                                                  GError   **error);
265 
266 gboolean gdk_surface_handle_event (GdkEvent       *event);
267 GdkSeat * gdk_surface_get_seat_from_event (GdkSurface *surface,
268                                            GdkEvent    *event);
269 
270 void       gdk_surface_enter_monitor (GdkSurface *surface,
271                                       GdkMonitor *monitor);
272 void       gdk_surface_leave_monitor (GdkSurface *surface,
273                                       GdkMonitor *monitor);
274 
275 void gdk_surface_destroy_notify       (GdkSurface *surface);
276 
277 void gdk_synthesize_surface_state (GdkSurface     *surface,
278                                    GdkToplevelState unset_flags,
279                                    GdkToplevelState set_flags);
280 
281 void gdk_surface_get_root_coords (GdkSurface *surface,
282                                   int         x,
283                                   int         y,
284                                   int        *root_x,
285                                   int        *root_y);
286 void gdk_surface_get_origin      (GdkSurface *surface,
287                                   int        *x,
288                                   int        *y);
289 
290 
291 void gdk_surface_get_geometry (GdkSurface *surface,
292                                int        *x,
293                                int        *y,
294                                int        *width,
295                                int        *height);
296 
297 void       gdk_surface_freeze_updates      (GdkSurface    *surface);
298 void       gdk_surface_thaw_updates        (GdkSurface    *surface);
299 
300 
301 typedef enum
302 {
303   GDK_HINT_MIN_SIZE    = 1 << 1,
304   GDK_HINT_MAX_SIZE    = 1 << 2,
305 } GdkSurfaceHints;
306 
307 typedef struct _GdkGeometry GdkGeometry;
308 
309 struct _GdkGeometry
310 {
311   int min_width;
312   int min_height;
313   int max_width;
314   int max_height;
315 };
316 
317 void       gdk_surface_constrain_size      (GdkGeometry    *geometry,
318                                             GdkSurfaceHints  flags,
319                                             int             width,
320                                             int             height,
321                                             int            *new_width,
322                                             int            *new_height);
323 
324 void       gdk_surface_queue_state_change  (GdkSurface       *surface,
325                                             GdkToplevelState  unset_flags,
326                                             GdkToplevelState  set_flags);
327 
328 void       gdk_surface_apply_state_change  (GdkSurface       *surface);
329 
330 void       gdk_surface_emit_size_changed   (GdkSurface       *surface,
331                                             int               width,
332                                             int               height);
333 
334 void       gdk_surface_request_compute_size (GdkSurface      *surface);
335 
336 GDK_AVAILABLE_IN_ALL
337 void           gdk_surface_request_motion (GdkSurface *surface);
338 
339 
340 G_END_DECLS
341 
342 #endif /* __GDK_SURFACE_PRIVATE_H__ */
343