3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 2005-2007 Imendio AB
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 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
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include <Carbon/Carbon.h>
26 #include "gdkdeviceprivate.h"
27 #include "gdkwindowimpl.h"
28 #include "gdkprivate-quartz.h"
29 #include "gdkscreen-quartz.h"
30 #include "gdkinputprivate.h"
33 #include <cairo-quartz.h>
35 static gpointer parent_class;
36 static gpointer root_window_parent_class;
38 static GSList *update_nswindows;
39 static gboolean in_process_all_updates = FALSE;
41 static GSList *main_window_stack;
43 void _gdk_quartz_window_flush (GdkWindowImplQuartz *window_impl);
45 #define FULLSCREEN_DATA "fullscreen-data"
51 GdkWMDecoration decor;
52 } FullscreenSavedGeometry;
55 static void update_toplevel_order (void);
56 static void clear_toplevel_order (void);
58 static FullscreenSavedGeometry *get_fullscreen_geometry (GdkWindow *window);
60 #define WINDOW_IS_TOPLEVEL(window) \
61 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
62 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \
63 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
66 gdk_quartz_window_get_nsview (GdkWindow *window)
68 if (GDK_WINDOW_DESTROYED (window))
71 return ((GdkWindowImplQuartz *)window->impl)->view;
75 gdk_quartz_window_get_nswindow (GdkWindow *window)
77 if (GDK_WINDOW_DESTROYED (window))
80 return ((GdkWindowImplQuartz *)window->impl)->toplevel;
84 gdk_window_impl_quartz_get_context (GdkWindowImplQuartz *window_impl,
87 CGContextRef cg_context;
89 if (GDK_WINDOW_DESTROYED (window_impl->wrapper))
92 /* Lock focus when not called as part of a drawRect call. This
93 * is needed when called from outside "real" expose events, for
94 * example for synthesized expose events when realizing windows
95 * and for widgets that send fake expose events like the arrow
96 * buttons in spinbuttons or the position marker in rulers.
98 if (window_impl->in_paint_rect_count == 0)
100 if (![window_impl->view lockFocusIfCanDraw])
104 cg_context = [[NSGraphicsContext currentContext] graphicsPort];
105 CGContextSaveGState (cg_context);
106 CGContextSetAllowsAntialiasing (cg_context, antialias);
108 /* We'll emulate the clipping caused by double buffering here */
109 if (window_impl->begin_paint_count != 0)
115 n_rects = cairo_region_num_rectangles (window_impl->paint_clip_region);
120 cg_rects = g_new (CGRect, n_rects);
122 for (i = 0; i < n_rects; i++)
124 cairo_rectangle_int_t cairo_rect;
125 cairo_region_get_rectangle (window_impl->paint_clip_region,
127 cg_rects[i].origin.x = cairo_rect.x;
128 cg_rects[i].origin.y = cairo_rect.y;
129 cg_rects[i].size.width = cairo_rect.width;
130 cg_rects[i].size.height = cairo_rect.height;
133 CGContextClipToRects (cg_context, cg_rects, n_rects);
135 if (cg_rects != &rect)
143 gdk_window_impl_quartz_release_context (GdkWindowImplQuartz *window_impl,
144 CGContextRef cg_context)
146 CGContextRestoreGState (cg_context);
147 CGContextSetAllowsAntialiasing (cg_context, TRUE);
149 /* See comment in gdk_quartz_window_get_context(). */
150 if (window_impl->in_paint_rect_count == 0)
152 _gdk_quartz_window_flush (window_impl);
153 [window_impl->view unlockFocus];
158 check_grab_unmap (GdkWindow *window)
161 GdkDisplay *display = gdk_window_get_display (window);
162 GdkDeviceManager *device_manager;
164 device_manager = gdk_display_get_device_manager (display);
165 list = gdk_device_manager_list_devices (device_manager,
166 GDK_DEVICE_TYPE_FLOATING);
167 for (l = list; l; l = l->next)
169 _gdk_display_end_device_grab (display, l->data, 0, window, TRUE);
176 check_grab_destroy (GdkWindow *window)
179 GdkDisplay *display = gdk_window_get_display (window);
180 GdkDeviceManager *device_manager;
182 /* Make sure there is no lasting grab in this native window */
183 device_manager = gdk_display_get_device_manager (display);
184 list = gdk_device_manager_list_devices (device_manager,
185 GDK_DEVICE_TYPE_MASTER);
187 for (l = list; l; l = l->next)
189 GdkDeviceGrabInfo *grab;
191 grab = _gdk_display_get_last_device_grab (display, l->data);
192 if (grab && grab->native_window == window)
194 /* Serials are always 0 in quartz, but for clarity: */
195 grab->serial_end = grab->serial_start;
196 grab->implicit_ungrab = TRUE;
204 gdk_window_impl_quartz_finalize (GObject *object)
206 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (object);
208 check_grab_destroy (GDK_WINDOW_IMPL_QUARTZ (object)->wrapper);
210 if (impl->paint_clip_region)
211 cairo_region_destroy (impl->paint_clip_region);
213 if (impl->transient_for)
214 g_object_unref (impl->transient_for);
216 G_OBJECT_CLASS (parent_class)->finalize (object);
219 /* Help preventing "beam sync penalty" where CG makes all graphics code
220 * block until the next vsync if we try to flush (including call display on
221 * a view) too often. We do this by limiting the manual flushing done
222 * outside of expose calls to less than some frequency when measured over
223 * the last 4 flushes. This is a bit arbitray, but seems to make it possible
224 * for some quick manual flushes (such as gtkruler or gimp's marching ants)
225 * without hitting the max flush frequency.
227 * If drawable NULL, no flushing is done, only registering that a flush was
231 _gdk_quartz_window_flush (GdkWindowImplQuartz *window_impl)
233 static struct timeval prev_tv;
234 static gint intervals[4];
239 gettimeofday (&tv, NULL);
240 ms = (tv.tv_sec - prev_tv.tv_sec) * 1000 + (tv.tv_usec - prev_tv.tv_usec) / 1000;
241 intervals[index++ % 4] = ms;
245 ms = intervals[0] + intervals[1] + intervals[2] + intervals[3];
247 /* ~25Hz on average. */
251 [window_impl->toplevel flushWindow];
260 static cairo_user_data_key_t gdk_quartz_cairo_key;
263 GdkWindowImplQuartz *window_impl;
264 CGContextRef cg_context;
265 } GdkQuartzCairoSurfaceData;
268 gdk_quartz_cairo_surface_destroy (void *data)
270 GdkQuartzCairoSurfaceData *surface_data = data;
272 surface_data->window_impl->cairo_surface = NULL;
274 gdk_quartz_window_release_context (surface_data->window_impl,
275 surface_data->cg_context);
277 g_free (surface_data);
280 static cairo_surface_t *
281 gdk_quartz_create_cairo_surface (GdkWindowImplQuartz *impl,
285 CGContextRef cg_context;
286 GdkQuartzCairoSurfaceData *surface_data;
287 cairo_surface_t *surface;
289 cg_context = gdk_quartz_window_get_context (impl, TRUE);
294 surface_data = g_new (GdkQuartzCairoSurfaceData, 1);
295 surface_data->window_impl = impl;
296 surface_data->cg_context = cg_context;
298 surface = cairo_quartz_surface_create_for_cg_context (cg_context,
301 cairo_surface_set_user_data (surface, &gdk_quartz_cairo_key,
303 gdk_quartz_cairo_surface_destroy);
308 static cairo_surface_t *
309 gdk_quartz_ref_cairo_surface (GdkWindow *window)
311 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
313 if (GDK_WINDOW_DESTROYED (window))
316 if (!impl->cairo_surface)
318 impl->cairo_surface =
319 gdk_quartz_create_cairo_surface (impl,
320 gdk_window_get_width (impl->wrapper),
321 gdk_window_get_height (impl->wrapper));
324 cairo_surface_reference (impl->cairo_surface);
326 return impl->cairo_surface;
330 gdk_window_impl_quartz_init (GdkWindowImplQuartz *impl)
332 impl->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
336 gdk_window_impl_quartz_begin_paint_region (GdkPaintable *paintable,
338 const cairo_region_t *region)
340 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (paintable);
341 cairo_region_t *clipped_and_offset_region;
344 clipped_and_offset_region = cairo_region_copy (region);
346 cairo_region_intersect (clipped_and_offset_region,
347 window->clip_region_with_children);
348 cairo_region_translate (clipped_and_offset_region,
349 window->abs_x, window->abs_y);
351 if (impl->begin_paint_count == 0)
352 impl->paint_clip_region = cairo_region_reference (clipped_and_offset_region);
354 cairo_region_union (impl->paint_clip_region, clipped_and_offset_region);
356 impl->begin_paint_count++;
358 if (cairo_region_is_empty (clipped_and_offset_region))
361 cr = gdk_cairo_create (window);
363 cairo_translate (cr, -window->abs_x, -window->abs_y);
365 gdk_cairo_region (cr, clipped_and_offset_region);
368 while (window->background == NULL && window->parent)
370 cairo_translate (cr, -window->x, window->y);
371 window = window->parent;
374 if (window->background)
375 cairo_set_source (cr, window->background);
377 cairo_set_source_rgba (cr, 0, 0, 0, 0);
379 /* Can use cairo_paint() here, we clipped above */
385 cairo_region_destroy (clipped_and_offset_region);
389 gdk_window_impl_quartz_end_paint (GdkPaintable *paintable)
391 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (paintable);
393 impl->begin_paint_count--;
395 if (impl->begin_paint_count == 0)
397 cairo_region_destroy (impl->paint_clip_region);
398 impl->paint_clip_region = NULL;
403 _gdk_quartz_window_set_needs_display_in_region (GdkWindow *window,
404 cairo_region_t *region)
406 GdkWindowImplQuartz *impl;
409 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
411 if (!impl->needs_display_region)
412 impl->needs_display_region = cairo_region_create ();
414 cairo_region_union (impl->needs_display_region, region);
416 n_rects = cairo_region_num_rectangles (region);
417 for (i = 0; i < n_rects; i++)
419 cairo_rectangle_int_t rect;
420 cairo_region_get_rectangle (region, i, &rect);
421 [impl->view setNeedsDisplayInRect:NSMakeRect (rect.x, rect.y,
422 rect.width, rect.height)];
427 _gdk_windowing_window_process_updates_recurse (GdkWindow *window,
428 cairo_region_t *region)
430 /* Make sure to only flush each toplevel at most once if we're called
431 * from process_all_updates.
433 if (in_process_all_updates)
437 toplevel = gdk_window_get_effective_toplevel (window);
438 if (toplevel && WINDOW_IS_TOPLEVEL (toplevel))
440 GdkWindowImplQuartz *toplevel_impl;
443 toplevel_impl = (GdkWindowImplQuartz *)toplevel->impl;
444 nswindow = toplevel_impl->toplevel;
446 /* In theory, we could skip the flush disabling, since we only
449 if (nswindow && ![nswindow isFlushWindowDisabled])
452 [nswindow disableFlushWindow];
453 update_nswindows = g_slist_prepend (update_nswindows, nswindow);
458 if (WINDOW_IS_TOPLEVEL (window))
459 _gdk_quartz_window_set_needs_display_in_region (window, region);
461 _gdk_window_process_updates_recurse (window, region);
463 /* NOTE: I'm not sure if we should displayIfNeeded here. It slows down a
464 * lot (since it triggers the beam syncing) and things seem to work
470 _gdk_windowing_before_process_all_updates (void)
472 in_process_all_updates = TRUE;
474 NSDisableScreenUpdates ();
478 _gdk_windowing_after_process_all_updates (void)
480 GSList *old_update_nswindows = update_nswindows;
481 GSList *tmp_list = update_nswindows;
483 update_nswindows = NULL;
487 NSWindow *nswindow = tmp_list->data;
489 [[nswindow contentView] displayIfNeeded];
491 _gdk_quartz_window_flush (NULL);
493 [nswindow enableFlushWindow];
494 [nswindow flushWindow];
497 tmp_list = tmp_list->next;
500 g_slist_free (old_update_nswindows);
502 in_process_all_updates = FALSE;
504 NSEnableScreenUpdates ();
508 gdk_window_impl_quartz_paintable_init (GdkPaintableIface *iface)
510 iface->begin_paint_region = gdk_window_impl_quartz_begin_paint_region;
511 iface->end_paint = gdk_window_impl_quartz_end_paint;
515 get_default_title (void)
519 title = g_get_application_name ();
521 title = g_get_prgname ();
527 get_ancestor_coordinates_from_child (GdkWindow *child_window,
530 GdkWindow *ancestor_window,
534 while (child_window != ancestor_window)
536 child_x += child_window->x;
537 child_y += child_window->y;
539 child_window = child_window->parent;
542 *ancestor_x = child_x;
543 *ancestor_y = child_y;
547 _gdk_quartz_window_debug_highlight (GdkWindow *window, gint number)
553 static NSWindow *debug_window[10];
554 static NSRect old_rect[10];
558 g_return_if_fail (number >= 0 && number <= 9);
560 if (window == _gdk_root)
565 if (debug_window[number])
566 [debug_window[number] close];
567 debug_window[number] = NULL;
572 toplevel = gdk_window_get_toplevel (window);
573 get_ancestor_coordinates_from_child (window, 0, 0, toplevel, &x, &y);
575 gdk_window_get_origin (toplevel, &tx, &ty);
579 _gdk_quartz_window_gdk_xy_to_xy (x, y + window->height,
582 rect = NSMakeRect (gx, gy, window->width, window->height);
584 if (debug_window[number] && NSEqualRects (rect, old_rect[number]))
587 old_rect[number] = rect;
589 if (debug_window[number])
590 [debug_window[number] close];
592 debug_window[number] = [[NSWindow alloc] initWithContentRect:rect
593 styleMask:NSBorderlessWindowMask
594 backing:NSBackingStoreBuffered
600 color = [NSColor redColor];
603 color = [NSColor blueColor];
606 color = [NSColor greenColor];
609 color = [NSColor yellowColor];
612 color = [NSColor brownColor];
615 color = [NSColor purpleColor];
618 color = [NSColor blackColor];
622 [debug_window[number] setBackgroundColor:color];
623 [debug_window[number] setAlphaValue:0.4];
624 [debug_window[number] setOpaque:NO];
625 [debug_window[number] setReleasedWhenClosed:YES];
626 [debug_window[number] setIgnoresMouseEvents:YES];
627 [debug_window[number] setLevel:NSFloatingWindowLevel];
629 [debug_window[number] orderFront:nil];
633 _gdk_quartz_window_is_ancestor (GdkWindow *ancestor,
636 if (ancestor == NULL || window == NULL)
639 return (gdk_window_get_parent (window) == ancestor ||
640 _gdk_quartz_window_is_ancestor (ancestor,
641 gdk_window_get_parent (window)));
645 /* See notes on top of gdkscreen-quartz.c */
647 _gdk_quartz_window_gdk_xy_to_xy (gint gdk_x,
652 GdkScreenQuartz *screen_quartz = GDK_SCREEN_QUARTZ (_gdk_screen);
655 *ns_y = screen_quartz->height - gdk_y + screen_quartz->min_y;
658 *ns_x = gdk_x + screen_quartz->min_x;
662 _gdk_quartz_window_xy_to_gdk_xy (gint ns_x,
667 GdkScreenQuartz *screen_quartz = GDK_SCREEN_QUARTZ (_gdk_screen);
670 *gdk_y = screen_quartz->height - ns_y + screen_quartz->min_y;
673 *gdk_x = ns_x - screen_quartz->min_x;
677 _gdk_quartz_window_nspoint_to_gdk_xy (NSPoint point,
681 _gdk_quartz_window_xy_to_gdk_xy (point.x, point.y,
686 find_child_window_helper (GdkWindow *window,
691 gboolean get_toplevel)
693 GdkWindowImplQuartz *impl;
696 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
698 if (window == _gdk_root)
699 update_toplevel_order ();
701 for (l = impl->sorted_children; l; l = l->next)
703 GdkWindow *child = l->data;
704 GdkWindowImplQuartz *child_impl = GDK_WINDOW_IMPL_QUARTZ (child->impl);
707 if (!GDK_WINDOW_IS_MAPPED (child))
710 temp_x = x_offset + child->x;
711 temp_y = y_offset + child->y;
713 /* Special-case the root window. We have to include the title
714 * bar in the checks, otherwise the window below the title bar
715 * will be found i.e. events punch through. (If we can find a
716 * better way to deal with the events in gdkevents-quartz, this
717 * might not be needed.)
719 if (window == _gdk_root)
721 NSRect frame = NSMakeRect (0, 0, 100, 100);
726 mask = [child_impl->toplevel styleMask];
728 /* Get the title bar height. */
729 content = [NSWindow contentRectForFrameRect:frame
731 titlebar_height = frame.size.height - content.size.height;
733 if (titlebar_height > 0 &&
734 x >= temp_x && y >= temp_y - titlebar_height &&
735 x < temp_x + child->width && y < temp_y)
737 /* The root means "unknown" i.e. a window not managed by
740 return (GdkWindow *)_gdk_root;
744 if ((!get_toplevel || (get_toplevel && window == _gdk_root)) &&
745 x >= temp_x && y >= temp_y &&
746 x < temp_x + child->width && y < temp_y + child->height)
748 /* Look for child windows. */
749 return find_child_window_helper (l->data,
759 /* Given a GdkWindow and coordinates relative to it, returns the
760 * innermost subwindow that contains the point. If the coordinates are
761 * outside the passed in window, NULL is returned.
764 _gdk_quartz_window_find_child (GdkWindow *window,
767 gboolean get_toplevel)
769 if (x >= 0 && y >= 0 && x < window->width && y < window->height)
770 return find_child_window_helper (window, x, y, 0, 0, get_toplevel);
777 _gdk_quartz_window_did_become_main (GdkWindow *window)
779 main_window_stack = g_slist_remove (main_window_stack, window);
781 if (window->window_type != GDK_WINDOW_TEMP)
782 main_window_stack = g_slist_prepend (main_window_stack, window);
784 clear_toplevel_order ();
788 _gdk_quartz_window_did_resign_main (GdkWindow *window)
790 GdkWindow *new_window = NULL;
792 if (main_window_stack)
793 new_window = main_window_stack->data;
798 toplevels = gdk_screen_get_toplevel_windows (gdk_screen_get_default ());
800 new_window = toplevels->data;
801 g_list_free (toplevels);
805 new_window != window &&
806 GDK_WINDOW_IS_MAPPED (new_window) &&
807 WINDOW_IS_TOPLEVEL (new_window))
809 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (new_window->impl);
811 [impl->toplevel makeKeyAndOrderFront:impl->toplevel];
814 clear_toplevel_order ();
818 get_nsscreen_for_point (gint x, gint y)
822 NSScreen *screen = NULL;
824 GDK_QUARTZ_ALLOC_POOL;
826 screens = [NSScreen screens];
828 for (i = 0; i < [screens count]; i++)
830 NSRect rect = [[screens objectAtIndex:i] frame];
832 if (x >= rect.origin.x && x <= rect.origin.x + rect.size.width &&
833 y >= rect.origin.y && y <= rect.origin.y + rect.size.height)
835 screen = [screens objectAtIndex:i];
840 GDK_QUARTZ_RELEASE_POOL;
846 _gdk_window_impl_new (GdkWindow *window,
847 GdkWindow *real_parent,
849 GdkEventMask event_mask,
850 GdkWindowAttr *attributes,
851 gint attributes_mask)
853 GdkWindowImplQuartz *impl;
854 GdkWindowImplQuartz *parent_impl;
856 GDK_QUARTZ_ALLOC_POOL;
858 impl = g_object_new (GDK_TYPE_WINDOW_IMPL_QUARTZ, NULL);
859 window->impl = GDK_WINDOW_IMPL (impl);
860 impl->wrapper = window;
862 parent_impl = GDK_WINDOW_IMPL_QUARTZ (window->parent->impl);
864 switch (window->window_type)
866 case GDK_WINDOW_TOPLEVEL:
867 case GDK_WINDOW_TEMP:
868 if (GDK_WINDOW_TYPE (window->parent) != GDK_WINDOW_ROOT)
870 /* The common code warns for this case */
871 parent_impl = GDK_WINDOW_IMPL_QUARTZ (_gdk_root->impl);
875 /* Maintain the z-ordered list of children. */
876 if (window->parent != _gdk_root)
877 parent_impl->sorted_children = g_list_prepend (parent_impl->sorted_children, window);
879 clear_toplevel_order ();
881 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
882 (attributes->cursor) :
887 switch (attributes->window_type)
889 case GDK_WINDOW_TOPLEVEL:
890 case GDK_WINDOW_TEMP:
895 NSUInteger style_mask;
899 /* initWithContentRect will place on the mainScreen by default.
900 * We want to select the screen to place on ourselves. We need
901 * to find the screen the window will be on and correct the
902 * content_rect coordinates to be relative to that screen.
904 _gdk_quartz_window_gdk_xy_to_xy (window->x, window->y, &nx, &ny);
906 screen = get_nsscreen_for_point (nx, ny);
907 screen_rect = [screen frame];
908 nx -= screen_rect.origin.x;
909 ny -= screen_rect.origin.y;
911 content_rect = NSMakeRect (nx, ny - window->height,
915 if (attributes->window_type == GDK_WINDOW_TEMP ||
916 attributes->type_hint == GDK_WINDOW_TYPE_HINT_SPLASHSCREEN)
918 style_mask = NSBorderlessWindowMask;
922 style_mask = (NSTitledWindowMask |
923 NSClosableWindowMask |
924 NSMiniaturizableWindowMask |
925 NSResizableWindowMask);
928 impl->toplevel = [[GdkQuartzWindow alloc] initWithContentRect:content_rect
930 backing:NSBackingStoreBuffered
934 if (attributes_mask & GDK_WA_TITLE)
935 title = attributes->title;
937 title = get_default_title ();
939 gdk_window_set_title (window, title);
941 if (gdk_window_get_visual (window) == gdk_screen_get_rgba_visual (_gdk_screen))
943 [impl->toplevel setOpaque:NO];
944 [impl->toplevel setBackgroundColor:[NSColor clearColor]];
947 content_rect.origin.x = 0;
948 content_rect.origin.y = 0;
950 impl->view = [[GdkQuartzView alloc] initWithFrame:content_rect];
951 [impl->view setGdkWindow:window];
952 [impl->toplevel setContentView:impl->view];
953 [impl->view release];
957 case GDK_WINDOW_CHILD:
959 GdkWindowImplQuartz *parent_impl = GDK_WINDOW_IMPL_QUARTZ (window->parent->impl);
961 if (!window->input_only)
963 NSRect frame_rect = NSMakeRect (window->x + window->parent->abs_x,
964 window->y + window->parent->abs_y,
968 impl->view = [[GdkQuartzView alloc] initWithFrame:frame_rect];
970 [impl->view setGdkWindow:window];
972 /* GdkWindows should be hidden by default */
973 [impl->view setHidden:YES];
974 [parent_impl->view addSubview:impl->view];
975 [impl->view release];
981 g_assert_not_reached ();
984 GDK_QUARTZ_RELEASE_POOL;
986 if (attributes_mask & GDK_WA_TYPE_HINT)
987 gdk_window_set_type_hint (window, attributes->type_hint);
991 _gdk_quartz_window_update_position (GdkWindow *window)
995 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
997 GDK_QUARTZ_ALLOC_POOL;
999 frame_rect = [impl->toplevel frame];
1000 content_rect = [impl->toplevel contentRectForFrameRect:frame_rect];
1002 _gdk_quartz_window_xy_to_gdk_xy (content_rect.origin.x,
1003 content_rect.origin.y + content_rect.size.height,
1004 &window->x, &window->y);
1007 GDK_QUARTZ_RELEASE_POOL;
1011 _gdk_windowing_update_window_sizes (GdkScreen *screen)
1013 GList *windows, *list;
1015 /* The size of the root window is so that it can contain all
1016 * monitors attached to this machine. The monitors are laid out
1017 * within this root window. We calculate the size of the root window
1018 * and the positions of the different monitors in gdkscreen-quartz.c.
1020 * This data is updated when the monitor configuration is changed.
1024 _gdk_root->abs_x = 0;
1025 _gdk_root->abs_y = 0;
1026 _gdk_root->width = gdk_screen_get_width (screen);
1027 _gdk_root->height = gdk_screen_get_height (screen);
1029 windows = gdk_screen_get_toplevel_windows (screen);
1031 for (list = windows; list; list = list->next)
1032 _gdk_quartz_window_update_position (list->data);
1034 g_list_free (windows);
1038 _gdk_windowing_window_init (void)
1040 GdkWindowImplQuartz *impl;
1042 g_assert (_gdk_root == NULL);
1044 _gdk_root = g_object_new (GDK_TYPE_WINDOW, NULL);
1046 _gdk_root->impl = g_object_new (_gdk_root_window_impl_quartz_get_type (), NULL);
1047 _gdk_root->impl_window = _gdk_root;
1048 _gdk_root->visual = gdk_screen_get_system_visual (_gdk_screen);
1050 impl = GDK_WINDOW_IMPL_QUARTZ (_gdk_root->impl);
1052 _gdk_windowing_update_window_sizes (_gdk_screen);
1054 _gdk_root->state = 0; /* We don't want GDK_WINDOW_STATE_WITHDRAWN here */
1055 _gdk_root->window_type = GDK_WINDOW_ROOT;
1056 _gdk_root->depth = 24;
1057 _gdk_root->viewable = TRUE;
1059 impl->wrapper = _gdk_root;
1063 _gdk_quartz_window_destroy (GdkWindow *window,
1065 gboolean foreign_destroy)
1067 GdkWindowImplQuartz *impl;
1070 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1072 main_window_stack = g_slist_remove (main_window_stack, window);
1074 g_list_free (impl->sorted_children);
1075 impl->sorted_children = NULL;
1077 parent = window->parent;
1080 GdkWindowImplQuartz *parent_impl = GDK_WINDOW_IMPL_QUARTZ (parent->impl);
1082 parent_impl->sorted_children = g_list_remove (parent_impl->sorted_children, window);
1085 if (impl->cairo_surface)
1087 cairo_surface_finish (impl->cairo_surface);
1088 cairo_surface_set_user_data (impl->cairo_surface, &gdk_quartz_cairo_key,
1090 impl->cairo_surface = NULL;
1093 if (!recursing && !foreign_destroy)
1095 GDK_QUARTZ_ALLOC_POOL;
1098 [impl->toplevel close];
1099 else if (impl->view)
1100 [impl->view removeFromSuperview];
1102 GDK_QUARTZ_RELEASE_POOL;
1106 static cairo_surface_t *
1107 gdk_window_quartz_resize_cairo_surface (GdkWindow *window,
1108 cairo_surface_t *surface,
1112 /* Quartz surfaces cannot be resized */
1113 cairo_surface_destroy (surface);
1119 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
1121 /* Foreign windows aren't supported in OSX. */
1124 /* FIXME: This might be possible to simplify with client-side windows. Also
1125 * note that already_mapped is not used yet, see the x11 backend.
1128 gdk_window_quartz_show (GdkWindow *window, gboolean already_mapped)
1130 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1131 gboolean focus_on_map;
1133 GDK_QUARTZ_ALLOC_POOL;
1135 if (!GDK_WINDOW_IS_MAPPED (window))
1136 focus_on_map = window->focus_on_map;
1138 focus_on_map = TRUE;
1140 if (WINDOW_IS_TOPLEVEL (window) && impl->toplevel)
1144 make_key = (window->accept_focus && focus_on_map &&
1145 window->window_type != GDK_WINDOW_TEMP);
1147 [(GdkQuartzWindow*)impl->toplevel showAndMakeKey:make_key];
1148 clear_toplevel_order ();
1150 _gdk_quartz_events_send_map_event (window);
1154 [impl->view setHidden:NO];
1157 [impl->view setNeedsDisplay:YES];
1159 gdk_synthesize_window_state (window, GDK_WINDOW_STATE_WITHDRAWN, 0);
1161 if (window->state & GDK_WINDOW_STATE_MAXIMIZED)
1162 gdk_window_maximize (window);
1164 if (window->state & GDK_WINDOW_STATE_ICONIFIED)
1165 gdk_window_iconify (window);
1167 if (impl->transient_for && !GDK_WINDOW_DESTROYED (impl->transient_for))
1168 _gdk_quartz_window_attach_to_parent (window);
1170 GDK_QUARTZ_RELEASE_POOL;
1173 /* Temporarily unsets the parent window, if the window is a
1177 _gdk_quartz_window_detach_from_parent (GdkWindow *window)
1179 GdkWindowImplQuartz *impl;
1181 g_return_if_fail (GDK_IS_WINDOW (window));
1183 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1185 g_return_if_fail (impl->toplevel != NULL);
1187 if (impl->transient_for && !GDK_WINDOW_DESTROYED (impl->transient_for))
1189 GdkWindowImplQuartz *parent_impl;
1191 parent_impl = GDK_WINDOW_IMPL_QUARTZ (impl->transient_for->impl);
1192 [parent_impl->toplevel removeChildWindow:impl->toplevel];
1193 clear_toplevel_order ();
1197 /* Re-sets the parent window, if the window is a transient. */
1199 _gdk_quartz_window_attach_to_parent (GdkWindow *window)
1201 GdkWindowImplQuartz *impl;
1203 g_return_if_fail (GDK_IS_WINDOW (window));
1205 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1207 g_return_if_fail (impl->toplevel != NULL);
1209 if (impl->transient_for && !GDK_WINDOW_DESTROYED (impl->transient_for))
1211 GdkWindowImplQuartz *parent_impl;
1213 parent_impl = GDK_WINDOW_IMPL_QUARTZ (impl->transient_for->impl);
1214 [parent_impl->toplevel addChildWindow:impl->toplevel ordered:NSWindowAbove];
1215 clear_toplevel_order ();
1220 gdk_window_quartz_hide (GdkWindow *window)
1222 GdkWindowImplQuartz *impl;
1224 /* Make sure we're not stuck in fullscreen mode. */
1225 if (get_fullscreen_geometry (window))
1226 SetSystemUIMode (kUIModeNormal, 0);
1228 check_grab_unmap (window);
1230 _gdk_window_clear_update_area (window);
1232 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1234 if (WINDOW_IS_TOPLEVEL (window))
1236 /* Update main window. */
1237 main_window_stack = g_slist_remove (main_window_stack, window);
1238 if ([NSApp mainWindow] == impl->toplevel)
1239 _gdk_quartz_window_did_resign_main (window);
1241 if (impl->transient_for)
1242 _gdk_quartz_window_detach_from_parent (window);
1244 [(GdkQuartzWindow*)impl->toplevel hide];
1246 else if (impl->view)
1248 [impl->view setHidden:YES];
1253 gdk_window_quartz_withdraw (GdkWindow *window)
1255 gdk_window_hide (window);
1259 move_resize_window_internal (GdkWindow *window,
1265 GdkWindowImplQuartz *impl;
1266 GdkRectangle old_visible;
1267 GdkRectangle new_visible;
1268 GdkRectangle scroll_rect;
1269 cairo_region_t *old_region;
1270 cairo_region_t *expose_region;
1273 if (GDK_WINDOW_DESTROYED (window))
1276 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1278 if ((x == -1 || (x == window->x)) &&
1279 (y == -1 || (y == window->y)) &&
1280 (width == -1 || (width == window->width)) &&
1281 (height == -1 || (height == window->height)))
1286 if (!impl->toplevel)
1288 /* The previously visible area of this window in a coordinate
1289 * system rooted at the origin of this window.
1291 old_visible.x = -window->x;
1292 old_visible.y = -window->y;
1294 old_visible.width = window->width;
1295 old_visible.height = window->height;
1300 delta.width = x - window->x;
1310 delta.height = y - window->y;
1319 window->width = width;
1322 window->height = height;
1324 GDK_QUARTZ_ALLOC_POOL;
1328 NSRect content_rect;
1332 _gdk_quartz_window_gdk_xy_to_xy (window->x, window->y + window->height,
1335 content_rect = NSMakeRect (gx, gy, window->width, window->height);
1337 frame_rect = [impl->toplevel frameRectForContentRect:content_rect];
1338 [impl->toplevel setFrame:frame_rect display:YES];
1342 if (!window->input_only)
1346 nsrect = NSMakeRect (window->x, window->y, window->width, window->height);
1348 /* The newly visible area of this window in a coordinate
1349 * system rooted at the origin of this window.
1351 new_visible.x = -window->x;
1352 new_visible.y = -window->y;
1353 new_visible.width = old_visible.width; /* parent has not changed size */
1354 new_visible.height = old_visible.height; /* parent has not changed size */
1356 expose_region = cairo_region_create_rectangle (&new_visible);
1357 old_region = cairo_region_create_rectangle (&old_visible);
1358 cairo_region_subtract (expose_region, old_region);
1360 /* Determine what (if any) part of the previously visible
1361 * part of the window can be copied without a redraw
1363 scroll_rect = old_visible;
1364 scroll_rect.x -= delta.width;
1365 scroll_rect.y -= delta.height;
1366 gdk_rectangle_intersect (&scroll_rect, &old_visible, &scroll_rect);
1368 if (!cairo_region_is_empty (expose_region))
1370 if (scroll_rect.width != 0 && scroll_rect.height != 0)
1372 [impl->view scrollRect:NSMakeRect (scroll_rect.x,
1379 [impl->view setFrame:nsrect];
1381 _gdk_quartz_window_set_needs_display_in_region (window, expose_region);
1385 [impl->view setFrame:nsrect];
1386 [impl->view setNeedsDisplay:YES];
1389 cairo_region_destroy (expose_region);
1390 cairo_region_destroy (old_region);
1394 GDK_QUARTZ_RELEASE_POOL;
1398 window_quartz_move (GdkWindow *window,
1402 g_return_if_fail (GDK_IS_WINDOW (window));
1404 if (window->state & GDK_WINDOW_STATE_FULLSCREEN)
1407 move_resize_window_internal (window, x, y, -1, -1);
1411 window_quartz_resize (GdkWindow *window,
1415 g_return_if_fail (GDK_IS_WINDOW (window));
1417 if (window->state & GDK_WINDOW_STATE_FULLSCREEN)
1425 move_resize_window_internal (window, -1, -1, width, height);
1429 window_quartz_move_resize (GdkWindow *window,
1440 move_resize_window_internal (window, x, y, width, height);
1444 gdk_window_quartz_move_resize (GdkWindow *window,
1451 if (with_move && (width < 0 && height < 0))
1452 window_quartz_move (window, x, y);
1456 window_quartz_move_resize (window, x, y, width, height);
1458 window_quartz_resize (window, width, height);
1462 /* FIXME: This might need fixing (reparenting didn't work before client-side
1466 gdk_window_quartz_reparent (GdkWindow *window,
1467 GdkWindow *new_parent,
1471 GdkWindow *old_parent;
1472 GdkWindowImplQuartz *impl, *old_parent_impl, *new_parent_impl;
1473 NSView *view, *new_parent_view;
1475 if (new_parent == _gdk_root)
1477 /* Could be added, just needs implementing. */
1478 g_warning ("Reparenting to root window is not supported yet in the Mac OS X backend");
1482 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1485 new_parent_impl = GDK_WINDOW_IMPL_QUARTZ (new_parent->impl);
1486 new_parent_view = new_parent_impl->view;
1488 old_parent = window->parent;
1489 old_parent_impl = GDK_WINDOW_IMPL_QUARTZ (old_parent->impl);
1493 [view removeFromSuperview];
1494 [new_parent_view addSubview:view];
1498 window->parent = new_parent;
1502 old_parent_impl->sorted_children = g_list_remove (old_parent_impl->sorted_children, window);
1505 new_parent_impl->sorted_children = g_list_prepend (new_parent_impl->sorted_children, window);
1510 /* Get the toplevel ordering from NSApp and update our own list. We do
1511 * this on demand since the NSApp's list is not up to date directly
1512 * after we get windowDidBecomeMain.
1515 update_toplevel_order (void)
1517 GdkWindowImplQuartz *root_impl;
1518 NSEnumerator *enumerator;
1520 GList *toplevels = NULL;
1522 root_impl = GDK_WINDOW_IMPL_QUARTZ (_gdk_root->impl);
1524 if (root_impl->sorted_children)
1527 GDK_QUARTZ_ALLOC_POOL;
1529 enumerator = [[NSApp orderedWindows] objectEnumerator];
1530 while ((nswindow = [enumerator nextObject]))
1534 if (![[nswindow contentView] isKindOfClass:[GdkQuartzView class]])
1537 window = [(GdkQuartzView *)[nswindow contentView] gdkWindow];
1538 toplevels = g_list_prepend (toplevels, window);
1541 GDK_QUARTZ_RELEASE_POOL;
1543 root_impl->sorted_children = g_list_reverse (toplevels);
1547 clear_toplevel_order (void)
1549 GdkWindowImplQuartz *root_impl;
1551 root_impl = GDK_WINDOW_IMPL_QUARTZ (_gdk_root->impl);
1553 g_list_free (root_impl->sorted_children);
1554 root_impl->sorted_children = NULL;
1558 gdk_window_quartz_raise (GdkWindow *window)
1560 if (GDK_WINDOW_DESTROYED (window))
1563 if (WINDOW_IS_TOPLEVEL (window))
1565 GdkWindowImplQuartz *impl;
1567 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1568 [impl->toplevel orderFront:impl->toplevel];
1570 clear_toplevel_order ();
1574 GdkWindow *parent = window->parent;
1578 GdkWindowImplQuartz *impl;
1580 impl = (GdkWindowImplQuartz *)parent->impl;
1582 impl->sorted_children = g_list_remove (impl->sorted_children, window);
1583 impl->sorted_children = g_list_prepend (impl->sorted_children, window);
1589 gdk_window_quartz_lower (GdkWindow *window)
1591 if (GDK_WINDOW_DESTROYED (window))
1594 if (WINDOW_IS_TOPLEVEL (window))
1596 GdkWindowImplQuartz *impl;
1598 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1599 [impl->toplevel orderBack:impl->toplevel];
1601 clear_toplevel_order ();
1605 GdkWindow *parent = window->parent;
1609 GdkWindowImplQuartz *impl;
1611 impl = (GdkWindowImplQuartz *)parent->impl;
1613 impl->sorted_children = g_list_remove (impl->sorted_children, window);
1614 impl->sorted_children = g_list_append (impl->sorted_children, window);
1620 gdk_window_quartz_restack_toplevel (GdkWindow *window,
1624 /* FIXME: Implement this */
1628 gdk_window_quartz_set_background (GdkWindow *window,
1629 cairo_pattern_t *pattern)
1631 /* FIXME: We could theoretically set the background color for toplevels
1632 * here. (Currently we draw the background before emitting expose events)
1637 gdk_window_quartz_set_device_cursor (GdkWindow *window,
1641 GdkCursorPrivate *cursor_private;
1644 cursor_private = (GdkCursorPrivate *)cursor;
1646 if (GDK_WINDOW_DESTROYED (window))
1650 nscursor = [NSCursor arrowCursor];
1652 nscursor = cursor_private->nscursor;
1658 gdk_window_quartz_get_geometry (GdkWindow *window,
1664 GdkWindowImplQuartz *impl;
1667 if (GDK_WINDOW_DESTROYED (window))
1670 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1671 if (window == _gdk_root)
1679 *width = window->width;
1681 *height = window->height;
1683 else if (WINDOW_IS_TOPLEVEL (window))
1685 ns_rect = [impl->toplevel contentRectForFrameRect:[impl->toplevel frame]];
1687 /* This doesn't work exactly as in X. There doesn't seem to be a
1688 * way to get the coords relative to the parent window (usually
1689 * the window frame), but that seems useless except for
1690 * borderless windows where it's relative to the root window. So
1691 * we return (0, 0) (should be something like (0, 22)) for
1692 * windows with borders and the root relative coordinates
1695 if ([impl->toplevel styleMask] == NSBorderlessWindowMask)
1697 _gdk_quartz_window_xy_to_gdk_xy (ns_rect.origin.x,
1698 ns_rect.origin.y + ns_rect.size.height,
1710 *width = ns_rect.size.width;
1712 *height = ns_rect.size.height;
1716 ns_rect = [impl->view frame];
1719 *x = ns_rect.origin.x;
1721 *y = ns_rect.origin.y;
1723 *width = ns_rect.size.width;
1725 *height = ns_rect.size.height;
1730 gdk_window_quartz_get_root_coords (GdkWindow *window,
1736 int tmp_x = 0, tmp_y = 0;
1737 GdkWindow *toplevel;
1738 NSRect content_rect;
1739 GdkWindowImplQuartz *impl;
1741 if (GDK_WINDOW_DESTROYED (window))
1751 if (window == _gdk_root)
1761 toplevel = gdk_window_get_toplevel (window);
1762 impl = GDK_WINDOW_IMPL_QUARTZ (toplevel->impl);
1764 content_rect = [impl->toplevel contentRectForFrameRect:[impl->toplevel frame]];
1766 _gdk_quartz_window_xy_to_gdk_xy (content_rect.origin.x,
1767 content_rect.origin.y + content_rect.size.height,
1773 while (window != toplevel)
1775 if (_gdk_window_has_impl ((GdkWindow *)window))
1781 window = window->parent;
1793 gdk_window_get_root_origin (GdkWindow *window,
1802 gdk_window_get_frame_extents (window, &rect);
1811 /* Returns coordinates relative to the passed in window. */
1813 gdk_window_quartz_get_device_state_helper (GdkWindow *window,
1817 GdkModifierType *mask)
1821 GdkWindow *toplevel;
1822 GdkWindow *found_window;
1824 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
1826 if (GDK_WINDOW_DESTROYED (window))
1834 toplevel = gdk_window_get_toplevel (window);
1836 *mask = _gdk_quartz_events_get_current_event_mask ();
1838 /* Get the y coordinate, needs to be flipped. */
1839 if (window == _gdk_root)
1841 point = [NSEvent mouseLocation];
1842 _gdk_quartz_window_nspoint_to_gdk_xy (point, &x_tmp, &y_tmp);
1846 GdkWindowImplQuartz *impl;
1849 impl = GDK_WINDOW_IMPL_QUARTZ (toplevel->impl);
1850 nswindow = impl->toplevel;
1852 point = [nswindow mouseLocationOutsideOfEventStream];
1855 y_tmp = toplevel->height - point.y;
1857 window = (GdkWindow *)toplevel;
1860 found_window = _gdk_quartz_window_find_child (window, x_tmp, y_tmp,
1863 /* We never return the root window. */
1864 if (found_window == _gdk_root)
1865 found_window = NULL;
1870 return found_window;
1874 gdk_window_quartz_get_device_state (GdkWindow *window,
1878 GdkModifierType *mask)
1880 return gdk_window_quartz_get_device_state_helper (window,
1882 x, y, mask) != NULL;
1885 /* Returns coordinates relative to the root. */
1887 _gdk_windowing_get_device_state (GdkDisplay *display,
1892 GdkModifierType *mask)
1894 g_return_if_fail (display == _gdk_display);
1896 *screen = _gdk_screen;
1897 gdk_window_quartz_get_device_state_helper (_gdk_root, device, x, y, mask);
1901 gdk_display_warp_pointer (GdkDisplay *display,
1906 CGDisplayMoveCursorToPoint (CGMainDisplayID (), CGPointMake (x, y));
1909 /* Returns coordinates relative to the found window. */
1911 _gdk_windowing_window_at_pointer (GdkDisplay *display,
1914 GdkModifierType *mask,
1915 gboolean get_toplevel)
1917 GdkWindow *found_window;
1919 GdkModifierType tmp_mask = 0;
1921 found_window = gdk_window_quartz_get_device_state_helper (_gdk_root,
1922 display->core_pointer,
1927 /* The coordinates returned above are relative the root, we want
1928 * coordinates relative the window here.
1930 while (found_window != _gdk_root)
1932 x -= found_window->x;
1933 y -= found_window->y;
1935 found_window = found_window->parent;
1943 /* Mimic the X backend here, -1,-1 for unknown windows. */
1953 /* Requested toplevel, find it. */
1954 /* TODO: This can be implemented more efficient by never
1955 recursing into children in the first place */
1958 /* Convert to toplevel */
1959 while (found_window->parent != NULL &&
1960 found_window->parent->window_type != GDK_WINDOW_ROOT)
1962 *win_x += found_window->x;
1963 *win_y += found_window->y;
1964 found_window = found_window->parent;
1969 return found_window;
1973 _gdk_windowing_window_at_device_position (GdkDisplay *display,
1977 GdkModifierType *mask,
1978 gboolean get_toplevel)
1980 return GDK_DEVICE_GET_CLASS (device)->window_at_position (device,
1988 gdk_window_quartz_get_events (GdkWindow *window)
1990 if (GDK_WINDOW_DESTROYED (window))
1993 return window->event_mask;
1997 gdk_window_quartz_set_events (GdkWindow *window,
1998 GdkEventMask event_mask)
2000 /* The mask is set in the common code. */
2004 gdk_window_set_urgency_hint (GdkWindow *window,
2007 if (GDK_WINDOW_DESTROYED (window) ||
2008 !WINDOW_IS_TOPLEVEL (window))
2011 /* FIXME: Implement */
2015 gdk_window_set_geometry_hints (GdkWindow *window,
2016 const GdkGeometry *geometry,
2017 GdkWindowHints geom_mask)
2019 GdkWindowImplQuartz *impl;
2021 g_return_if_fail (geometry != NULL);
2023 if (GDK_WINDOW_DESTROYED (window) ||
2024 !WINDOW_IS_TOPLEVEL (window))
2027 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2028 if (!impl->toplevel)
2031 if (geom_mask & GDK_HINT_POS)
2033 /* FIXME: Implement */
2036 if (geom_mask & GDK_HINT_USER_POS)
2038 /* FIXME: Implement */
2041 if (geom_mask & GDK_HINT_USER_SIZE)
2043 /* FIXME: Implement */
2046 if (geom_mask & GDK_HINT_MIN_SIZE)
2050 size.width = geometry->min_width;
2051 size.height = geometry->min_height;
2053 [impl->toplevel setContentMinSize:size];
2056 if (geom_mask & GDK_HINT_MAX_SIZE)
2060 size.width = geometry->max_width;
2061 size.height = geometry->max_height;
2063 [impl->toplevel setContentMaxSize:size];
2066 if (geom_mask & GDK_HINT_BASE_SIZE)
2068 /* FIXME: Implement */
2071 if (geom_mask & GDK_HINT_RESIZE_INC)
2075 size.width = geometry->width_inc;
2076 size.height = geometry->height_inc;
2078 [impl->toplevel setContentResizeIncrements:size];
2081 if (geom_mask & GDK_HINT_ASPECT)
2083 /* FIXME: Implement */
2086 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2088 /* FIXME: Implement */
2093 gdk_window_set_title (GdkWindow *window,
2096 GdkWindowImplQuartz *impl;
2098 g_return_if_fail (title != NULL);
2100 if (GDK_WINDOW_DESTROYED (window) ||
2101 !WINDOW_IS_TOPLEVEL (window))
2104 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2108 GDK_QUARTZ_ALLOC_POOL;
2109 [impl->toplevel setTitle:[NSString stringWithUTF8String:title]];
2110 GDK_QUARTZ_RELEASE_POOL;
2115 gdk_window_set_role (GdkWindow *window,
2118 if (GDK_WINDOW_DESTROYED (window) ||
2119 WINDOW_IS_TOPLEVEL (window))
2122 /* FIXME: Implement */
2126 gdk_window_set_transient_for (GdkWindow *window,
2129 GdkWindowImplQuartz *window_impl;
2130 GdkWindowImplQuartz *parent_impl;
2132 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (parent) ||
2133 !WINDOW_IS_TOPLEVEL (window))
2136 window_impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2137 if (!window_impl->toplevel)
2140 GDK_QUARTZ_ALLOC_POOL;
2142 if (window_impl->transient_for)
2144 _gdk_quartz_window_detach_from_parent (window);
2146 g_object_unref (window_impl->transient_for);
2147 window_impl->transient_for = NULL;
2150 parent_impl = GDK_WINDOW_IMPL_QUARTZ (parent->impl);
2151 if (parent_impl->toplevel)
2153 /* We save the parent because it needs to be unset/reset when
2154 * hiding and showing the window.
2157 /* We don't set transients for tooltips, they are already
2158 * handled by the window level being the top one. If we do, then
2159 * the parent window will be brought to the top just because the
2160 * tooltip is, which is not what we want.
2162 if (gdk_window_get_type_hint (window) != GDK_WINDOW_TYPE_HINT_TOOLTIP)
2164 window_impl->transient_for = g_object_ref (parent);
2166 /* We only add the window if it is shown, otherwise it will
2167 * be shown unconditionally here. If it is not shown, the
2168 * window will be added in show() instead.
2170 if (!(window->state & GDK_WINDOW_STATE_WITHDRAWN))
2171 _gdk_quartz_window_attach_to_parent (window);
2175 GDK_QUARTZ_RELEASE_POOL;
2179 gdk_window_quartz_shape_combine_region (GdkWindow *window,
2180 const cairo_region_t *shape,
2184 /* FIXME: Implement */
2188 gdk_window_quartz_input_shape_combine_region (GdkWindow *window,
2189 const cairo_region_t *shape_region,
2193 /* FIXME: Implement */
2197 gdk_window_set_override_redirect (GdkWindow *window,
2198 gboolean override_redirect)
2200 /* FIXME: Implement */
2204 gdk_window_set_accept_focus (GdkWindow *window,
2205 gboolean accept_focus)
2207 window->accept_focus = accept_focus != FALSE;
2211 gdk_window_quartz_set_static_gravities (GdkWindow *window,
2212 gboolean use_static)
2214 if (GDK_WINDOW_DESTROYED (window) ||
2215 !WINDOW_IS_TOPLEVEL (window))
2218 /* FIXME: Implement */
2223 gdk_window_set_focus_on_map (GdkWindow *window,
2224 gboolean focus_on_map)
2226 window->focus_on_map = focus_on_map != FALSE;
2230 gdk_window_set_icon_name (GdkWindow *window,
2233 /* FIXME: Implement */
2237 gdk_window_focus (GdkWindow *window,
2240 GdkWindowImplQuartz *impl;
2242 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2244 if (GDK_WINDOW_DESTROYED (window) ||
2245 !WINDOW_IS_TOPLEVEL (window))
2248 if (window->accept_focus && window->window_type != GDK_WINDOW_TEMP)
2250 GDK_QUARTZ_ALLOC_POOL;
2251 [impl->toplevel makeKeyAndOrderFront:impl->toplevel];
2252 clear_toplevel_order ();
2253 GDK_QUARTZ_RELEASE_POOL;
2258 gint window_type_hint_to_level (GdkWindowTypeHint hint)
2262 case GDK_WINDOW_TYPE_HINT_DOCK:
2263 case GDK_WINDOW_TYPE_HINT_UTILITY:
2264 return NSFloatingWindowLevel;
2266 case GDK_WINDOW_TYPE_HINT_MENU: /* Torn-off menu */
2267 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU: /* Menu from menubar */
2268 return NSTornOffMenuWindowLevel;
2270 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
2271 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
2272 return NSStatusWindowLevel;
2274 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
2275 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
2276 case GDK_WINDOW_TYPE_HINT_COMBO:
2277 case GDK_WINDOW_TYPE_HINT_DND:
2278 return NSPopUpMenuWindowLevel;
2280 case GDK_WINDOW_TYPE_HINT_NORMAL: /* Normal toplevel window */
2281 case GDK_WINDOW_TYPE_HINT_DIALOG: /* Dialog window */
2282 case GDK_WINDOW_TYPE_HINT_TOOLBAR: /* Window used to implement toolbars */
2283 case GDK_WINDOW_TYPE_HINT_DESKTOP: /* N/A */
2290 return NSNormalWindowLevel;
2294 window_type_hint_to_shadow (GdkWindowTypeHint hint)
2298 case GDK_WINDOW_TYPE_HINT_NORMAL: /* Normal toplevel window */
2299 case GDK_WINDOW_TYPE_HINT_DIALOG: /* Dialog window */
2300 case GDK_WINDOW_TYPE_HINT_DOCK:
2301 case GDK_WINDOW_TYPE_HINT_UTILITY:
2302 case GDK_WINDOW_TYPE_HINT_MENU: /* Torn-off menu */
2303 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU: /* Menu from menubar */
2304 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
2305 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
2306 case GDK_WINDOW_TYPE_HINT_COMBO:
2307 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
2308 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
2311 case GDK_WINDOW_TYPE_HINT_TOOLBAR: /* Window used to implement toolbars */
2312 case GDK_WINDOW_TYPE_HINT_DESKTOP: /* N/A */
2313 case GDK_WINDOW_TYPE_HINT_DND:
2325 gdk_window_set_type_hint (GdkWindow *window,
2326 GdkWindowTypeHint hint)
2328 GdkWindowImplQuartz *impl;
2330 if (GDK_WINDOW_DESTROYED (window) ||
2331 !WINDOW_IS_TOPLEVEL (window))
2334 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2336 impl->type_hint = hint;
2338 /* Match the documentation, only do something if we're not mapped yet. */
2339 if (GDK_WINDOW_IS_MAPPED (window))
2342 [impl->toplevel setHasShadow: window_type_hint_to_shadow (hint)];
2343 [impl->toplevel setLevel: window_type_hint_to_level (hint)];
2347 gdk_window_get_type_hint (GdkWindow *window)
2349 if (GDK_WINDOW_DESTROYED (window) ||
2350 !WINDOW_IS_TOPLEVEL (window))
2351 return GDK_WINDOW_TYPE_HINT_NORMAL;
2353 return GDK_WINDOW_IMPL_QUARTZ (window->impl)->type_hint;
2357 gdk_window_set_modal_hint (GdkWindow *window,
2360 if (GDK_WINDOW_DESTROYED (window) ||
2361 !WINDOW_IS_TOPLEVEL (window))
2364 /* FIXME: Implement */
2368 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
2369 gboolean skips_taskbar)
2371 if (GDK_WINDOW_DESTROYED (window) ||
2372 !WINDOW_IS_TOPLEVEL (window))
2375 /* FIXME: Implement */
2379 gdk_window_set_skip_pager_hint (GdkWindow *window,
2380 gboolean skips_pager)
2382 if (GDK_WINDOW_DESTROYED (window) ||
2383 !WINDOW_IS_TOPLEVEL (window))
2386 /* FIXME: Implement */
2390 gdk_window_begin_resize_drag (GdkWindow *window,
2397 GdkWindowImplQuartz *impl;
2399 g_return_if_fail (GDK_IS_WINDOW (window));
2401 if (edge != GDK_WINDOW_EDGE_SOUTH_EAST)
2403 g_warning ("Resizing is only implemented for GDK_WINDOW_EDGE_SOUTH_EAST on Mac OS");
2407 if (GDK_WINDOW_DESTROYED (window))
2410 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2412 if (!impl->toplevel)
2414 g_warning ("Can't call gdk_window_begin_resize_drag on non-toplevel window");
2418 [(GdkQuartzWindow *)impl->toplevel beginManualResize];
2422 gdk_window_begin_move_drag (GdkWindow *window,
2428 GdkWindowImplQuartz *impl;
2430 if (GDK_WINDOW_DESTROYED (window) ||
2431 !WINDOW_IS_TOPLEVEL (window))
2434 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2436 if (!impl->toplevel)
2438 g_warning ("Can't call gdk_window_begin_move_drag on non-toplevel window");
2442 [(GdkQuartzWindow *)impl->toplevel beginManualMove];
2446 gdk_window_set_icon_list (GdkWindow *window,
2449 /* FIXME: Implement */
2453 gdk_window_get_frame_extents (GdkWindow *window,
2456 GdkWindow *toplevel;
2457 GdkWindowImplQuartz *impl;
2460 g_return_if_fail (rect != NULL);
2468 toplevel = gdk_window_get_effective_toplevel (window);
2469 impl = GDK_WINDOW_IMPL_QUARTZ (toplevel->impl);
2471 ns_rect = [impl->toplevel frame];
2473 _gdk_quartz_window_xy_to_gdk_xy (ns_rect.origin.x,
2474 ns_rect.origin.y + ns_rect.size.height,
2475 &rect->x, &rect->y);
2477 rect->width = ns_rect.size.width;
2478 rect->height = ns_rect.size.height;
2482 gdk_window_set_decorations (GdkWindow *window,
2483 GdkWMDecoration decorations)
2485 GdkWindowImplQuartz *impl;
2486 NSUInteger old_mask, new_mask;
2489 if (GDK_WINDOW_DESTROYED (window) ||
2490 !WINDOW_IS_TOPLEVEL (window))
2493 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2495 if (decorations == 0 || GDK_WINDOW_TYPE (window) == GDK_WINDOW_TEMP ||
2496 impl->type_hint == GDK_WINDOW_TYPE_HINT_SPLASHSCREEN )
2498 new_mask = NSBorderlessWindowMask;
2502 /* FIXME: Honor other GDK_DECOR_* flags. */
2503 new_mask = (NSTitledWindowMask | NSClosableWindowMask |
2504 NSMiniaturizableWindowMask | NSResizableWindowMask);
2507 GDK_QUARTZ_ALLOC_POOL;
2509 old_mask = [impl->toplevel styleMask];
2511 /* Note, there doesn't seem to be a way to change this without
2512 * recreating the toplevel. There might be bad side-effects of doing
2513 * that, but it seems alright.
2515 if (old_mask != new_mask)
2519 old_view = [impl->toplevel contentView];
2521 rect = [impl->toplevel frame];
2523 /* Properly update the size of the window when the titlebar is
2526 if (old_mask == NSBorderlessWindowMask &&
2527 new_mask != NSBorderlessWindowMask)
2529 rect = [NSWindow frameRectForContentRect:rect styleMask:new_mask];
2532 else if (old_mask != NSBorderlessWindowMask &&
2533 new_mask == NSBorderlessWindowMask)
2535 rect = [NSWindow contentRectForFrameRect:rect styleMask:old_mask];
2538 impl->toplevel = [impl->toplevel initWithContentRect:rect
2540 backing:NSBackingStoreBuffered
2543 [impl->toplevel setHasShadow: window_type_hint_to_shadow (impl->type_hint)];
2544 [impl->toplevel setLevel: window_type_hint_to_level (impl->type_hint)];
2546 [impl->toplevel setContentView:old_view];
2547 [impl->toplevel setFrame:rect display:YES];
2549 /* Invalidate the window shadow for non-opaque views that have shadow
2550 * enabled, to get the shadow shape updated.
2552 if (![old_view isOpaque] && [impl->toplevel hasShadow])
2553 [(GdkQuartzView*)old_view setNeedsInvalidateShadow:YES];
2556 GDK_QUARTZ_RELEASE_POOL;
2560 gdk_window_get_decorations (GdkWindow *window,
2561 GdkWMDecoration *decorations)
2563 GdkWindowImplQuartz *impl;
2565 if (GDK_WINDOW_DESTROYED (window) ||
2566 !WINDOW_IS_TOPLEVEL (window))
2569 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2573 /* Borderless is 0, so we can't check it as a bit being set. */
2574 if ([impl->toplevel styleMask] == NSBorderlessWindowMask)
2580 /* FIXME: Honor the other GDK_DECOR_* flags. */
2581 *decorations = GDK_DECOR_ALL;
2589 gdk_window_set_functions (GdkWindow *window,
2590 GdkWMFunction functions)
2592 g_return_if_fail (GDK_IS_WINDOW (window));
2594 /* FIXME: Implement */
2598 _gdk_windowing_window_queue_antiexpose (GdkWindow *window,
2599 cairo_region_t *area)
2605 gdk_window_stick (GdkWindow *window)
2607 if (GDK_WINDOW_DESTROYED (window) ||
2608 !WINDOW_IS_TOPLEVEL (window))
2613 gdk_window_unstick (GdkWindow *window)
2615 if (GDK_WINDOW_DESTROYED (window) ||
2616 !WINDOW_IS_TOPLEVEL (window))
2621 gdk_window_maximize (GdkWindow *window)
2623 GdkWindowImplQuartz *impl;
2625 if (GDK_WINDOW_DESTROYED (window) ||
2626 !WINDOW_IS_TOPLEVEL (window))
2629 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2631 if (GDK_WINDOW_IS_MAPPED (window))
2633 GDK_QUARTZ_ALLOC_POOL;
2635 if (impl->toplevel && ![impl->toplevel isZoomed])
2636 [impl->toplevel zoom:nil];
2638 GDK_QUARTZ_RELEASE_POOL;
2642 gdk_synthesize_window_state (window,
2644 GDK_WINDOW_STATE_MAXIMIZED);
2649 gdk_window_unmaximize (GdkWindow *window)
2651 GdkWindowImplQuartz *impl;
2653 if (GDK_WINDOW_DESTROYED (window) ||
2654 !WINDOW_IS_TOPLEVEL (window))
2657 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2659 if (GDK_WINDOW_IS_MAPPED (window))
2661 GDK_QUARTZ_ALLOC_POOL;
2663 if (impl->toplevel && [impl->toplevel isZoomed])
2664 [impl->toplevel zoom:nil];
2666 GDK_QUARTZ_RELEASE_POOL;
2670 gdk_synthesize_window_state (window,
2671 GDK_WINDOW_STATE_MAXIMIZED,
2677 gdk_window_iconify (GdkWindow *window)
2679 GdkWindowImplQuartz *impl;
2681 if (GDK_WINDOW_DESTROYED (window) ||
2682 !WINDOW_IS_TOPLEVEL (window))
2685 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2687 if (GDK_WINDOW_IS_MAPPED (window))
2689 GDK_QUARTZ_ALLOC_POOL;
2692 [impl->toplevel miniaturize:nil];
2694 GDK_QUARTZ_RELEASE_POOL;
2698 gdk_synthesize_window_state (window,
2700 GDK_WINDOW_STATE_ICONIFIED);
2705 gdk_window_deiconify (GdkWindow *window)
2707 GdkWindowImplQuartz *impl;
2709 if (GDK_WINDOW_DESTROYED (window) ||
2710 !WINDOW_IS_TOPLEVEL (window))
2713 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2715 if (GDK_WINDOW_IS_MAPPED (window))
2717 GDK_QUARTZ_ALLOC_POOL;
2720 [impl->toplevel deminiaturize:nil];
2722 GDK_QUARTZ_RELEASE_POOL;
2726 gdk_synthesize_window_state (window,
2727 GDK_WINDOW_STATE_ICONIFIED,
2732 static FullscreenSavedGeometry *
2733 get_fullscreen_geometry (GdkWindow *window)
2735 return g_object_get_data (G_OBJECT (window), FULLSCREEN_DATA);
2739 gdk_window_fullscreen (GdkWindow *window)
2741 FullscreenSavedGeometry *geometry;
2744 if (GDK_WINDOW_DESTROYED (window) ||
2745 !WINDOW_IS_TOPLEVEL (window))
2748 geometry = get_fullscreen_geometry (window);
2751 geometry = g_new (FullscreenSavedGeometry, 1);
2753 geometry->x = window->x;
2754 geometry->y = window->y;
2755 geometry->width = window->width;
2756 geometry->height = window->height;
2758 if (!gdk_window_get_decorations (window, &geometry->decor))
2759 geometry->decor = GDK_DECOR_ALL;
2761 g_object_set_data_full (G_OBJECT (window),
2762 FULLSCREEN_DATA, geometry,
2765 gdk_window_set_decorations (window, 0);
2767 frame = [[NSScreen mainScreen] frame];
2768 move_resize_window_internal (window,
2770 frame.size.width, frame.size.height);
2773 SetSystemUIMode (kUIModeAllHidden, kUIOptionAutoShowMenuBar);
2775 gdk_synthesize_window_state (window, 0, GDK_WINDOW_STATE_FULLSCREEN);
2779 gdk_window_unfullscreen (GdkWindow *window)
2781 FullscreenSavedGeometry *geometry;
2783 if (GDK_WINDOW_DESTROYED (window) ||
2784 !WINDOW_IS_TOPLEVEL (window))
2787 geometry = get_fullscreen_geometry (window);
2790 SetSystemUIMode (kUIModeNormal, 0);
2792 move_resize_window_internal (window,
2798 gdk_window_set_decorations (window, geometry->decor);
2800 g_object_set_data (G_OBJECT (window), FULLSCREEN_DATA, NULL);
2802 gdk_synthesize_window_state (window, GDK_WINDOW_STATE_FULLSCREEN, 0);
2807 gdk_window_set_keep_above (GdkWindow *window, gboolean setting)
2809 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2812 g_return_if_fail (GDK_IS_WINDOW (window));
2814 if (GDK_WINDOW_DESTROYED (window) ||
2815 !WINDOW_IS_TOPLEVEL (window))
2818 level = window_type_hint_to_level (gdk_window_get_type_hint (window));
2820 /* Adjust normal window level by one if necessary. */
2821 [impl->toplevel setLevel: level + (setting ? 1 : 0)];
2825 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
2827 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2830 g_return_if_fail (GDK_IS_WINDOW (window));
2832 if (GDK_WINDOW_DESTROYED (window) ||
2833 !WINDOW_IS_TOPLEVEL (window))
2836 level = window_type_hint_to_level (gdk_window_get_type_hint (window));
2838 /* Adjust normal window level by one if necessary. */
2839 [impl->toplevel setLevel: level - (setting ? 1 : 0)];
2843 gdk_window_get_group (GdkWindow *window)
2845 g_return_val_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD, NULL);
2847 if (GDK_WINDOW_DESTROYED (window) ||
2848 !WINDOW_IS_TOPLEVEL (window))
2851 /* FIXME: Implement */
2857 gdk_window_set_group (GdkWindow *window,
2860 /* FIXME: Implement */
2864 gdk_window_foreign_new_for_display (GdkDisplay *display,
2865 GdkNativeWindow anid)
2867 /* Foreign windows aren't supported in Mac OS X */
2872 gdk_window_lookup (GdkNativeWindow anid)
2874 /* Foreign windows aren't supported in Mac OS X */
2879 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
2881 /* Foreign windows aren't supported in Mac OS X */
2886 gdk_window_enable_synchronized_configure (GdkWindow *window)
2891 gdk_window_configure_finished (GdkWindow *window)
2896 gdk_window_destroy_notify (GdkWindow *window)
2898 check_grab_destroy (window);
2902 gdk_window_set_opacity (GdkWindow *window,
2905 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2907 g_return_if_fail (GDK_IS_WINDOW (window));
2908 g_return_if_fail (WINDOW_IS_TOPLEVEL (window));
2910 if (GDK_WINDOW_DESTROYED (window) ||
2911 !WINDOW_IS_TOPLEVEL (window))
2916 else if (opacity > 1)
2919 [impl->toplevel setAlphaValue: opacity];
2923 _gdk_windowing_window_set_composited (GdkWindow *window, gboolean composited)
2927 static cairo_region_t *
2928 gdk_quartz_window_get_shape (GdkWindow *window)
2930 /* FIXME: implement */
2934 static cairo_region_t *
2935 gdk_quartz_window_get_input_shape (GdkWindow *window)
2937 /* FIXME: implement */
2943 gdk_window_impl_quartz_class_init (GdkWindowImplQuartzClass *klass)
2945 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2946 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_CLASS (klass);
2947 GdkWindowImplQuartzClass *impl_quartz_class = GDK_WINDOW_IMPL_QUARTZ_CLASS (klass);
2949 parent_class = g_type_class_peek_parent (klass);
2951 object_class->finalize = gdk_window_impl_quartz_finalize;
2953 impl_class->ref_cairo_surface = gdk_quartz_ref_cairo_surface;
2954 impl_class->show = gdk_window_quartz_show;
2955 impl_class->hide = gdk_window_quartz_hide;
2956 impl_class->withdraw = gdk_window_quartz_withdraw;
2957 impl_class->set_events = gdk_window_quartz_set_events;
2958 impl_class->get_events = gdk_window_quartz_get_events;
2959 impl_class->raise = gdk_window_quartz_raise;
2960 impl_class->lower = gdk_window_quartz_lower;
2961 impl_class->restack_toplevel = gdk_window_quartz_restack_toplevel;
2962 impl_class->move_resize = gdk_window_quartz_move_resize;
2963 impl_class->set_background = gdk_window_quartz_set_background;
2964 impl_class->reparent = gdk_window_quartz_reparent;
2965 impl_class->set_device_cursor = gdk_window_quartz_set_device_cursor;
2966 impl_class->get_geometry = gdk_window_quartz_get_geometry;
2967 impl_class->get_root_coords = gdk_window_quartz_get_root_coords;
2968 impl_class->get_device_state = gdk_window_quartz_get_device_state;
2969 impl_class->shape_combine_region = gdk_window_quartz_shape_combine_region;
2970 impl_class->input_shape_combine_region = gdk_window_quartz_input_shape_combine_region;
2971 impl_class->set_static_gravities = gdk_window_quartz_set_static_gravities;
2972 impl_class->queue_antiexpose = _gdk_quartz_window_queue_antiexpose;
2973 impl_class->translate = _gdk_quartz_window_translate;
2974 impl_class->destroy = _gdk_quartz_window_destroy;
2975 impl_class->resize_cairo_surface = gdk_window_quartz_resize_cairo_surface;
2976 impl_class->get_shape = gdk_quartz_window_get_shape;
2977 impl_class->get_input_shape = gdk_quartz_window_get_input_shape;
2979 impl_quartz_class->get_context = gdk_window_impl_quartz_get_context;
2980 impl_quartz_class->release_context = gdk_window_impl_quartz_release_context;
2984 _gdk_window_impl_quartz_get_type (void)
2986 static GType object_type = 0;
2990 const GTypeInfo object_info =
2992 sizeof (GdkWindowImplQuartzClass),
2993 (GBaseInitFunc) NULL,
2994 (GBaseFinalizeFunc) NULL,
2995 (GClassInitFunc) gdk_window_impl_quartz_class_init,
2996 NULL, /* class_finalize */
2997 NULL, /* class_data */
2998 sizeof (GdkWindowImplQuartz),
2999 0, /* n_preallocs */
3000 (GInstanceInitFunc) gdk_window_impl_quartz_init,
3003 const GInterfaceInfo paintable_info =
3005 (GInterfaceInitFunc) gdk_window_impl_quartz_paintable_init,
3010 object_type = g_type_register_static (GDK_TYPE_WINDOW_IMPL,
3011 "GdkWindowImplQuartz",
3013 g_type_add_interface_static (object_type,
3022 gdk_quartz_window_get_context (GdkWindowImplQuartz *window,
3025 if (!GDK_WINDOW_IMPL_QUARTZ_GET_CLASS (window)->get_context)
3027 g_warning ("%s doesn't implement GdkWindowImplQuartzClass::get_context()",
3028 G_OBJECT_TYPE_NAME (window));
3032 return GDK_WINDOW_IMPL_QUARTZ_GET_CLASS (window)->get_context (window, antialias);
3036 gdk_quartz_window_release_context (GdkWindowImplQuartz *window,
3037 CGContextRef cg_context)
3039 if (!GDK_WINDOW_IMPL_QUARTZ_GET_CLASS (window)->release_context)
3041 g_warning ("%s doesn't implement GdkWindowImplQuartzClass::release_context()",
3042 G_OBJECT_TYPE_NAME (window));
3046 GDK_WINDOW_IMPL_QUARTZ_GET_CLASS (window)->release_context (window, cg_context);
3052 gdk_root_window_impl_quartz_get_context (GdkWindowImplQuartz *window,
3055 CGColorSpaceRef colorspace;
3056 CGContextRef cg_context;
3057 GdkWindowImplQuartz *window_impl = GDK_WINDOW_IMPL_QUARTZ (window);
3059 if (GDK_WINDOW_DESTROYED (window_impl->wrapper))
3062 /* We do not have the notion of a root window on OS X. We fake this
3063 * by creating a 1x1 bitmap and return a context to that.
3065 colorspace = CGColorSpaceCreateWithName (kCGColorSpaceGenericRGB);
3066 cg_context = CGBitmapContextCreate (NULL,
3067 1, 1, 8, 4, colorspace,
3068 kCGImageAlphaPremultipliedLast);
3069 CGColorSpaceRelease (colorspace);
3075 gdk_root_window_impl_quartz_release_context (GdkWindowImplQuartz *window,
3076 CGContextRef cg_context)
3078 CGContextRelease (cg_context);
3082 gdk_root_window_impl_quartz_class_init (GdkRootWindowImplQuartzClass *klass)
3084 GdkWindowImplQuartzClass *window_quartz_class = GDK_WINDOW_IMPL_QUARTZ_CLASS (klass);
3086 root_window_parent_class = g_type_class_peek_parent (klass);
3088 window_quartz_class->get_context = gdk_root_window_impl_quartz_get_context;
3089 window_quartz_class->release_context = gdk_root_window_impl_quartz_release_context;
3093 gdk_root_window_impl_quartz_init (GdkRootWindowImplQuartz *impl)
3098 _gdk_root_window_impl_quartz_get_type (void)
3100 static GType object_type = 0;
3104 const GTypeInfo object_info =
3106 sizeof (GdkRootWindowImplQuartzClass),
3107 (GBaseInitFunc) NULL,
3108 (GBaseFinalizeFunc) NULL,
3109 (GClassInitFunc) gdk_root_window_impl_quartz_class_init,
3110 NULL, /* class_finalize */
3111 NULL, /* class_data */
3112 sizeof (GdkRootWindowImplQuartz),
3113 0, /* n_preallocs */
3114 (GInstanceInitFunc) gdk_root_window_impl_quartz_init,
3117 object_type = g_type_register_static (GDK_TYPE_WINDOW_IMPL_QUARTZ,
3118 "GdkRootWindowQuartz",