gtk_type_init() with no X connection [was: Re: horrible things]



On Wed, 2001-10-24 at 21:15, Owen Taylor wrote:
> 
> > > jacob berkman <jacob ximian com> writes:
> > > 
> > > > this patch allows the gtk docs to build w/o an X connection.
> 
> Looks like its definitely heading in the right direction. But
> there is a much simpler solution for GtkPreview - just let it
> use the default visual and colormap for the widget instead of setting 
> something different:
> 
>  - The GdkRGB visual/colormap are the default now
>  - GdkRGB can render into any visual/colormap now
> 
> I think it should be possible to fix GtkPreview with a '-' only
> patch.

ok - this patch does that, but i'm not sure it's the right thing.

there is currently code (mostly in gimp) which does:

gtk_widget_push_colormap (gtk_preview_get_colormap ());

this could be safely removed - since you don't need to push the colormap
/ visual any more.  with this patch, gtk_preview_get_colormap () would
return NULL, and you'd get failed assertions.

so, that could either be left in such that people should remove the
push/pop, or _get_colormap() could return gdk_rgb_get_colormap().

(maybe the visual / colormap fields should be removed if the former?)

i also fixed up colorsel per your suggestions.

jacob
-- 
"Beat mixing is 10000 times more fun than even video games."
	-- bt
Index: gtkpreview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkpreview.c,v
retrieving revision 1.36
diff -u -r1.36 gtkpreview.c
--- gtkpreview.c	2001/07/18 23:39:23	1.36
+++ gtkpreview.c	2001/10/27 19:03:21
@@ -125,8 +125,6 @@
   klass->info.gamma = 1.0;
 
   gdk_rgb_init ();
-  klass->info.cmap = gdk_rgb_get_cmap ();
-  klass->info.visual = gdk_rgb_get_visual ();
 
   g_object_class_install_property (gobject_class,
                                    PROP_EXPAND,
@@ -313,7 +311,6 @@
 
   g_return_if_fail (GTK_IS_PREVIEW (preview));
   g_return_if_fail (data != NULL);
-  g_return_if_fail (preview_class->info.visual != NULL);
   
   bpp = (preview->type == GTK_PREVIEW_COLOR ? 3 : 1);
   rowstride = (preview->buffer_width * bpp + 3) & -4;
@@ -491,10 +488,8 @@
   attributes.y = widget->allocation.y + (widget->allocation.height - attributes.height) / 2;;
 
   attributes.wclass = GDK_INPUT_OUTPUT;
-  attributes.visual = preview_class->info.visual;
-  attributes.colormap = preview_class->info.cmap;
   attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
-  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+  attributes_mask = GDK_WA_X | GDK_WA_Y;
 
   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
   gdk_window_set_user_data (widget->window, widget);
Index: gtkcolorsel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcolorsel.c,v
retrieving revision 1.78
diff -u -r1.78 gtkcolorsel.c
--- gtkcolorsel.c	2001/10/11 20:37:51	1.78
+++ gtkcolorsel.c	2001/10/27 19:03:21
@@ -143,6 +143,7 @@
 static void gtk_color_selection_class_init	(GtkColorSelectionClass	 *klass);
 static void gtk_color_selection_destroy		(GtkObject		 *object);
 static void gtk_color_selection_finalize        (GObject		 *object);
+static void gtk_color_selection_realize         (GtkWidget               *widget);
 static void update_color			(GtkColorSelection	 *colorsel);
 static void gtk_color_selection_set_property    (GObject                 *object,
 					         guint                    prop_id,
@@ -1648,10 +1649,11 @@
 {
   GtkObjectClass *object_class;
   GObjectClass *gobject_class;
-  gchar *palette;
+  GtkWidgetClass *widget_class;
   
   object_class = GTK_OBJECT_CLASS (klass);
   gobject_class = G_OBJECT_CLASS (klass);
+  widget_class = GTK_WIDGET_CLASS (klass);
   
   parent_class = gtk_type_class (GTK_TYPE_VBOX);
   
@@ -1661,6 +1663,8 @@
   gobject_class->set_property = gtk_color_selection_set_property;
   gobject_class->get_property = gtk_color_selection_get_property;
   
+  widget_class->realize = gtk_color_selection_realize;
+
   g_object_class_install_property (gobject_class,
                                    PROP_HAS_OPACITY_CONTROL,
                                    g_param_spec_boolean ("has_opacity_control",
@@ -1703,21 +1707,6 @@
                                                       _("Palette to use in the color selector"),
                                                       default_colors,
                                                       G_PARAM_READWRITE));
-
-  g_object_get (G_OBJECT (gtk_settings_get_default ()),
-                "gtk-color-palette",
-                &palette,
-                NULL);
-  
-  fill_palette_from_string (palette);
-  g_free (palette);
-
-  change_palette_hook = default_change_palette_func;
-  
-  g_signal_connect_data (G_OBJECT (gtk_settings_get_default ()),
-                         "notify::gtk-color-palette",
-                         G_CALLBACK (palette_change_notify_class),
-                         NULL, NULL, 0);
 }
 
 /* widget functions */
@@ -1875,16 +1864,6 @@
   
   gtk_widget_show_all (top_hbox);
 
-  /* Set default colors */
-
-  update_palette (colorsel);
-
-  priv->settings_connection = 
-    g_signal_connect_data (G_OBJECT (gtk_settings_get_default ()),
-                           "notify::gtk-color-palette",
-                           G_CALLBACK (palette_change_notify_instance),
-                           colorsel, NULL, 0);
-  
   /* hide unused stuff */
   
   if (priv->has_opacity == FALSE)
@@ -1942,6 +1921,43 @@
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+static void
+gtk_color_selection_realize (GtkWidget *widget)
+{
+  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (widget);
+  ColorSelectionPrivate *priv = colorsel->private_data;
+  gchar *palette;
+
+  g_object_get (G_OBJECT (gtk_settings_get_default ()),
+                "gtk-color-palette",
+                &palette,
+                NULL);
+  
+  fill_palette_from_string (palette);
+  g_free (palette);
+
+  if (!change_palette_hook)
+    {
+      change_palette_hook = default_change_palette_func;
+  
+      g_signal_connect (gtk_settings_get_default (),
+			"notify::gtk-color-palette",
+			G_CALLBACK (palette_change_notify_class),
+			NULL);
+    }
+  
+  /* Set default colors */
+
+  update_palette (colorsel);
+  priv->settings_connection =
+    g_signal_connect (gtk_settings_get_default (),
+		      "notify::gtk-color-palette",
+		      G_CALLBACK (palette_change_notify_instance),
+		      colorsel);
+
+  if (GTK_WIDGET_CLASS (parent_class)->realize)
+    GTK_WIDGET_CLASS (parent_class)->realize (widget);
+}
 
 /**
  * gtk_color_selection_new:


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