Skip to content

Instantly share code, notes, and snippets.

@remleduff
Created May 26, 2010 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remleduff/414786 to your computer and use it in GitHub Desktop.
Save remleduff/414786 to your computer and use it in GitHub Desktop.
GtkOffscreenWindow* offscreenWindow;
GtkPixmap* snapshotWidget(GtkWidget* widget) {
// Caching doesn't work, must create a new one every time (the widget parameter is gtk_widget_destroy'ed by the caller)
// if (!offscreenWindow)
offscreenWindow = gtk_offscreen_window_new();
gtk_container_add(offscreenWindow, widget);
gtk_widget_show(offscreenWindow);
force_draw(widget);
// This doesn't seem to make any difference
// force_draw(offscreenWindow);
GtkPixmap* result = gtk_offscreen_window_get_pixmap(offscreenWindow)
// Doesn't work
// gtk_widget_destroy(offscreenWindow);
return result;
}
void force_draw(GtkWidget* widget) {
gtk_widget_queue_draw(widget);
GdkWindow* window = gtk_widget_get_window(widget);
gdk_window_process_updates(window, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment