[gtk+/gtk-2-24-quartz] Bug #655074: Fix crash with undecorated windows on MacOS Lion



commit 97d11999b0abe531e9d128eedccda17598da260a
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
    
    Patch by Michael Hutchison, testundecorated by John Ralls

 gdk/quartz/gdkwindow-quartz.c |   31 +++++++++++++++++++------------
 tests/Makefile.am             |    9 +++++++--
 tests/testundecorated.c       |   29 +++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 14 deletions(-)
---
diff --git a/gdk/quartz/gdkwindow-quartz.c b/gdk/quartz/gdkwindow-quartz.c
index b28d9b7..486b36a 100644
--- a/gdk/quartz/gdkwindow-quartz.c
+++ b/gdk/quartz/gdkwindow-quartz.c
@@ -2622,10 +2622,6 @@ gdk_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;
@@ -2649,15 +2645,26 @@ gdk_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 = [[GdkQuartzWindow 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 e011484..874c2f4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -88,7 +88,8 @@ noinst_PROGRAMS =  $(TEST_PROGS)	\
 	testactions			\
 	testgrouping			\
 	testtooltips			\
-	testvolumebutton
+	testvolumebutton                \
+	testundecorated
 
 if HAVE_CXX
 noinst_PROGRAMS += autotestkeywords
@@ -165,6 +166,7 @@ testgrouping_DEPENDENCIES = $(TEST_DEPS)
 testtooltips_DEPENDENCIES = $(TEST_DEPS)
 testvolumebutton_DEPENDENCIES = $(TEST_DEPS)
 testwindows_DEPENDENCIES = $(TEST_DEPS)
+testundecorated_DEPENDENCIES = $(TEST_DEPS)
 
 flicker_LDADD = $(LDADDS)
 simple_LDADD = $(LDADDS)
@@ -231,7 +233,7 @@ testgrouping_LDADD = $(LDADDS)
 testtooltips_LDADD = $(LDADDS)
 testvolumebutton_LDADD = $(LDADDS)
 testwindows_LDADD = $(LDADDS)
-
+testundecorated_LDADD = $(LDADDS)
 
 testentrycompletion_SOURCES = 	\
 	prop-editor.c		\
@@ -340,6 +342,9 @@ testoffscreenwindow_SOURCES =	\
 testwindows_SOURCES = 	\
 	testwindows.c
 
+testundecorated_SOURCES = \
+	testundecorated.c
+
 EXTRA_DIST += 			\
 	prop-editor.h		\
 	testgtk.1 		\
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]