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 "gdkdisplayprivate.h"
28 #include "gdkwindowimpl.h"
29 #include "gdkprivate-quartz.h"
30 #include "gdkscreen-quartz.h"
31 #include "gdkcursor-quartz.h"
34 #include <cairo-quartz.h>
36 static gpointer parent_class;
37 static gpointer root_window_parent_class;
39 static GSList *update_nswindows;
40 static gboolean in_process_all_updates = FALSE;
42 static GSList *main_window_stack;
44 void _gdk_quartz_window_flush (GdkWindowImplQuartz *window_impl);
46 #define FULLSCREEN_DATA "fullscreen-data"
52 GdkWMDecoration decor;
53 } FullscreenSavedGeometry;
56 static void update_toplevel_order (void);
57 static void clear_toplevel_order (void);
59 static FullscreenSavedGeometry *get_fullscreen_geometry (GdkWindow *window);
61 #define WINDOW_IS_TOPLEVEL(window) \
62 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
63 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \
64 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
70 struct _GdkQuartzWindow
75 struct _GdkQuartzWindowClass
77 GdkWindowClass parent_class;
80 G_DEFINE_TYPE (GdkQuartzWindow, gdk_quartz_window, GDK_TYPE_WINDOW);
83 gdk_quartz_window_class_init (GdkQuartzWindowClass *quartz_window_class)
88 gdk_quartz_window_init (GdkQuartzWindow *quartz_window)
98 gdk_quartz_window_get_nsview (GdkWindow *window)
100 if (GDK_WINDOW_DESTROYED (window))
103 return ((GdkWindowImplQuartz *)window->impl)->view;
107 gdk_quartz_window_get_nswindow (GdkWindow *window)
109 if (GDK_WINDOW_DESTROYED (window))
112 return ((GdkWindowImplQuartz *)window->impl)->toplevel;
116 gdk_window_impl_quartz_get_context (GdkWindowImplQuartz *window_impl,
119 CGContextRef cg_context;
121 if (GDK_WINDOW_DESTROYED (window_impl->wrapper))
124 /* Lock focus when not called as part of a drawRect call. This
125 * is needed when called from outside "real" expose events, for
126 * example for synthesized expose events when realizing windows
127 * and for widgets that send fake expose events like the arrow
128 * buttons in spinbuttons or the position marker in rulers.
130 if (window_impl->in_paint_rect_count == 0)
132 if (![window_impl->view lockFocusIfCanDraw])
136 cg_context = [[NSGraphicsContext currentContext] graphicsPort];
137 CGContextSaveGState (cg_context);
138 CGContextSetAllowsAntialiasing (cg_context, antialias);
140 /* We'll emulate the clipping caused by double buffering here */
141 if (window_impl->begin_paint_count != 0)
147 n_rects = cairo_region_num_rectangles (window_impl->paint_clip_region);
152 cg_rects = g_new (CGRect, n_rects);
154 for (i = 0; i < n_rects; i++)
156 cairo_rectangle_int_t cairo_rect;
157 cairo_region_get_rectangle (window_impl->paint_clip_region,
159 cg_rects[i].origin.x = cairo_rect.x;
160 cg_rects[i].origin.y = cairo_rect.y;
161 cg_rects[i].size.width = cairo_rect.width;
162 cg_rects[i].size.height = cairo_rect.height;
165 CGContextClipToRects (cg_context, cg_rects, n_rects);
167 if (cg_rects != &rect)
175 gdk_window_impl_quartz_release_context (GdkWindowImplQuartz *window_impl,
176 CGContextRef cg_context)
178 CGContextRestoreGState (cg_context);
179 CGContextSetAllowsAntialiasing (cg_context, TRUE);
181 /* See comment in gdk_quartz_window_get_context(). */
182 if (window_impl->in_paint_rect_count == 0)
184 _gdk_quartz_window_flush (window_impl);
185 [window_impl->view unlockFocus];
190 check_grab_unmap (GdkWindow *window)
193 GdkDisplay *display = gdk_window_get_display (window);
194 GdkDeviceManager *device_manager;
196 device_manager = gdk_display_get_device_manager (display);
197 list = gdk_device_manager_list_devices (device_manager,
198 GDK_DEVICE_TYPE_FLOATING);
199 for (l = list; l; l = l->next)
201 _gdk_display_end_device_grab (display, l->data, 0, window, TRUE);
208 check_grab_destroy (GdkWindow *window)
211 GdkDisplay *display = gdk_window_get_display (window);
212 GdkDeviceManager *device_manager;
214 /* Make sure there is no lasting grab in this native window */
215 device_manager = gdk_display_get_device_manager (display);
216 list = gdk_device_manager_list_devices (device_manager,
217 GDK_DEVICE_TYPE_MASTER);
219 for (l = list; l; l = l->next)
221 GdkDeviceGrabInfo *grab;
223 grab = _gdk_display_get_last_device_grab (display, l->data);
224 if (grab && grab->native_window == window)
226 /* Serials are always 0 in quartz, but for clarity: */
227 grab->serial_end = grab->serial_start;
228 grab->implicit_ungrab = TRUE;
236 gdk_window_impl_quartz_finalize (GObject *object)
238 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (object);
240 check_grab_destroy (GDK_WINDOW_IMPL_QUARTZ (object)->wrapper);
242 if (impl->paint_clip_region)
243 cairo_region_destroy (impl->paint_clip_region);
245 if (impl->transient_for)
246 g_object_unref (impl->transient_for);
248 G_OBJECT_CLASS (parent_class)->finalize (object);
251 /* Help preventing "beam sync penalty" where CG makes all graphics code
252 * block until the next vsync if we try to flush (including call display on
253 * a view) too often. We do this by limiting the manual flushing done
254 * outside of expose calls to less than some frequency when measured over
255 * the last 4 flushes. This is a bit arbitray, but seems to make it possible
256 * for some quick manual flushes (such as gtkruler or gimp's marching ants)
257 * without hitting the max flush frequency.
259 * If drawable NULL, no flushing is done, only registering that a flush was
263 _gdk_quartz_window_flush (GdkWindowImplQuartz *window_impl)
265 static struct timeval prev_tv;
266 static gint intervals[4];
271 gettimeofday (&tv, NULL);
272 ms = (tv.tv_sec - prev_tv.tv_sec) * 1000 + (tv.tv_usec - prev_tv.tv_usec) / 1000;
273 intervals[index++ % 4] = ms;
277 ms = intervals[0] + intervals[1] + intervals[2] + intervals[3];
279 /* ~25Hz on average. */
283 [window_impl->toplevel flushWindow];
292 static cairo_user_data_key_t gdk_quartz_cairo_key;
295 GdkWindowImplQuartz *window_impl;
296 CGContextRef cg_context;
297 } GdkQuartzCairoSurfaceData;
300 gdk_quartz_cairo_surface_destroy (void *data)
302 GdkQuartzCairoSurfaceData *surface_data = data;
304 surface_data->window_impl->cairo_surface = NULL;
306 gdk_quartz_window_release_context (surface_data->window_impl,
307 surface_data->cg_context);
309 g_free (surface_data);
312 static cairo_surface_t *
313 gdk_quartz_create_cairo_surface (GdkWindowImplQuartz *impl,
317 CGContextRef cg_context;
318 GdkQuartzCairoSurfaceData *surface_data;
319 cairo_surface_t *surface;
321 cg_context = gdk_quartz_window_get_context (impl, TRUE);
326 surface_data = g_new (GdkQuartzCairoSurfaceData, 1);
327 surface_data->window_impl = impl;
328 surface_data->cg_context = cg_context;
330 surface = cairo_quartz_surface_create_for_cg_context (cg_context,
333 cairo_surface_set_user_data (surface, &gdk_quartz_cairo_key,
335 gdk_quartz_cairo_surface_destroy);
340 static cairo_surface_t *
341 gdk_quartz_ref_cairo_surface (GdkWindow *window)
343 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
345 if (GDK_WINDOW_DESTROYED (window))
348 if (!impl->cairo_surface)
350 impl->cairo_surface =
351 gdk_quartz_create_cairo_surface (impl,
352 gdk_window_get_width (impl->wrapper),
353 gdk_window_get_height (impl->wrapper));
356 cairo_surface_reference (impl->cairo_surface);
358 return impl->cairo_surface;
362 gdk_window_impl_quartz_init (GdkWindowImplQuartz *impl)
364 impl->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
368 gdk_window_impl_quartz_begin_paint_region (GdkPaintable *paintable,
370 const cairo_region_t *region)
372 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (paintable);
373 cairo_region_t *clipped_and_offset_region;
376 clipped_and_offset_region = cairo_region_copy (region);
378 cairo_region_intersect (clipped_and_offset_region,
379 window->clip_region_with_children);
380 cairo_region_translate (clipped_and_offset_region,
381 window->abs_x, window->abs_y);
383 if (impl->begin_paint_count == 0)
384 impl->paint_clip_region = cairo_region_reference (clipped_and_offset_region);
386 cairo_region_union (impl->paint_clip_region, clipped_and_offset_region);
388 impl->begin_paint_count++;
390 if (cairo_region_is_empty (clipped_and_offset_region))
393 cr = gdk_cairo_create (window);
395 cairo_translate (cr, -window->abs_x, -window->abs_y);
397 gdk_cairo_region (cr, clipped_and_offset_region);
400 while (window->background == NULL && window->parent)
402 cairo_translate (cr, -window->x, window->y);
403 window = window->parent;
406 if (window->background)
407 cairo_set_source (cr, window->background);
409 cairo_set_source_rgba (cr, 0, 0, 0, 0);
411 /* Can use cairo_paint() here, we clipped above */
417 cairo_region_destroy (clipped_and_offset_region);
421 gdk_window_impl_quartz_end_paint (GdkPaintable *paintable)
423 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (paintable);
425 impl->begin_paint_count--;
427 if (impl->begin_paint_count == 0)
429 cairo_region_destroy (impl->paint_clip_region);
430 impl->paint_clip_region = NULL;
435 _gdk_quartz_window_set_needs_display_in_region (GdkWindow *window,
436 cairo_region_t *region)
438 GdkWindowImplQuartz *impl;
441 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
443 if (!impl->needs_display_region)
444 impl->needs_display_region = cairo_region_create ();
446 cairo_region_union (impl->needs_display_region, region);
448 n_rects = cairo_region_num_rectangles (region);
449 for (i = 0; i < n_rects; i++)
451 cairo_rectangle_int_t rect;
452 cairo_region_get_rectangle (region, i, &rect);
453 [impl->view setNeedsDisplayInRect:NSMakeRect (rect.x, rect.y,
454 rect.width, rect.height)];
459 _gdk_quartz_window_process_updates_recurse (GdkWindow *window,
460 cairo_region_t *region)
462 /* Make sure to only flush each toplevel at most once if we're called
463 * from process_all_updates.
465 if (in_process_all_updates)
469 toplevel = gdk_window_get_effective_toplevel (window);
470 if (toplevel && WINDOW_IS_TOPLEVEL (toplevel))
472 GdkWindowImplQuartz *toplevel_impl;
475 toplevel_impl = (GdkWindowImplQuartz *)toplevel->impl;
476 nswindow = toplevel_impl->toplevel;
478 /* In theory, we could skip the flush disabling, since we only
481 if (nswindow && ![nswindow isFlushWindowDisabled])
484 [nswindow disableFlushWindow];
485 update_nswindows = g_slist_prepend (update_nswindows, nswindow);
490 if (WINDOW_IS_TOPLEVEL (window))
491 _gdk_quartz_window_set_needs_display_in_region (window, region);
493 _gdk_window_process_updates_recurse (window, region);
495 /* NOTE: I'm not sure if we should displayIfNeeded here. It slows down a
496 * lot (since it triggers the beam syncing) and things seem to work
502 _gdk_quartz_display_before_process_all_updates (GdkDisplay *display)
504 in_process_all_updates = TRUE;
506 NSDisableScreenUpdates ();
510 _gdk_quartz_display_after_process_all_updates (GdkDisplay *display)
512 GSList *old_update_nswindows = update_nswindows;
513 GSList *tmp_list = update_nswindows;
515 update_nswindows = NULL;
519 NSWindow *nswindow = tmp_list->data;
521 [[nswindow contentView] displayIfNeeded];
523 _gdk_quartz_window_flush (NULL);
525 [nswindow enableFlushWindow];
526 [nswindow flushWindow];
529 tmp_list = tmp_list->next;
532 g_slist_free (old_update_nswindows);
534 in_process_all_updates = FALSE;
536 NSEnableScreenUpdates ();
540 gdk_window_impl_quartz_paintable_init (GdkPaintableIface *iface)
542 iface->begin_paint_region = gdk_window_impl_quartz_begin_paint_region;
543 iface->end_paint = gdk_window_impl_quartz_end_paint;
547 get_default_title (void)
551 title = g_get_application_name ();
553 title = g_get_prgname ();
559 get_ancestor_coordinates_from_child (GdkWindow *child_window,
562 GdkWindow *ancestor_window,
566 while (child_window != ancestor_window)
568 child_x += child_window->x;
569 child_y += child_window->y;
571 child_window = child_window->parent;
574 *ancestor_x = child_x;
575 *ancestor_y = child_y;
579 _gdk_quartz_window_debug_highlight (GdkWindow *window, gint number)
585 static NSWindow *debug_window[10];
586 static NSRect old_rect[10];
590 g_return_if_fail (number >= 0 && number <= 9);
592 if (window == _gdk_root)
597 if (debug_window[number])
598 [debug_window[number] close];
599 debug_window[number] = NULL;
604 toplevel = gdk_window_get_toplevel (window);
605 get_ancestor_coordinates_from_child (window, 0, 0, toplevel, &x, &y);
607 gdk_window_get_origin (toplevel, &tx, &ty);
611 _gdk_quartz_window_gdk_xy_to_xy (x, y + window->height,
614 rect = NSMakeRect (gx, gy, window->width, window->height);
616 if (debug_window[number] && NSEqualRects (rect, old_rect[number]))
619 old_rect[number] = rect;
621 if (debug_window[number])
622 [debug_window[number] close];
624 debug_window[number] = [[NSWindow alloc] initWithContentRect:rect
625 styleMask:NSBorderlessWindowMask
626 backing:NSBackingStoreBuffered
632 color = [NSColor redColor];
635 color = [NSColor blueColor];
638 color = [NSColor greenColor];
641 color = [NSColor yellowColor];
644 color = [NSColor brownColor];
647 color = [NSColor purpleColor];
650 color = [NSColor blackColor];
654 [debug_window[number] setBackgroundColor:color];
655 [debug_window[number] setAlphaValue:0.4];
656 [debug_window[number] setOpaque:NO];
657 [debug_window[number] setReleasedWhenClosed:YES];
658 [debug_window[number] setIgnoresMouseEvents:YES];
659 [debug_window[number] setLevel:NSFloatingWindowLevel];
661 [debug_window[number] orderFront:nil];
665 _gdk_quartz_window_is_ancestor (GdkWindow *ancestor,
668 if (ancestor == NULL || window == NULL)
671 return (gdk_window_get_parent (window) == ancestor ||
672 _gdk_quartz_window_is_ancestor (ancestor,
673 gdk_window_get_parent (window)));
677 /* See notes on top of gdkscreen-quartz.c */
679 _gdk_quartz_window_gdk_xy_to_xy (gint gdk_x,
684 GdkQuartzScreen *screen_quartz = GDK_QUARTZ_SCREEN (_gdk_screen);
687 *ns_y = screen_quartz->height - gdk_y + screen_quartz->min_y;
690 *ns_x = gdk_x + screen_quartz->min_x;
694 _gdk_quartz_window_xy_to_gdk_xy (gint ns_x,
699 GdkQuartzScreen *screen_quartz = GDK_QUARTZ_SCREEN (_gdk_screen);
702 *gdk_y = screen_quartz->height - ns_y + screen_quartz->min_y;
705 *gdk_x = ns_x - screen_quartz->min_x;
709 _gdk_quartz_window_nspoint_to_gdk_xy (NSPoint point,
713 _gdk_quartz_window_xy_to_gdk_xy (point.x, point.y,
718 find_child_window_helper (GdkWindow *window,
723 gboolean get_toplevel)
725 GdkWindowImplQuartz *impl;
728 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
730 if (window == _gdk_root)
731 update_toplevel_order ();
733 for (l = impl->sorted_children; l; l = l->next)
735 GdkWindow *child = l->data;
736 GdkWindowImplQuartz *child_impl = GDK_WINDOW_IMPL_QUARTZ (child->impl);
739 if (!GDK_WINDOW_IS_MAPPED (child))
742 temp_x = x_offset + child->x;
743 temp_y = y_offset + child->y;
745 /* Special-case the root window. We have to include the title
746 * bar in the checks, otherwise the window below the title bar
747 * will be found i.e. events punch through. (If we can find a
748 * better way to deal with the events in gdkevents-quartz, this
749 * might not be needed.)
751 if (window == _gdk_root)
753 NSRect frame = NSMakeRect (0, 0, 100, 100);
758 mask = [child_impl->toplevel styleMask];
760 /* Get the title bar height. */
761 content = [NSWindow contentRectForFrameRect:frame
763 titlebar_height = frame.size.height - content.size.height;
765 if (titlebar_height > 0 &&
766 x >= temp_x && y >= temp_y - titlebar_height &&
767 x < temp_x + child->width && y < temp_y)
769 /* The root means "unknown" i.e. a window not managed by
772 return (GdkWindow *)_gdk_root;
776 if ((!get_toplevel || (get_toplevel && window == _gdk_root)) &&
777 x >= temp_x && y >= temp_y &&
778 x < temp_x + child->width && y < temp_y + child->height)
780 /* Look for child windows. */
781 return find_child_window_helper (l->data,
791 /* Given a GdkWindow and coordinates relative to it, returns the
792 * innermost subwindow that contains the point. If the coordinates are
793 * outside the passed in window, NULL is returned.
796 _gdk_quartz_window_find_child (GdkWindow *window,
799 gboolean get_toplevel)
801 if (x >= 0 && y >= 0 && x < window->width && y < window->height)
802 return find_child_window_helper (window, x, y, 0, 0, get_toplevel);
809 _gdk_quartz_window_did_become_main (GdkWindow *window)
811 main_window_stack = g_slist_remove (main_window_stack, window);
813 if (window->window_type != GDK_WINDOW_TEMP)
814 main_window_stack = g_slist_prepend (main_window_stack, window);
816 clear_toplevel_order ();
820 _gdk_quartz_window_did_resign_main (GdkWindow *window)
822 GdkWindow *new_window = NULL;
824 if (main_window_stack)
825 new_window = main_window_stack->data;
830 toplevels = gdk_screen_get_toplevel_windows (gdk_screen_get_default ());
832 new_window = toplevels->data;
833 g_list_free (toplevels);
837 new_window != window &&
838 GDK_WINDOW_IS_MAPPED (new_window) &&
839 WINDOW_IS_TOPLEVEL (new_window))
841 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (new_window->impl);
843 [impl->toplevel makeKeyAndOrderFront:impl->toplevel];
846 clear_toplevel_order ();
850 get_nsscreen_for_point (gint x, gint y)
854 NSScreen *screen = NULL;
856 GDK_QUARTZ_ALLOC_POOL;
858 screens = [NSScreen screens];
860 for (i = 0; i < [screens count]; i++)
862 NSRect rect = [[screens objectAtIndex:i] frame];
864 if (x >= rect.origin.x && x <= rect.origin.x + rect.size.width &&
865 y >= rect.origin.y && y <= rect.origin.y + rect.size.height)
867 screen = [screens objectAtIndex:i];
872 GDK_QUARTZ_RELEASE_POOL;
878 _gdk_quartz_display_create_window_impl (GdkDisplay *display,
880 GdkWindow *real_parent,
882 GdkEventMask event_mask,
883 GdkWindowAttr *attributes,
884 gint attributes_mask)
886 GdkWindowImplQuartz *impl;
887 GdkWindowImplQuartz *parent_impl;
889 GDK_QUARTZ_ALLOC_POOL;
891 impl = g_object_new (GDK_TYPE_WINDOW_IMPL_QUARTZ, NULL);
892 window->impl = GDK_WINDOW_IMPL (impl);
893 impl->wrapper = window;
895 parent_impl = GDK_WINDOW_IMPL_QUARTZ (window->parent->impl);
897 switch (window->window_type)
899 case GDK_WINDOW_TOPLEVEL:
900 case GDK_WINDOW_TEMP:
901 if (GDK_WINDOW_TYPE (window->parent) != GDK_WINDOW_ROOT)
903 /* The common code warns for this case */
904 parent_impl = GDK_WINDOW_IMPL_QUARTZ (_gdk_root->impl);
908 /* Maintain the z-ordered list of children. */
909 if (window->parent != _gdk_root)
910 parent_impl->sorted_children = g_list_prepend (parent_impl->sorted_children, window);
912 clear_toplevel_order ();
914 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
915 (attributes->cursor) :
920 switch (attributes->window_type)
922 case GDK_WINDOW_TOPLEVEL:
923 case GDK_WINDOW_TEMP:
928 NSUInteger style_mask;
932 /* initWithContentRect will place on the mainScreen by default.
933 * We want to select the screen to place on ourselves. We need
934 * to find the screen the window will be on and correct the
935 * content_rect coordinates to be relative to that screen.
937 _gdk_quartz_window_gdk_xy_to_xy (window->x, window->y, &nx, &ny);
939 screen = get_nsscreen_for_point (nx, ny);
940 screen_rect = [screen frame];
941 nx -= screen_rect.origin.x;
942 ny -= screen_rect.origin.y;
944 content_rect = NSMakeRect (nx, ny - window->height,
948 if (attributes->window_type == GDK_WINDOW_TEMP ||
949 attributes->type_hint == GDK_WINDOW_TYPE_HINT_SPLASHSCREEN)
951 style_mask = NSBorderlessWindowMask;
955 style_mask = (NSTitledWindowMask |
956 NSClosableWindowMask |
957 NSMiniaturizableWindowMask |
958 NSResizableWindowMask);
961 impl->toplevel = [[GdkQuartzNSWindow alloc] initWithContentRect:content_rect
963 backing:NSBackingStoreBuffered
967 if (attributes_mask & GDK_WA_TITLE)
968 title = attributes->title;
970 title = get_default_title ();
972 gdk_window_set_title (window, title);
974 if (gdk_window_get_visual (window) == gdk_screen_get_rgba_visual (_gdk_screen))
976 [impl->toplevel setOpaque:NO];
977 [impl->toplevel setBackgroundColor:[NSColor clearColor]];
980 content_rect.origin.x = 0;
981 content_rect.origin.y = 0;
983 impl->view = [[GdkQuartzView alloc] initWithFrame:content_rect];
984 [impl->view setGdkWindow:window];
985 [impl->toplevel setContentView:impl->view];
986 [impl->view release];
990 case GDK_WINDOW_CHILD:
992 GdkWindowImplQuartz *parent_impl = GDK_WINDOW_IMPL_QUARTZ (window->parent->impl);
994 if (!window->input_only)
996 NSRect frame_rect = NSMakeRect (window->x + window->parent->abs_x,
997 window->y + window->parent->abs_y,
1001 impl->view = [[GdkQuartzView alloc] initWithFrame:frame_rect];
1003 [impl->view setGdkWindow:window];
1005 /* GdkWindows should be hidden by default */
1006 [impl->view setHidden:YES];
1007 [parent_impl->view addSubview:impl->view];
1008 [impl->view release];
1014 g_assert_not_reached ();
1017 GDK_QUARTZ_RELEASE_POOL;
1019 if (attributes_mask & GDK_WA_TYPE_HINT)
1020 gdk_window_set_type_hint (window, attributes->type_hint);
1024 _gdk_quartz_window_update_position (GdkWindow *window)
1027 NSRect content_rect;
1028 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1030 GDK_QUARTZ_ALLOC_POOL;
1032 frame_rect = [impl->toplevel frame];
1033 content_rect = [impl->toplevel contentRectForFrameRect:frame_rect];
1035 _gdk_quartz_window_xy_to_gdk_xy (content_rect.origin.x,
1036 content_rect.origin.y + content_rect.size.height,
1037 &window->x, &window->y);
1040 GDK_QUARTZ_RELEASE_POOL;
1044 _gdk_windowing_update_window_sizes (GdkScreen *screen)
1046 GList *windows, *list;
1048 /* The size of the root window is so that it can contain all
1049 * monitors attached to this machine. The monitors are laid out
1050 * within this root window. We calculate the size of the root window
1051 * and the positions of the different monitors in gdkscreen-quartz.c.
1053 * This data is updated when the monitor configuration is changed.
1057 _gdk_root->abs_x = 0;
1058 _gdk_root->abs_y = 0;
1059 _gdk_root->width = gdk_screen_get_width (screen);
1060 _gdk_root->height = gdk_screen_get_height (screen);
1062 windows = gdk_screen_get_toplevel_windows (screen);
1064 for (list = windows; list; list = list->next)
1065 _gdk_quartz_window_update_position (list->data);
1067 g_list_free (windows);
1071 _gdk_windowing_window_init (void)
1073 GdkWindowImplQuartz *impl;
1075 g_assert (_gdk_root == NULL);
1077 _gdk_root = _gdk_display_create_window (_gdk_display);
1079 _gdk_root->impl = g_object_new (_gdk_root_window_impl_quartz_get_type (), NULL);
1080 _gdk_root->impl_window = _gdk_root;
1081 _gdk_root->visual = gdk_screen_get_system_visual (_gdk_screen);
1083 impl = GDK_WINDOW_IMPL_QUARTZ (_gdk_root->impl);
1085 _gdk_windowing_update_window_sizes (_gdk_screen);
1087 _gdk_root->state = 0; /* We don't want GDK_WINDOW_STATE_WITHDRAWN here */
1088 _gdk_root->window_type = GDK_WINDOW_ROOT;
1089 _gdk_root->depth = 24;
1090 _gdk_root->viewable = TRUE;
1092 impl->wrapper = _gdk_root;
1096 gdk_quartz_window_destroy (GdkWindow *window,
1098 gboolean foreign_destroy)
1100 GdkWindowImplQuartz *impl;
1103 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1105 main_window_stack = g_slist_remove (main_window_stack, window);
1107 g_list_free (impl->sorted_children);
1108 impl->sorted_children = NULL;
1110 parent = window->parent;
1113 GdkWindowImplQuartz *parent_impl = GDK_WINDOW_IMPL_QUARTZ (parent->impl);
1115 parent_impl->sorted_children = g_list_remove (parent_impl->sorted_children, window);
1118 if (impl->cairo_surface)
1120 cairo_surface_finish (impl->cairo_surface);
1121 cairo_surface_set_user_data (impl->cairo_surface, &gdk_quartz_cairo_key,
1123 impl->cairo_surface = NULL;
1126 if (!recursing && !foreign_destroy)
1128 GDK_QUARTZ_ALLOC_POOL;
1131 [impl->toplevel close];
1132 else if (impl->view)
1133 [impl->view removeFromSuperview];
1135 GDK_QUARTZ_RELEASE_POOL;
1139 static cairo_surface_t *
1140 gdk_window_quartz_resize_cairo_surface (GdkWindow *window,
1141 cairo_surface_t *surface,
1145 /* Quartz surfaces cannot be resized */
1146 cairo_surface_destroy (surface);
1152 gdk_quartz_window_destroy_foreign (GdkWindow *window)
1154 /* Foreign windows aren't supported in OSX. */
1157 /* FIXME: This might be possible to simplify with client-side windows. Also
1158 * note that already_mapped is not used yet, see the x11 backend.
1161 gdk_window_quartz_show (GdkWindow *window, gboolean already_mapped)
1163 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1164 gboolean focus_on_map;
1166 GDK_QUARTZ_ALLOC_POOL;
1168 if (!GDK_WINDOW_IS_MAPPED (window))
1169 focus_on_map = window->focus_on_map;
1171 focus_on_map = TRUE;
1173 if (WINDOW_IS_TOPLEVEL (window) && impl->toplevel)
1177 make_key = (window->accept_focus && focus_on_map &&
1178 window->window_type != GDK_WINDOW_TEMP);
1180 [(GdkQuartzNSWindow*)impl->toplevel showAndMakeKey:make_key];
1181 clear_toplevel_order ();
1183 _gdk_quartz_events_send_map_event (window);
1187 [impl->view setHidden:NO];
1190 [impl->view setNeedsDisplay:YES];
1192 gdk_synthesize_window_state (window, GDK_WINDOW_STATE_WITHDRAWN, 0);
1194 if (window->state & GDK_WINDOW_STATE_MAXIMIZED)
1195 gdk_window_maximize (window);
1197 if (window->state & GDK_WINDOW_STATE_ICONIFIED)
1198 gdk_window_iconify (window);
1200 if (impl->transient_for && !GDK_WINDOW_DESTROYED (impl->transient_for))
1201 _gdk_quartz_window_attach_to_parent (window);
1203 GDK_QUARTZ_RELEASE_POOL;
1206 /* Temporarily unsets the parent window, if the window is a
1210 _gdk_quartz_window_detach_from_parent (GdkWindow *window)
1212 GdkWindowImplQuartz *impl;
1214 g_return_if_fail (GDK_IS_WINDOW (window));
1216 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1218 g_return_if_fail (impl->toplevel != NULL);
1220 if (impl->transient_for && !GDK_WINDOW_DESTROYED (impl->transient_for))
1222 GdkWindowImplQuartz *parent_impl;
1224 parent_impl = GDK_WINDOW_IMPL_QUARTZ (impl->transient_for->impl);
1225 [parent_impl->toplevel removeChildWindow:impl->toplevel];
1226 clear_toplevel_order ();
1230 /* Re-sets the parent window, if the window is a transient. */
1232 _gdk_quartz_window_attach_to_parent (GdkWindow *window)
1234 GdkWindowImplQuartz *impl;
1236 g_return_if_fail (GDK_IS_WINDOW (window));
1238 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1240 g_return_if_fail (impl->toplevel != NULL);
1242 if (impl->transient_for && !GDK_WINDOW_DESTROYED (impl->transient_for))
1244 GdkWindowImplQuartz *parent_impl;
1246 parent_impl = GDK_WINDOW_IMPL_QUARTZ (impl->transient_for->impl);
1247 [parent_impl->toplevel addChildWindow:impl->toplevel ordered:NSWindowAbove];
1248 clear_toplevel_order ();
1253 gdk_window_quartz_hide (GdkWindow *window)
1255 GdkWindowImplQuartz *impl;
1257 /* Make sure we're not stuck in fullscreen mode. */
1258 if (get_fullscreen_geometry (window))
1259 SetSystemUIMode (kUIModeNormal, 0);
1261 check_grab_unmap (window);
1263 _gdk_window_clear_update_area (window);
1265 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1267 if (WINDOW_IS_TOPLEVEL (window))
1269 /* Update main window. */
1270 main_window_stack = g_slist_remove (main_window_stack, window);
1271 if ([NSApp mainWindow] == impl->toplevel)
1272 _gdk_quartz_window_did_resign_main (window);
1274 if (impl->transient_for)
1275 _gdk_quartz_window_detach_from_parent (window);
1277 [(GdkQuartzNSWindow*)impl->toplevel hide];
1279 else if (impl->view)
1281 [impl->view setHidden:YES];
1286 gdk_window_quartz_withdraw (GdkWindow *window)
1288 gdk_window_hide (window);
1292 move_resize_window_internal (GdkWindow *window,
1298 GdkWindowImplQuartz *impl;
1299 GdkRectangle old_visible;
1300 GdkRectangle new_visible;
1301 GdkRectangle scroll_rect;
1302 cairo_region_t *old_region;
1303 cairo_region_t *expose_region;
1306 if (GDK_WINDOW_DESTROYED (window))
1309 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1311 if ((x == -1 || (x == window->x)) &&
1312 (y == -1 || (y == window->y)) &&
1313 (width == -1 || (width == window->width)) &&
1314 (height == -1 || (height == window->height)))
1319 if (!impl->toplevel)
1321 /* The previously visible area of this window in a coordinate
1322 * system rooted at the origin of this window.
1324 old_visible.x = -window->x;
1325 old_visible.y = -window->y;
1327 old_visible.width = window->width;
1328 old_visible.height = window->height;
1333 delta.width = x - window->x;
1343 delta.height = y - window->y;
1352 window->width = width;
1355 window->height = height;
1357 GDK_QUARTZ_ALLOC_POOL;
1361 NSRect content_rect;
1365 _gdk_quartz_window_gdk_xy_to_xy (window->x, window->y + window->height,
1368 content_rect = NSMakeRect (gx, gy, window->width, window->height);
1370 frame_rect = [impl->toplevel frameRectForContentRect:content_rect];
1371 [impl->toplevel setFrame:frame_rect display:YES];
1375 if (!window->input_only)
1379 nsrect = NSMakeRect (window->x, window->y, window->width, window->height);
1381 /* The newly visible area of this window in a coordinate
1382 * system rooted at the origin of this window.
1384 new_visible.x = -window->x;
1385 new_visible.y = -window->y;
1386 new_visible.width = old_visible.width; /* parent has not changed size */
1387 new_visible.height = old_visible.height; /* parent has not changed size */
1389 expose_region = cairo_region_create_rectangle (&new_visible);
1390 old_region = cairo_region_create_rectangle (&old_visible);
1391 cairo_region_subtract (expose_region, old_region);
1393 /* Determine what (if any) part of the previously visible
1394 * part of the window can be copied without a redraw
1396 scroll_rect = old_visible;
1397 scroll_rect.x -= delta.width;
1398 scroll_rect.y -= delta.height;
1399 gdk_rectangle_intersect (&scroll_rect, &old_visible, &scroll_rect);
1401 if (!cairo_region_is_empty (expose_region))
1403 if (scroll_rect.width != 0 && scroll_rect.height != 0)
1405 [impl->view scrollRect:NSMakeRect (scroll_rect.x,
1412 [impl->view setFrame:nsrect];
1414 _gdk_quartz_window_set_needs_display_in_region (window, expose_region);
1418 [impl->view setFrame:nsrect];
1419 [impl->view setNeedsDisplay:YES];
1422 cairo_region_destroy (expose_region);
1423 cairo_region_destroy (old_region);
1427 GDK_QUARTZ_RELEASE_POOL;
1431 window_quartz_move (GdkWindow *window,
1435 g_return_if_fail (GDK_IS_WINDOW (window));
1437 if (window->state & GDK_WINDOW_STATE_FULLSCREEN)
1440 move_resize_window_internal (window, x, y, -1, -1);
1444 window_quartz_resize (GdkWindow *window,
1448 g_return_if_fail (GDK_IS_WINDOW (window));
1450 if (window->state & GDK_WINDOW_STATE_FULLSCREEN)
1458 move_resize_window_internal (window, -1, -1, width, height);
1462 window_quartz_move_resize (GdkWindow *window,
1473 move_resize_window_internal (window, x, y, width, height);
1477 gdk_window_quartz_move_resize (GdkWindow *window,
1484 if (with_move && (width < 0 && height < 0))
1485 window_quartz_move (window, x, y);
1489 window_quartz_move_resize (window, x, y, width, height);
1491 window_quartz_resize (window, width, height);
1495 /* FIXME: This might need fixing (reparenting didn't work before client-side
1499 gdk_window_quartz_reparent (GdkWindow *window,
1500 GdkWindow *new_parent,
1504 GdkWindow *old_parent;
1505 GdkWindowImplQuartz *impl, *old_parent_impl, *new_parent_impl;
1506 NSView *view, *new_parent_view;
1508 if (new_parent == _gdk_root)
1510 /* Could be added, just needs implementing. */
1511 g_warning ("Reparenting to root window is not supported yet in the Mac OS X backend");
1515 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1518 new_parent_impl = GDK_WINDOW_IMPL_QUARTZ (new_parent->impl);
1519 new_parent_view = new_parent_impl->view;
1521 old_parent = window->parent;
1522 old_parent_impl = GDK_WINDOW_IMPL_QUARTZ (old_parent->impl);
1526 [view removeFromSuperview];
1527 [new_parent_view addSubview:view];
1531 window->parent = new_parent;
1535 old_parent_impl->sorted_children = g_list_remove (old_parent_impl->sorted_children, window);
1538 new_parent_impl->sorted_children = g_list_prepend (new_parent_impl->sorted_children, window);
1543 /* Get the toplevel ordering from NSApp and update our own list. We do
1544 * this on demand since the NSApp's list is not up to date directly
1545 * after we get windowDidBecomeMain.
1548 update_toplevel_order (void)
1550 GdkWindowImplQuartz *root_impl;
1551 NSEnumerator *enumerator;
1553 GList *toplevels = NULL;
1555 root_impl = GDK_WINDOW_IMPL_QUARTZ (_gdk_root->impl);
1557 if (root_impl->sorted_children)
1560 GDK_QUARTZ_ALLOC_POOL;
1562 enumerator = [[NSApp orderedWindows] objectEnumerator];
1563 while ((nswindow = [enumerator nextObject]))
1567 if (![[nswindow contentView] isKindOfClass:[GdkQuartzView class]])
1570 window = [(GdkQuartzView *)[nswindow contentView] gdkWindow];
1571 toplevels = g_list_prepend (toplevels, window);
1574 GDK_QUARTZ_RELEASE_POOL;
1576 root_impl->sorted_children = g_list_reverse (toplevels);
1580 clear_toplevel_order (void)
1582 GdkWindowImplQuartz *root_impl;
1584 root_impl = GDK_WINDOW_IMPL_QUARTZ (_gdk_root->impl);
1586 g_list_free (root_impl->sorted_children);
1587 root_impl->sorted_children = NULL;
1591 gdk_window_quartz_raise (GdkWindow *window)
1593 if (GDK_WINDOW_DESTROYED (window))
1596 if (WINDOW_IS_TOPLEVEL (window))
1598 GdkWindowImplQuartz *impl;
1600 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1601 [impl->toplevel orderFront:impl->toplevel];
1603 clear_toplevel_order ();
1607 GdkWindow *parent = window->parent;
1611 GdkWindowImplQuartz *impl;
1613 impl = (GdkWindowImplQuartz *)parent->impl;
1615 impl->sorted_children = g_list_remove (impl->sorted_children, window);
1616 impl->sorted_children = g_list_prepend (impl->sorted_children, window);
1622 gdk_window_quartz_lower (GdkWindow *window)
1624 if (GDK_WINDOW_DESTROYED (window))
1627 if (WINDOW_IS_TOPLEVEL (window))
1629 GdkWindowImplQuartz *impl;
1631 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1632 [impl->toplevel orderBack:impl->toplevel];
1634 clear_toplevel_order ();
1638 GdkWindow *parent = window->parent;
1642 GdkWindowImplQuartz *impl;
1644 impl = (GdkWindowImplQuartz *)parent->impl;
1646 impl->sorted_children = g_list_remove (impl->sorted_children, window);
1647 impl->sorted_children = g_list_append (impl->sorted_children, window);
1653 gdk_window_quartz_restack_toplevel (GdkWindow *window,
1657 /* FIXME: Implement this */
1661 gdk_window_quartz_set_background (GdkWindow *window,
1662 cairo_pattern_t *pattern)
1664 /* FIXME: We could theoretically set the background color for toplevels
1665 * here. (Currently we draw the background before emitting expose events)
1670 gdk_window_quartz_set_device_cursor (GdkWindow *window,
1674 GdkQuartzCursor *cursor_private;
1677 cursor_private = (GdkQuartzCursor *)cursor;
1679 if (GDK_WINDOW_DESTROYED (window))
1683 nscursor = [NSCursor arrowCursor];
1685 nscursor = cursor_private->nscursor;
1691 gdk_window_quartz_get_geometry (GdkWindow *window,
1697 GdkWindowImplQuartz *impl;
1700 if (GDK_WINDOW_DESTROYED (window))
1703 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
1704 if (window == _gdk_root)
1712 *width = window->width;
1714 *height = window->height;
1716 else if (WINDOW_IS_TOPLEVEL (window))
1718 ns_rect = [impl->toplevel contentRectForFrameRect:[impl->toplevel frame]];
1720 /* This doesn't work exactly as in X. There doesn't seem to be a
1721 * way to get the coords relative to the parent window (usually
1722 * the window frame), but that seems useless except for
1723 * borderless windows where it's relative to the root window. So
1724 * we return (0, 0) (should be something like (0, 22)) for
1725 * windows with borders and the root relative coordinates
1728 if ([impl->toplevel styleMask] == NSBorderlessWindowMask)
1730 _gdk_quartz_window_xy_to_gdk_xy (ns_rect.origin.x,
1731 ns_rect.origin.y + ns_rect.size.height,
1743 *width = ns_rect.size.width;
1745 *height = ns_rect.size.height;
1749 ns_rect = [impl->view frame];
1752 *x = ns_rect.origin.x;
1754 *y = ns_rect.origin.y;
1756 *width = ns_rect.size.width;
1758 *height = ns_rect.size.height;
1763 gdk_window_quartz_get_root_coords (GdkWindow *window,
1769 int tmp_x = 0, tmp_y = 0;
1770 GdkWindow *toplevel;
1771 NSRect content_rect;
1772 GdkWindowImplQuartz *impl;
1774 if (GDK_WINDOW_DESTROYED (window))
1784 if (window == _gdk_root)
1794 toplevel = gdk_window_get_toplevel (window);
1795 impl = GDK_WINDOW_IMPL_QUARTZ (toplevel->impl);
1797 content_rect = [impl->toplevel contentRectForFrameRect:[impl->toplevel frame]];
1799 _gdk_quartz_window_xy_to_gdk_xy (content_rect.origin.x,
1800 content_rect.origin.y + content_rect.size.height,
1806 while (window != toplevel)
1808 if (_gdk_window_has_impl ((GdkWindow *)window))
1814 window = window->parent;
1826 gdk_quartz_window_get_root_origin (GdkWindow *window,
1835 gdk_window_get_frame_extents (window, &rect);
1844 /* Returns coordinates relative to the passed in window. */
1846 gdk_window_quartz_get_device_state_helper (GdkWindow *window,
1850 GdkModifierType *mask)
1854 GdkWindow *toplevel;
1855 GdkWindow *found_window;
1857 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
1859 if (GDK_WINDOW_DESTROYED (window))
1867 toplevel = gdk_window_get_toplevel (window);
1869 *mask = _gdk_quartz_events_get_current_event_mask ();
1871 /* Get the y coordinate, needs to be flipped. */
1872 if (window == _gdk_root)
1874 point = [NSEvent mouseLocation];
1875 _gdk_quartz_window_nspoint_to_gdk_xy (point, &x_tmp, &y_tmp);
1879 GdkWindowImplQuartz *impl;
1882 impl = GDK_WINDOW_IMPL_QUARTZ (toplevel->impl);
1883 nswindow = impl->toplevel;
1885 point = [nswindow mouseLocationOutsideOfEventStream];
1888 y_tmp = toplevel->height - point.y;
1890 window = (GdkWindow *)toplevel;
1893 found_window = _gdk_quartz_window_find_child (window, x_tmp, y_tmp,
1896 /* We never return the root window. */
1897 if (found_window == _gdk_root)
1898 found_window = NULL;
1903 return found_window;
1907 gdk_window_quartz_get_device_state (GdkWindow *window,
1911 GdkModifierType *mask)
1913 return gdk_window_quartz_get_device_state_helper (window,
1915 x, y, mask) != NULL;
1918 /* Returns coordinates relative to the root. */
1920 _gdk_windowing_get_device_state (GdkDisplay *display,
1925 GdkModifierType *mask)
1927 g_return_if_fail (display == _gdk_display);
1929 *screen = _gdk_screen;
1930 gdk_window_quartz_get_device_state_helper (_gdk_root, device, x, y, mask);
1933 /* Returns coordinates relative to the found window. */
1935 _gdk_windowing_window_at_pointer (GdkDisplay *display,
1938 GdkModifierType *mask,
1939 gboolean get_toplevel)
1941 GdkWindow *found_window;
1943 GdkModifierType tmp_mask = 0;
1945 found_window = gdk_window_quartz_get_device_state_helper (_gdk_root,
1946 display->core_pointer,
1951 /* The coordinates returned above are relative the root, we want
1952 * coordinates relative the window here.
1954 while (found_window != _gdk_root)
1956 x -= found_window->x;
1957 y -= found_window->y;
1959 found_window = found_window->parent;
1967 /* Mimic the X backend here, -1,-1 for unknown windows. */
1977 /* Requested toplevel, find it. */
1978 /* TODO: This can be implemented more efficient by never
1979 recursing into children in the first place */
1982 /* Convert to toplevel */
1983 while (found_window->parent != NULL &&
1984 found_window->parent->window_type != GDK_WINDOW_ROOT)
1986 *win_x += found_window->x;
1987 *win_y += found_window->y;
1988 found_window = found_window->parent;
1993 return found_window;
1997 _gdk_windowing_window_at_device_position (GdkDisplay *display,
2001 GdkModifierType *mask,
2002 gboolean get_toplevel)
2004 return GDK_DEVICE_GET_CLASS (device)->window_at_position (device,
2012 gdk_window_quartz_get_events (GdkWindow *window)
2014 if (GDK_WINDOW_DESTROYED (window))
2017 return window->event_mask;
2021 gdk_window_quartz_set_events (GdkWindow *window,
2022 GdkEventMask event_mask)
2024 /* The mask is set in the common code. */
2028 gdk_quartz_window_set_urgency_hint (GdkWindow *window,
2031 if (GDK_WINDOW_DESTROYED (window) ||
2032 !WINDOW_IS_TOPLEVEL (window))
2035 /* FIXME: Implement */
2039 gdk_quartz_window_set_geometry_hints (GdkWindow *window,
2040 const GdkGeometry *geometry,
2041 GdkWindowHints geom_mask)
2043 GdkWindowImplQuartz *impl;
2045 g_return_if_fail (geometry != NULL);
2047 if (GDK_WINDOW_DESTROYED (window) ||
2048 !WINDOW_IS_TOPLEVEL (window))
2051 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2052 if (!impl->toplevel)
2055 if (geom_mask & GDK_HINT_POS)
2057 /* FIXME: Implement */
2060 if (geom_mask & GDK_HINT_USER_POS)
2062 /* FIXME: Implement */
2065 if (geom_mask & GDK_HINT_USER_SIZE)
2067 /* FIXME: Implement */
2070 if (geom_mask & GDK_HINT_MIN_SIZE)
2074 size.width = geometry->min_width;
2075 size.height = geometry->min_height;
2077 [impl->toplevel setContentMinSize:size];
2080 if (geom_mask & GDK_HINT_MAX_SIZE)
2084 size.width = geometry->max_width;
2085 size.height = geometry->max_height;
2087 [impl->toplevel setContentMaxSize:size];
2090 if (geom_mask & GDK_HINT_BASE_SIZE)
2092 /* FIXME: Implement */
2095 if (geom_mask & GDK_HINT_RESIZE_INC)
2099 size.width = geometry->width_inc;
2100 size.height = geometry->height_inc;
2102 [impl->toplevel setContentResizeIncrements:size];
2105 if (geom_mask & GDK_HINT_ASPECT)
2107 /* FIXME: Implement */
2110 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2112 /* FIXME: Implement */
2117 gdk_quartz_window_set_title (GdkWindow *window,
2120 GdkWindowImplQuartz *impl;
2122 g_return_if_fail (title != NULL);
2124 if (GDK_WINDOW_DESTROYED (window) ||
2125 !WINDOW_IS_TOPLEVEL (window))
2128 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2132 GDK_QUARTZ_ALLOC_POOL;
2133 [impl->toplevel setTitle:[NSString stringWithUTF8String:title]];
2134 GDK_QUARTZ_RELEASE_POOL;
2139 gdk_quartz_window_set_role (GdkWindow *window,
2142 if (GDK_WINDOW_DESTROYED (window) ||
2143 WINDOW_IS_TOPLEVEL (window))
2146 /* FIXME: Implement */
2150 gdk_quartz_window_set_transient_for (GdkWindow *window,
2153 GdkWindowImplQuartz *window_impl;
2154 GdkWindowImplQuartz *parent_impl;
2156 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (parent) ||
2157 !WINDOW_IS_TOPLEVEL (window))
2160 window_impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2161 if (!window_impl->toplevel)
2164 GDK_QUARTZ_ALLOC_POOL;
2166 if (window_impl->transient_for)
2168 _gdk_quartz_window_detach_from_parent (window);
2170 g_object_unref (window_impl->transient_for);
2171 window_impl->transient_for = NULL;
2174 parent_impl = GDK_WINDOW_IMPL_QUARTZ (parent->impl);
2175 if (parent_impl->toplevel)
2177 /* We save the parent because it needs to be unset/reset when
2178 * hiding and showing the window.
2181 /* We don't set transients for tooltips, they are already
2182 * handled by the window level being the top one. If we do, then
2183 * the parent window will be brought to the top just because the
2184 * tooltip is, which is not what we want.
2186 if (gdk_window_get_type_hint (window) != GDK_WINDOW_TYPE_HINT_TOOLTIP)
2188 window_impl->transient_for = g_object_ref (parent);
2190 /* We only add the window if it is shown, otherwise it will
2191 * be shown unconditionally here. If it is not shown, the
2192 * window will be added in show() instead.
2194 if (!(window->state & GDK_WINDOW_STATE_WITHDRAWN))
2195 _gdk_quartz_window_attach_to_parent (window);
2199 GDK_QUARTZ_RELEASE_POOL;
2203 gdk_window_quartz_shape_combine_region (GdkWindow *window,
2204 const cairo_region_t *shape,
2208 /* FIXME: Implement */
2212 gdk_window_quartz_input_shape_combine_region (GdkWindow *window,
2213 const cairo_region_t *shape_region,
2217 /* FIXME: Implement */
2221 gdk_quartz_window_set_override_redirect (GdkWindow *window,
2222 gboolean override_redirect)
2224 /* FIXME: Implement */
2228 gdk_quartz_window_set_accept_focus (GdkWindow *window,
2229 gboolean accept_focus)
2231 window->accept_focus = accept_focus != FALSE;
2235 gdk_window_quartz_set_static_gravities (GdkWindow *window,
2236 gboolean use_static)
2238 if (GDK_WINDOW_DESTROYED (window) ||
2239 !WINDOW_IS_TOPLEVEL (window))
2242 /* FIXME: Implement */
2247 gdk_quartz_window_set_focus_on_map (GdkWindow *window,
2248 gboolean focus_on_map)
2250 window->focus_on_map = focus_on_map != FALSE;
2254 gdk_quartz_window_set_icon_name (GdkWindow *window,
2257 /* FIXME: Implement */
2261 gdk_quartz_window_focus (GdkWindow *window,
2264 GdkWindowImplQuartz *impl;
2266 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2268 if (GDK_WINDOW_DESTROYED (window) ||
2269 !WINDOW_IS_TOPLEVEL (window))
2272 if (window->accept_focus && window->window_type != GDK_WINDOW_TEMP)
2274 GDK_QUARTZ_ALLOC_POOL;
2275 [impl->toplevel makeKeyAndOrderFront:impl->toplevel];
2276 clear_toplevel_order ();
2277 GDK_QUARTZ_RELEASE_POOL;
2282 gint window_type_hint_to_level (GdkWindowTypeHint hint)
2286 case GDK_WINDOW_TYPE_HINT_DOCK:
2287 case GDK_WINDOW_TYPE_HINT_UTILITY:
2288 return NSFloatingWindowLevel;
2290 case GDK_WINDOW_TYPE_HINT_MENU: /* Torn-off menu */
2291 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU: /* Menu from menubar */
2292 return NSTornOffMenuWindowLevel;
2294 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
2295 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
2296 return NSStatusWindowLevel;
2298 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
2299 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
2300 case GDK_WINDOW_TYPE_HINT_COMBO:
2301 case GDK_WINDOW_TYPE_HINT_DND:
2302 return NSPopUpMenuWindowLevel;
2304 case GDK_WINDOW_TYPE_HINT_NORMAL: /* Normal toplevel window */
2305 case GDK_WINDOW_TYPE_HINT_DIALOG: /* Dialog window */
2306 case GDK_WINDOW_TYPE_HINT_TOOLBAR: /* Window used to implement toolbars */
2307 case GDK_WINDOW_TYPE_HINT_DESKTOP: /* N/A */
2314 return NSNormalWindowLevel;
2318 window_type_hint_to_shadow (GdkWindowTypeHint hint)
2322 case GDK_WINDOW_TYPE_HINT_NORMAL: /* Normal toplevel window */
2323 case GDK_WINDOW_TYPE_HINT_DIALOG: /* Dialog window */
2324 case GDK_WINDOW_TYPE_HINT_DOCK:
2325 case GDK_WINDOW_TYPE_HINT_UTILITY:
2326 case GDK_WINDOW_TYPE_HINT_MENU: /* Torn-off menu */
2327 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU: /* Menu from menubar */
2328 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
2329 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
2330 case GDK_WINDOW_TYPE_HINT_COMBO:
2331 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
2332 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
2335 case GDK_WINDOW_TYPE_HINT_TOOLBAR: /* Window used to implement toolbars */
2336 case GDK_WINDOW_TYPE_HINT_DESKTOP: /* N/A */
2337 case GDK_WINDOW_TYPE_HINT_DND:
2349 gdk_quartz_window_set_type_hint (GdkWindow *window,
2350 GdkWindowTypeHint hint)
2352 GdkWindowImplQuartz *impl;
2354 if (GDK_WINDOW_DESTROYED (window) ||
2355 !WINDOW_IS_TOPLEVEL (window))
2358 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2360 impl->type_hint = hint;
2362 /* Match the documentation, only do something if we're not mapped yet. */
2363 if (GDK_WINDOW_IS_MAPPED (window))
2366 [impl->toplevel setHasShadow: window_type_hint_to_shadow (hint)];
2367 [impl->toplevel setLevel: window_type_hint_to_level (hint)];
2370 static GdkWindowTypeHint
2371 gdk_quartz_window_get_type_hint (GdkWindow *window)
2373 if (GDK_WINDOW_DESTROYED (window) ||
2374 !WINDOW_IS_TOPLEVEL (window))
2375 return GDK_WINDOW_TYPE_HINT_NORMAL;
2377 return GDK_WINDOW_IMPL_QUARTZ (window->impl)->type_hint;
2381 gdk_quartz_window_set_modal_hint (GdkWindow *window,
2384 if (GDK_WINDOW_DESTROYED (window) ||
2385 !WINDOW_IS_TOPLEVEL (window))
2388 /* FIXME: Implement */
2392 gdk_quartz_window_set_skip_taskbar_hint (GdkWindow *window,
2393 gboolean skips_taskbar)
2395 if (GDK_WINDOW_DESTROYED (window) ||
2396 !WINDOW_IS_TOPLEVEL (window))
2399 /* FIXME: Implement */
2403 gdk_quartz_window_set_skip_pager_hint (GdkWindow *window,
2404 gboolean skips_pager)
2406 if (GDK_WINDOW_DESTROYED (window) ||
2407 !WINDOW_IS_TOPLEVEL (window))
2410 /* FIXME: Implement */
2414 gdk_quartz_window_begin_resize_drag (GdkWindow *window,
2421 GdkWindowImplQuartz *impl;
2423 g_return_if_fail (GDK_IS_WINDOW (window));
2425 if (edge != GDK_WINDOW_EDGE_SOUTH_EAST)
2427 g_warning ("Resizing is only implemented for GDK_WINDOW_EDGE_SOUTH_EAST on Mac OS");
2431 if (GDK_WINDOW_DESTROYED (window))
2434 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2436 if (!impl->toplevel)
2438 g_warning ("Can't call gdk_window_begin_resize_drag on non-toplevel window");
2442 [(GdkQuartzNSWindow *)impl->toplevel beginManualResize];
2446 gdk_quartz_window_begin_move_drag (GdkWindow *window,
2452 GdkWindowImplQuartz *impl;
2454 if (GDK_WINDOW_DESTROYED (window) ||
2455 !WINDOW_IS_TOPLEVEL (window))
2458 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2460 if (!impl->toplevel)
2462 g_warning ("Can't call gdk_window_begin_move_drag on non-toplevel window");
2466 [(GdkQuartzNSWindow *)impl->toplevel beginManualMove];
2470 gdk_quartz_window_set_icon_list (GdkWindow *window,
2473 /* FIXME: Implement */
2477 gdk_quartz_window_get_frame_extents (GdkWindow *window,
2480 GdkWindow *toplevel;
2481 GdkWindowImplQuartz *impl;
2484 g_return_if_fail (rect != NULL);
2492 toplevel = gdk_window_get_effective_toplevel (window);
2493 impl = GDK_WINDOW_IMPL_QUARTZ (toplevel->impl);
2495 ns_rect = [impl->toplevel frame];
2497 _gdk_quartz_window_xy_to_gdk_xy (ns_rect.origin.x,
2498 ns_rect.origin.y + ns_rect.size.height,
2499 &rect->x, &rect->y);
2501 rect->width = ns_rect.size.width;
2502 rect->height = ns_rect.size.height;
2506 gdk_quartz_window_set_decorations (GdkWindow *window,
2507 GdkWMDecoration decorations)
2509 GdkWindowImplQuartz *impl;
2510 NSUInteger old_mask, new_mask;
2513 if (GDK_WINDOW_DESTROYED (window) ||
2514 !WINDOW_IS_TOPLEVEL (window))
2517 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2519 if (decorations == 0 || GDK_WINDOW_TYPE (window) == GDK_WINDOW_TEMP ||
2520 impl->type_hint == GDK_WINDOW_TYPE_HINT_SPLASHSCREEN )
2522 new_mask = NSBorderlessWindowMask;
2526 /* FIXME: Honor other GDK_DECOR_* flags. */
2527 new_mask = (NSTitledWindowMask | NSClosableWindowMask |
2528 NSMiniaturizableWindowMask | NSResizableWindowMask);
2531 GDK_QUARTZ_ALLOC_POOL;
2533 old_mask = [impl->toplevel styleMask];
2535 /* Note, there doesn't seem to be a way to change this without
2536 * recreating the toplevel. There might be bad side-effects of doing
2537 * that, but it seems alright.
2539 if (old_mask != new_mask)
2543 old_view = [impl->toplevel contentView];
2545 rect = [impl->toplevel frame];
2547 /* Properly update the size of the window when the titlebar is
2550 if (old_mask == NSBorderlessWindowMask &&
2551 new_mask != NSBorderlessWindowMask)
2553 rect = [NSWindow frameRectForContentRect:rect styleMask:new_mask];
2556 else if (old_mask != NSBorderlessWindowMask &&
2557 new_mask == NSBorderlessWindowMask)
2559 rect = [NSWindow contentRectForFrameRect:rect styleMask:old_mask];
2562 impl->toplevel = [impl->toplevel initWithContentRect:rect
2564 backing:NSBackingStoreBuffered
2567 [impl->toplevel setHasShadow: window_type_hint_to_shadow (impl->type_hint)];
2568 [impl->toplevel setLevel: window_type_hint_to_level (impl->type_hint)];
2570 [impl->toplevel setContentView:old_view];
2571 [impl->toplevel setFrame:rect display:YES];
2573 /* Invalidate the window shadow for non-opaque views that have shadow
2574 * enabled, to get the shadow shape updated.
2576 if (![old_view isOpaque] && [impl->toplevel hasShadow])
2577 [(GdkQuartzView*)old_view setNeedsInvalidateShadow:YES];
2580 GDK_QUARTZ_RELEASE_POOL;
2584 gdk_quartz_window_get_decorations (GdkWindow *window,
2585 GdkWMDecoration *decorations)
2587 GdkWindowImplQuartz *impl;
2589 if (GDK_WINDOW_DESTROYED (window) ||
2590 !WINDOW_IS_TOPLEVEL (window))
2593 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2597 /* Borderless is 0, so we can't check it as a bit being set. */
2598 if ([impl->toplevel styleMask] == NSBorderlessWindowMask)
2604 /* FIXME: Honor the other GDK_DECOR_* flags. */
2605 *decorations = GDK_DECOR_ALL;
2613 gdk_quartz_window_set_functions (GdkWindow *window,
2614 GdkWMFunction functions)
2616 g_return_if_fail (GDK_IS_WINDOW (window));
2618 /* FIXME: Implement */
2622 _gdk_windowing_window_queue_antiexpose (GdkWindow *window,
2623 cairo_region_t *area)
2629 gdk_quartz_window_stick (GdkWindow *window)
2631 if (GDK_WINDOW_DESTROYED (window) ||
2632 !WINDOW_IS_TOPLEVEL (window))
2637 gdk_quartz_window_unstick (GdkWindow *window)
2639 if (GDK_WINDOW_DESTROYED (window) ||
2640 !WINDOW_IS_TOPLEVEL (window))
2645 gdk_quartz_window_maximize (GdkWindow *window)
2647 GdkWindowImplQuartz *impl;
2649 if (GDK_WINDOW_DESTROYED (window) ||
2650 !WINDOW_IS_TOPLEVEL (window))
2653 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2655 if (GDK_WINDOW_IS_MAPPED (window))
2657 GDK_QUARTZ_ALLOC_POOL;
2659 if (impl->toplevel && ![impl->toplevel isZoomed])
2660 [impl->toplevel zoom:nil];
2662 GDK_QUARTZ_RELEASE_POOL;
2666 gdk_synthesize_window_state (window,
2668 GDK_WINDOW_STATE_MAXIMIZED);
2673 gdk_quartz_window_unmaximize (GdkWindow *window)
2675 GdkWindowImplQuartz *impl;
2677 if (GDK_WINDOW_DESTROYED (window) ||
2678 !WINDOW_IS_TOPLEVEL (window))
2681 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2683 if (GDK_WINDOW_IS_MAPPED (window))
2685 GDK_QUARTZ_ALLOC_POOL;
2687 if (impl->toplevel && [impl->toplevel isZoomed])
2688 [impl->toplevel zoom:nil];
2690 GDK_QUARTZ_RELEASE_POOL;
2694 gdk_synthesize_window_state (window,
2695 GDK_WINDOW_STATE_MAXIMIZED,
2701 gdk_quartz_window_iconify (GdkWindow *window)
2703 GdkWindowImplQuartz *impl;
2705 if (GDK_WINDOW_DESTROYED (window) ||
2706 !WINDOW_IS_TOPLEVEL (window))
2709 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2711 if (GDK_WINDOW_IS_MAPPED (window))
2713 GDK_QUARTZ_ALLOC_POOL;
2716 [impl->toplevel miniaturize:nil];
2718 GDK_QUARTZ_RELEASE_POOL;
2722 gdk_synthesize_window_state (window,
2724 GDK_WINDOW_STATE_ICONIFIED);
2729 gdk_quartz_window_deiconify (GdkWindow *window)
2731 GdkWindowImplQuartz *impl;
2733 if (GDK_WINDOW_DESTROYED (window) ||
2734 !WINDOW_IS_TOPLEVEL (window))
2737 impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2739 if (GDK_WINDOW_IS_MAPPED (window))
2741 GDK_QUARTZ_ALLOC_POOL;
2744 [impl->toplevel deminiaturize:nil];
2746 GDK_QUARTZ_RELEASE_POOL;
2750 gdk_synthesize_window_state (window,
2751 GDK_WINDOW_STATE_ICONIFIED,
2756 static FullscreenSavedGeometry *
2757 get_fullscreen_geometry (GdkWindow *window)
2759 return g_object_get_data (G_OBJECT (window), FULLSCREEN_DATA);
2763 gdk_quartz_window_fullscreen (GdkWindow *window)
2765 FullscreenSavedGeometry *geometry;
2768 if (GDK_WINDOW_DESTROYED (window) ||
2769 !WINDOW_IS_TOPLEVEL (window))
2772 geometry = get_fullscreen_geometry (window);
2775 geometry = g_new (FullscreenSavedGeometry, 1);
2777 geometry->x = window->x;
2778 geometry->y = window->y;
2779 geometry->width = window->width;
2780 geometry->height = window->height;
2782 if (!gdk_window_get_decorations (window, &geometry->decor))
2783 geometry->decor = GDK_DECOR_ALL;
2785 g_object_set_data_full (G_OBJECT (window),
2786 FULLSCREEN_DATA, geometry,
2789 gdk_window_set_decorations (window, 0);
2791 frame = [[NSScreen mainScreen] frame];
2792 move_resize_window_internal (window,
2794 frame.size.width, frame.size.height);
2797 SetSystemUIMode (kUIModeAllHidden, kUIOptionAutoShowMenuBar);
2799 gdk_synthesize_window_state (window, 0, GDK_WINDOW_STATE_FULLSCREEN);
2803 gdk_quartz_window_unfullscreen (GdkWindow *window)
2805 FullscreenSavedGeometry *geometry;
2807 if (GDK_WINDOW_DESTROYED (window) ||
2808 !WINDOW_IS_TOPLEVEL (window))
2811 geometry = get_fullscreen_geometry (window);
2814 SetSystemUIMode (kUIModeNormal, 0);
2816 move_resize_window_internal (window,
2822 gdk_window_set_decorations (window, geometry->decor);
2824 g_object_set_data (G_OBJECT (window), FULLSCREEN_DATA, NULL);
2826 gdk_synthesize_window_state (window, GDK_WINDOW_STATE_FULLSCREEN, 0);
2831 gdk_quartz_window_set_keep_above (GdkWindow *window,
2834 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2837 g_return_if_fail (GDK_IS_WINDOW (window));
2839 if (GDK_WINDOW_DESTROYED (window) ||
2840 !WINDOW_IS_TOPLEVEL (window))
2843 level = window_type_hint_to_level (gdk_window_get_type_hint (window));
2845 /* Adjust normal window level by one if necessary. */
2846 [impl->toplevel setLevel: level + (setting ? 1 : 0)];
2850 gdk_quartz_window_set_keep_below (GdkWindow *window,
2853 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2856 g_return_if_fail (GDK_IS_WINDOW (window));
2858 if (GDK_WINDOW_DESTROYED (window) ||
2859 !WINDOW_IS_TOPLEVEL (window))
2862 level = window_type_hint_to_level (gdk_window_get_type_hint (window));
2864 /* Adjust normal window level by one if necessary. */
2865 [impl->toplevel setLevel: level - (setting ? 1 : 0)];
2869 gdk_quartz_window_get_group (GdkWindow *window)
2871 g_return_val_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD, NULL);
2873 if (GDK_WINDOW_DESTROYED (window) ||
2874 !WINDOW_IS_TOPLEVEL (window))
2877 /* FIXME: Implement */
2883 gdk_quartz_window_set_group (GdkWindow *window,
2886 /* FIXME: Implement */
2890 gdk_quartz_window_enable_synchronized_configure (GdkWindow *window)
2895 gdk_quartz_window_configure_finished (GdkWindow *window)
2900 gdk_quartz_window_destroy_notify (GdkWindow *window)
2902 check_grab_destroy (window);
2906 gdk_quartz_window_set_opacity (GdkWindow *window,
2909 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
2911 g_return_if_fail (GDK_IS_WINDOW (window));
2912 g_return_if_fail (WINDOW_IS_TOPLEVEL (window));
2914 if (GDK_WINDOW_DESTROYED (window) ||
2915 !WINDOW_IS_TOPLEVEL (window))
2920 else if (opacity > 1)
2923 [impl->toplevel setAlphaValue: opacity];
2926 static cairo_region_t *
2927 gdk_quartz_window_get_shape (GdkWindow *window)
2929 /* FIXME: implement */
2933 static cairo_region_t *
2934 gdk_quartz_window_get_input_shape (GdkWindow *window)
2936 /* FIXME: implement */
2942 gdk_window_impl_quartz_class_init (GdkWindowImplQuartzClass *klass)
2944 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2945 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_CLASS (klass);
2946 GdkWindowImplQuartzClass *impl_quartz_class = GDK_WINDOW_IMPL_QUARTZ_CLASS (klass);
2948 parent_class = g_type_class_peek_parent (klass);
2950 object_class->finalize = gdk_window_impl_quartz_finalize;
2952 impl_class->ref_cairo_surface = gdk_quartz_ref_cairo_surface;
2953 impl_class->show = gdk_window_quartz_show;
2954 impl_class->hide = gdk_window_quartz_hide;
2955 impl_class->withdraw = gdk_window_quartz_withdraw;
2956 impl_class->set_events = gdk_window_quartz_set_events;
2957 impl_class->get_events = gdk_window_quartz_get_events;
2958 impl_class->raise = gdk_window_quartz_raise;
2959 impl_class->lower = gdk_window_quartz_lower;
2960 impl_class->restack_toplevel = gdk_window_quartz_restack_toplevel;
2961 impl_class->move_resize = gdk_window_quartz_move_resize;
2962 impl_class->set_background = gdk_window_quartz_set_background;
2963 impl_class->reparent = gdk_window_quartz_reparent;
2964 impl_class->set_device_cursor = gdk_window_quartz_set_device_cursor;
2965 impl_class->get_geometry = gdk_window_quartz_get_geometry;
2966 impl_class->get_root_coords = gdk_window_quartz_get_root_coords;
2967 impl_class->get_device_state = gdk_window_quartz_get_device_state;
2968 impl_class->shape_combine_region = gdk_window_quartz_shape_combine_region;
2969 impl_class->input_shape_combine_region = gdk_window_quartz_input_shape_combine_region;
2970 impl_class->set_static_gravities = gdk_window_quartz_set_static_gravities;
2971 impl_class->queue_antiexpose = _gdk_quartz_window_queue_antiexpose;
2972 impl_class->translate = _gdk_quartz_window_translate;
2973 impl_class->destroy = gdk_quartz_window_destroy;
2974 impl_class->destroy_foreign = gdk_quartz_window_destroy_foreign;
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_class->focus = gdk_quartz_window_focus;
2980 impl_class->set_type_hint = gdk_quartz_window_set_type_hint;
2981 impl_class->get_type_hint = gdk_quartz_window_get_type_hint;
2982 impl_class->set_modal_hint = gdk_quartz_window_set_modal_hint;
2983 impl_class->set_skip_taskbar_hint = gdk_quartz_window_set_skip_taskbar_hint;
2984 impl_class->set_skip_pager_hint = gdk_quartz_window_set_skip_pager_hint;
2985 impl_class->set_urgency_hint = gdk_quartz_window_set_urgency_hint;
2986 impl_class->set_geometry_hints = gdk_quartz_window_set_geometry_hints;
2987 impl_class->set_title = gdk_quartz_window_set_title;
2988 impl_class->set_role = gdk_quartz_window_set_role;
2989 impl_class->set_startup_id = _gdk_quartz_window_set_startup_id;
2990 impl_class->set_transient_for = gdk_quartz_window_set_transient_for;
2991 impl_class->get_root_origin = gdk_quartz_window_get_root_origin;
2992 impl_class->get_frame_extents = gdk_quartz_window_get_frame_extents;
2993 impl_class->set_override_redirect = gdk_quartz_window_set_override_redirect;
2994 impl_class->set_accept_focus = gdk_quartz_window_set_accept_focus;
2995 impl_class->set_focus_on_map = gdk_quartz_window_set_focus_on_map;
2996 impl_class->set_icon_list = gdk_quartz_window_set_icon_list;
2997 impl_class->set_icon_name = gdk_quartz_window_set_icon_name;
2998 impl_class->iconify = gdk_quartz_window_iconify;
2999 impl_class->deiconify = gdk_quartz_window_deiconify;
3000 impl_class->stick = gdk_quartz_window_stick;
3001 impl_class->unstick = gdk_quartz_window_unstick;
3002 impl_class->maximize = gdk_quartz_window_maximize;
3003 impl_class->unmaximize = gdk_quartz_window_unmaximize;
3004 impl_class->fullscreen = gdk_quartz_window_fullscreen;
3005 impl_class->unfullscreen = gdk_quartz_window_unfullscreen;
3006 impl_class->set_keep_above = gdk_quartz_window_set_keep_above;
3007 impl_class->set_keep_below = gdk_quartz_window_set_keep_below;
3008 impl_class->get_group = gdk_quartz_window_get_group;
3009 impl_class->set_group = gdk_quartz_window_set_group;
3010 impl_class->set_decorations = gdk_quartz_window_set_decorations;
3011 impl_class->get_decorations = gdk_quartz_window_get_decorations;
3012 impl_class->set_functions = gdk_quartz_window_set_functions;
3013 impl_class->set_functions = gdk_quartz_window_set_functions;
3014 impl_class->begin_resize_drag = gdk_quartz_window_begin_resize_drag;
3015 impl_class->begin_move_drag = gdk_quartz_window_begin_move_drag;
3016 impl_class->enable_synchronized_configure = gdk_quartz_window_enable_synchronized_configure;
3017 impl_class->configure_finished = gdk_quartz_window_configure_finished;
3018 impl_class->set_opacity = gdk_quartz_window_set_opacity;
3019 impl_class->destroy_notify = gdk_quartz_window_destroy_notify;
3020 impl_class->register_dnd = _gdk_quartz_window_register_dnd;
3021 impl_class->drag_begin = _gdk_quartz_window_drag_begin;
3022 impl_class->process_updates_recurse = _gdk_quartz_window_process_updates_recurse;
3023 impl_class->sync_rendering = _gdk_quartz_window_sync_rendering;
3024 impl_class->simulate_key = _gdk_quartz_window_simulate_key;
3025 impl_class->simulate_button = _gdk_quartz_window_simulate_button;
3026 impl_class->get_property = _gdk_quartz_window_get_property;
3027 impl_class->change_property = _gdk_quartz_window_change_property;
3028 impl_class->delete_property = _gdk_quartz_window_delete_property;
3031 impl_quartz_class->get_context = gdk_window_impl_quartz_get_context;
3032 impl_quartz_class->release_context = gdk_window_impl_quartz_release_context;
3036 _gdk_window_impl_quartz_get_type (void)
3038 static GType object_type = 0;
3042 const GTypeInfo object_info =
3044 sizeof (GdkWindowImplQuartzClass),
3045 (GBaseInitFunc) NULL,
3046 (GBaseFinalizeFunc) NULL,
3047 (GClassInitFunc) gdk_window_impl_quartz_class_init,
3048 NULL, /* class_finalize */
3049 NULL, /* class_data */
3050 sizeof (GdkWindowImplQuartz),
3051 0, /* n_preallocs */
3052 (GInstanceInitFunc) gdk_window_impl_quartz_init,
3055 const GInterfaceInfo paintable_info =
3057 (GInterfaceInitFunc) gdk_window_impl_quartz_paintable_init,
3062 object_type = g_type_register_static (GDK_TYPE_WINDOW_IMPL,
3063 "GdkWindowImplQuartz",
3065 g_type_add_interface_static (object_type,
3074 gdk_quartz_window_get_context (GdkWindowImplQuartz *window,
3077 if (!GDK_WINDOW_IMPL_QUARTZ_GET_CLASS (window)->get_context)
3079 g_warning ("%s doesn't implement GdkWindowImplQuartzClass::get_context()",
3080 G_OBJECT_TYPE_NAME (window));
3084 return GDK_WINDOW_IMPL_QUARTZ_GET_CLASS (window)->get_context (window, antialias);
3088 gdk_quartz_window_release_context (GdkWindowImplQuartz *window,
3089 CGContextRef cg_context)
3091 if (!GDK_WINDOW_IMPL_QUARTZ_GET_CLASS (window)->release_context)
3093 g_warning ("%s doesn't implement GdkWindowImplQuartzClass::release_context()",
3094 G_OBJECT_TYPE_NAME (window));
3098 GDK_WINDOW_IMPL_QUARTZ_GET_CLASS (window)->release_context (window, cg_context);
3104 gdk_root_window_impl_quartz_get_context (GdkWindowImplQuartz *window,
3107 CGColorSpaceRef colorspace;
3108 CGContextRef cg_context;
3109 GdkWindowImplQuartz *window_impl = GDK_WINDOW_IMPL_QUARTZ (window);
3111 if (GDK_WINDOW_DESTROYED (window_impl->wrapper))
3114 /* We do not have the notion of a root window on OS X. We fake this
3115 * by creating a 1x1 bitmap and return a context to that.
3117 colorspace = CGColorSpaceCreateWithName (kCGColorSpaceGenericRGB);
3118 cg_context = CGBitmapContextCreate (NULL,
3119 1, 1, 8, 4, colorspace,
3120 kCGImageAlphaPremultipliedLast);
3121 CGColorSpaceRelease (colorspace);
3127 gdk_root_window_impl_quartz_release_context (GdkWindowImplQuartz *window,
3128 CGContextRef cg_context)
3130 CGContextRelease (cg_context);
3134 gdk_root_window_impl_quartz_class_init (GdkRootWindowImplQuartzClass *klass)
3136 GdkWindowImplQuartzClass *window_quartz_class = GDK_WINDOW_IMPL_QUARTZ_CLASS (klass);
3138 root_window_parent_class = g_type_class_peek_parent (klass);
3140 window_quartz_class->get_context = gdk_root_window_impl_quartz_get_context;
3141 window_quartz_class->release_context = gdk_root_window_impl_quartz_release_context;
3145 gdk_root_window_impl_quartz_init (GdkRootWindowImplQuartz *impl)
3150 _gdk_root_window_impl_quartz_get_type (void)
3152 static GType object_type = 0;
3156 const GTypeInfo object_info =
3158 sizeof (GdkRootWindowImplQuartzClass),
3159 (GBaseInitFunc) NULL,
3160 (GBaseFinalizeFunc) NULL,
3161 (GClassInitFunc) gdk_root_window_impl_quartz_class_init,
3162 NULL, /* class_finalize */
3163 NULL, /* class_data */
3164 sizeof (GdkRootWindowImplQuartz),
3165 0, /* n_preallocs */
3166 (GInstanceInitFunc) gdk_root_window_impl_quartz_init,
3169 object_type = g_type_register_static (GDK_TYPE_WINDOW_IMPL_QUARTZ,
3170 "GdkRootWindowQuartz",