diff --git a/src/sugar/_sugarext.defs b/src/sugar/_sugarext.defs index 87d629f6..72ff7af4 100644 --- a/src/sugar/_sugarext.defs +++ b/src/sugar/_sugarext.defs @@ -200,7 +200,7 @@ (c-name "sugar_preview_take_screenshot") (return-type "none") (parameters - '("GdkDrawable" "drawable") + '("GtkWidget" "widget") ) ) diff --git a/src/sugar/_sugarext.override b/src/sugar/_sugarext.override index b9936004..a68564a3 100644 --- a/src/sugar/_sugarext.override +++ b/src/sugar/_sugarext.override @@ -22,11 +22,11 @@ headers modulename sugar._sugarext %% import gobject.GObject as PyGObject_Type +import gtk.Widget as PyGtkWidget_Type import gtk.Entry as PyGtkEntry_Type import gtk.Menu as PyGtkMenu_Type import gtk.Container as PyGtkContainer_Type import gtk.gdk.Window as PyGdkWindow_Type -import gtk.gdk.Drawable as PyGdkDrawable_Type import gtk.Image as PyGtkImage_Type %% ignore-glob diff --git a/src/sugar/activity/activity.py b/src/sugar/activity/activity.py index f74bb557..73eeea74 100644 --- a/src/sugar/activity/activity.py +++ b/src/sugar/activity/activity.py @@ -754,8 +754,8 @@ class Activity(Window, gtk.Container): return {} def take_screenshot(self): - if self.canvas and self.canvas.window: - self._preview.take_screenshot(self.canvas.window) + if self.canvas: + self._preview.take_screenshot(self.canvas) def save(self): """Request that the activity is saved to the Journal. diff --git a/src/sugar/sugar-preview.c b/src/sugar/sugar-preview.c index 42fb9d31..44b83e4d 100644 --- a/src/sugar/sugar-preview.c +++ b/src/sugar/sugar-preview.c @@ -69,16 +69,38 @@ sugar_preview_clear(SugarPreview *preview) } } -void -sugar_preview_take_screenshot(SugarPreview *preview, GdkDrawable *drawable) +static gboolean +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; GdkVisual *visual; GdkColormap *colormap; gint width, height; + if (widget->window == NULL || widget_is_off_screen(widget)) { + return; + } + sugar_preview_clear(preview); + drawable = GDK_DRAWABLE(widget->window); + gdk_drawable_get_size(drawable, &width, &height); screen = gdk_drawable_get_screen(drawable); diff --git a/src/sugar/sugar-preview.h b/src/sugar/sugar-preview.h index 6029cc17..70ea1562 100644 --- a/src/sugar/sugar-preview.h +++ b/src/sugar/sugar-preview.h @@ -50,7 +50,7 @@ struct _SugarPreviewClass { GType sugar_preview_get_type (void); void sugar_preview_take_screenshot (SugarPreview *preview, - GdkDrawable *drawable); + GtkWidget *widget); void sugar_preview_set_size (SugarPreview *preview, int width, int height);