Ensure that the widget is fully onscreen before taking a screenshot.

Otherwise X emits a BadMatch and gtk kills the process (!).
Fix #8220
This commit is contained in:
Marco Pesenti Gritti 2008-08-31 14:40:03 +02:00
parent 938e2e9648
commit 6e503b0a24
5 changed files with 29 additions and 7 deletions

View File

@ -200,7 +200,7 @@
(c-name "sugar_preview_take_screenshot") (c-name "sugar_preview_take_screenshot")
(return-type "none") (return-type "none")
(parameters (parameters
'("GdkDrawable" "drawable") '("GtkWidget" "widget")
) )
) )

View File

@ -22,11 +22,11 @@ headers
modulename sugar._sugarext modulename sugar._sugarext
%% %%
import gobject.GObject as PyGObject_Type import gobject.GObject as PyGObject_Type
import gtk.Widget as PyGtkWidget_Type
import gtk.Entry as PyGtkEntry_Type import gtk.Entry as PyGtkEntry_Type
import gtk.Menu as PyGtkMenu_Type import gtk.Menu as PyGtkMenu_Type
import gtk.Container as PyGtkContainer_Type import gtk.Container as PyGtkContainer_Type
import gtk.gdk.Window as PyGdkWindow_Type import gtk.gdk.Window as PyGdkWindow_Type
import gtk.gdk.Drawable as PyGdkDrawable_Type
import gtk.Image as PyGtkImage_Type import gtk.Image as PyGtkImage_Type
%% %%
ignore-glob ignore-glob

View File

@ -754,8 +754,8 @@ class Activity(Window, gtk.Container):
return {} return {}
def take_screenshot(self): def take_screenshot(self):
if self.canvas and self.canvas.window: if self.canvas:
self._preview.take_screenshot(self.canvas.window) self._preview.take_screenshot(self.canvas)
def save(self): def save(self):
"""Request that the activity is saved to the Journal. """Request that the activity is saved to the Journal.

View File

@ -69,16 +69,38 @@ sugar_preview_clear(SugarPreview *preview)
} }
} }
void static gboolean
sugar_preview_take_screenshot(SugarPreview *preview, GdkDrawable *drawable) widget_is_off_screen(GtkWidget *widget)
{ {
GdkScreen *screen;
gint x, y, width, height;
screen = gtk_widget_get_screen(widget);
gdk_window_get_geometry(widget->window, &x, &y, &width, &height, NULL);
return (x < 0 || y < 0 ||
x + width > gdk_screen_get_width(screen) ||
y + height > gdk_screen_get_height(screen));
}
void
sugar_preview_take_screenshot(SugarPreview *preview, GtkWidget *widget)
{
GdkDrawable *drawable;
GdkScreen *screen; GdkScreen *screen;
GdkVisual *visual; GdkVisual *visual;
GdkColormap *colormap; GdkColormap *colormap;
gint width, height; gint width, height;
if (widget->window == NULL || widget_is_off_screen(widget)) {
return;
}
sugar_preview_clear(preview); sugar_preview_clear(preview);
drawable = GDK_DRAWABLE(widget->window);
gdk_drawable_get_size(drawable, &width, &height); gdk_drawable_get_size(drawable, &width, &height);
screen = gdk_drawable_get_screen(drawable); screen = gdk_drawable_get_screen(drawable);

View File

@ -50,7 +50,7 @@ struct _SugarPreviewClass {
GType sugar_preview_get_type (void); GType sugar_preview_get_type (void);
void sugar_preview_take_screenshot (SugarPreview *preview, void sugar_preview_take_screenshot (SugarPreview *preview,
GdkDrawable *drawable); GtkWidget *widget);
void sugar_preview_set_size (SugarPreview *preview, void sugar_preview_set_size (SugarPreview *preview,
int width, int width,
int height); int height);