Toolbar Editor is throwing gtk-critical messages (patch included)



Toolbar Editor is throwing the following error:

Gtk-CRITICAL **: gtk_widget_set_window: assertion `window == NULL ||
GDK_IS_WINDOW (window)' failed.

I debugged the problem and it happens during the creation of the
Toolbar Separator pixbuf.

I attached a patch that fixes this by replacing the fake_expose_widget
method with a combination of the gtk_offscreen_window and
gtk_widget_get_snapshot method.

opinions, suggestions and reviews will be appreciated.

regards
/jk
From 735983ede47f62c66d05aa481aaa7c78357de54c Mon Sep 17 00:00:00 2001
From: Jorge Kalmbach <kalmbach gmail com>
Date: Wed, 14 Jul 2010 01:38:47 -0300
Subject: [PATCH] refactored new_pixbuf_from_widget using gtk_offscreen_window

---
 lib/egg/egg-editable-toolbar.c |   52 +++++----------------------------------
 1 files changed, 7 insertions(+), 45 deletions(-)

diff --git a/lib/egg/egg-editable-toolbar.c b/lib/egg/egg-editable-toolbar.c
index adcab7f..983d746 100644
--- a/lib/egg/egg-editable-toolbar.c
+++ b/lib/egg/egg-editable-toolbar.c
@@ -1737,26 +1737,6 @@ egg_editable_toolbar_set_fixed (EggEditableToolbar *etoolbar,
 #define DEFAULT_ICON_HEIGHT 20
 #define DEFAULT_ICON_WIDTH 0
 
-static void
-fake_expose_widget (GtkWidget *widget,
-		    GdkPixmap *pixmap)
-{
-  GdkWindow *tmp_window;
-  GdkEventExpose event;
-
-  event.type = GDK_EXPOSE;
-  event.window = pixmap;
-  event.send_event = FALSE;
-  gtk_widget_get_allocation (widget, &event.area);
-  event.region = NULL;
-  event.count = 0;
-
-  tmp_window = gtk_widget_get_window (widget);
-  gtk_widget_set_window (widget, pixmap);
-  gtk_widget_send_expose (widget, (GdkEvent *) &event);
-  gtk_widget_set_window (widget, tmp_window);
-}
-
 /* We should probably experiment some more with this.
  * Right now the rendered icon is pretty good for most
  * themes. However, the icon is slightly large for themes
@@ -1771,7 +1751,6 @@ new_pixbuf_from_widget (GtkWidget *widget)
   GtkAllocation allocation;
   GtkStyle *style;
   GdkPixmap *pixmap;
-  GdkVisual *visual;
   gint icon_width;
   gint icon_height;
   GdkScreen *screen;
@@ -1788,13 +1767,8 @@ new_pixbuf_from_widget (GtkWidget *widget)
       icon_height = DEFAULT_ICON_HEIGHT;
     }
 
-  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-  
-  gtk_container_add (GTK_CONTAINER (window), widget);
-  gtk_widget_realize (window);
-  gtk_widget_show (widget);
-  gtk_widget_realize (widget);
-  gtk_widget_map (widget);
+  window = gtk_offscreen_window_new ();  
+  gtk_container_add (GTK_CONTAINER (window), widget);   
 
   /* Gtk will never set the width or height of a window to 0. So setting the width to
    * 0 and than getting it will provide us with the minimum width needed to render
@@ -1802,7 +1776,7 @@ new_pixbuf_from_widget (GtkWidget *widget)
    * This is needed mostly for pixmap based themes.
    */
   gtk_window_set_default_size (GTK_WINDOW (window), icon_width, icon_height);
-  gtk_window_get_size (GTK_WINDOW (window),&icon_width, &icon_height);
+  gtk_window_get_size (GTK_WINDOW (window), &icon_width, &icon_height);
 
   gtk_widget_size_request (window, &requisition);
   allocation.x = 0;
@@ -1812,22 +1786,10 @@ new_pixbuf_from_widget (GtkWidget *widget)
   gtk_widget_size_allocate (window, &allocation);
   gtk_widget_size_request (window, &requisition);
   
-  /* Create a pixmap */
-  visual = gtk_widget_get_visual (window);
-  pixmap = gdk_pixmap_new (NULL, icon_width, icon_height, gdk_visual_get_depth (visual));
-  gdk_drawable_set_colormap (GDK_DRAWABLE (pixmap), gtk_widget_get_colormap (window));
-
-  /* Draw the window */
-  gtk_widget_ensure_style (window);
-  style = gtk_widget_get_style (window);
-  g_assert (style);
-  g_assert (style->font_desc);
-  
-  fake_expose_widget (window, pixmap);
-  fake_expose_widget (widget, pixmap);
-  
-  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, icon_width, icon_height);
-  gdk_pixbuf_get_from_drawable (pixbuf, pixmap, NULL, 0, 0, 0, 0, icon_width, icon_height);
+  gtk_widget_show_all (window);
+
+  pixmap = gtk_widget_get_snapshot (GTK_WIDGET (widget), NULL); 
+  pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, gtk_widget_get_colormap (window), 0, 0, 0, 0, icon_width, icon_height);
 
   gtk_widget_destroy (window);
 
-- 
1.7.0.4



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