[gtk+/quartz-integration] Bug #655074: Fix crash with undecorated windows on MacOS Lion Original patch by Michael Hutchison Mo



commit 516dd460ebe6022a957c4876de78dfe9a89d0a13
Author: Michael Hutchinson <m j hutchinson gmail com>
Date:   Thu Jul 21 21:52:08 2011 +0100

    Bug #655074: Fix crash with undecorated windows on MacOS Lion
    Original patch by Michael Hutchison
    Modified for Gtk+-3.0 and testundecorated added by John Ralls

 gdk/quartz/gdkwindow-quartz.c |   31 +++++++++++++++++++------------
 tests/Makefile.am             |    6 +++++-
 tests/testundecorated.c       |   29 +++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 13 deletions(-)
---
diff --git a/gdk/quartz/gdkwindow-quartz.c b/gdk/quartz/gdkwindow-quartz.c
index a6fc4ed..ebfd795 100644
--- a/gdk/quartz/gdkwindow-quartz.c
+++ b/gdk/quartz/gdkwindow-quartz.c
@@ -2559,10 +2559,6 @@ gdk_quartz_window_set_decorations (GdkWindow       *window,
 
   old_mask = [impl->toplevel styleMask];
 
-  /* Note, there doesn't seem to be a way to change this without
-   * recreating the toplevel. There might be bad side-effects of doing
-   * that, but it seems alright.
-   */
   if (old_mask != new_mask)
     {
       NSRect rect;
@@ -2586,15 +2582,26 @@ gdk_quartz_window_set_decorations (GdkWindow       *window,
           rect = [NSWindow contentRectForFrameRect:rect styleMask:old_mask];
         }
 
-      impl->toplevel = [impl->toplevel initWithContentRect:rect
-                                                 styleMask:new_mask
-                                                   backing:NSBackingStoreBuffered
-                                                     defer:NO];
-
-      [impl->toplevel setHasShadow: window_type_hint_to_shadow (impl->type_hint)];
-      [impl->toplevel setLevel: window_type_hint_to_level (impl->type_hint)];
+      /* Note, before OS 10.6 there doesn't seem to be a way to change this without
+       * recreating the toplevel. There might be bad side-effects of doing
+       * that, but it seems alright.
+       */
+      if ([impl->toplevel respondsToSelector:@selector(setStyleMask:)])
+        {
+          [impl->toplevel setStyleMask:new_mask];
+        }
+      else
+        {
+          [impl->toplevel release];
+          impl->toplevel = [[GdkQuartzNSWindow alloc] initWithContentRect:rect
+                                                              styleMask:new_mask
+                                                                backing:NSBackingStoreBuffered
+                                                                  defer:NO];
+          [impl->toplevel setHasShadow: window_type_hint_to_shadow (impl->type_hint)];
+          [impl->toplevel setLevel: window_type_hint_to_level (impl->type_hint)];
+          [impl->toplevel setContentView:old_view];
+        }
 
-      [impl->toplevel setContentView:old_view];
       [impl->toplevel setFrame:rect display:YES];
 
       /* Invalidate the window shadow for non-opaque views that have shadow
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7bed9b2..fce7d30 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -118,7 +118,8 @@ noinst_PROGRAMS =  $(TEST_PROGS)	\
 	testpixbuf-save			\
 	testpixbuf-color		\
 	testpixbuf-scale		\
-	widget-factory
+	widget-factory			\
+	testundecorated
 
 if USE_X11
 noinst_PROGRAMS += testerrors
@@ -226,6 +227,7 @@ testpixbuf_save_DEPENDENCIES = $(TEST_DEPS)
 testpixbuf_color_DEPENDENCIES = $(TEST_DEPS)
 testpixbuf_scale_DEPENDENCIES = $(TEST_DEPS)
 widget_factory_DEPENDENCIES = $(TEST_DEPS)
+testundecorated_DEPENDENCIES = $(TEST_DEPS)
 
 flicker_LDADD = $(LDADDS)
 simple_LDADD = $(LDADDS)
@@ -320,6 +322,7 @@ testpixbuf_save_LDADD = $(LDADDS)
 testpixbuf_color_LDADD = $(LDADDS)
 testpixbuf_scale_LDADD = $(LDADDS)
 widget_factory_LDADD = $(LDADDS)
+testundecorated_LDADD = $(LDADDS)
 
 
 testboxcss_SOURCES =	\
@@ -484,6 +487,7 @@ testpixbuf_save_SOURCES = testpixbuf-save.c
 
 widget_factory_SOURCES = widget-factory.c
 
+testundecorated_SOURCES = testundecorated.c
 
 EXTRA_DIST += 			\
 	gradient1.png		\
diff --git a/tests/testundecorated.c b/tests/testundecorated.c
new file mode 100644
index 0000000..2024464
--- /dev/null
+++ b/tests/testundecorated.c
@@ -0,0 +1,29 @@
+#include <gtk/gtk.h>
+
+static gboolean
+destroy_cb (GtkWidget *win)
+{
+    gtk_widget_destroy (win);
+    gtk_main_quit();
+    return FALSE;
+}
+
+static void
+show_window (void)
+{
+    GtkWidget *win;
+    win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+    gtk_window_set_decorated (GTK_WINDOW (win), FALSE);
+    gtk_window_set_title (GTK_WINDOW (win), "Naked");
+    gtk_widget_show_all (win);
+    g_timeout_add_seconds (5, (GSourceFunc)destroy_cb, win);
+}
+
+int
+main(int argc, char** argv)
+{
+    gtk_init (&argc, &argv);
+    show_window();
+    gtk_main();
+    return 0;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]