How can I save the current window as an image file such as a png?
I know I can get a gdkWindow from current windows. I can even get an image. From this image struct
Use gdk_pixbuf_get_from_drawable to get from the GdkWindow
to a GdkPixbuf
, then if you want to save to a file use gdk_pixbuf_save.
In Cairo, which is the more future-proof method, you could use cairo_image_surface_create, pass the result to cairo_create, pass that to gdk_cairo_set_source_window, copy to your image surface with cairo_paint, and write your image with cairo_surface_write_to_png.
Also note that your question is similar to this one. However, since the answer to that question does not work, if my answer answers your question, I'll close the other question as a dupe of this.