Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think this should do it, although you may need to iterate the main loop after showing the window to get it to paint properly, in which case you'll need some more code (I haven't tested this)</p> <pre><code>#include &lt;unistd.h&gt; #include &lt;stdio.h&gt; #include &lt;gtk/gtk.h&gt; #include &lt;cairo.h&gt; static GtkWidget* createWindow() { GtkWidget *window; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window), 800, 600); gtk_widget_set_name(window, "GtkLauncher"); g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); return window; } int main(int argc, char **argv) { gdk_init(&amp;argc, &amp;argv); GtkWidget *main_window = createWindow(); gtk_widget_show_all(main_window); // may not need this, it also may not be enough either while (gtk_events_pending ()) gtk_main_iteration (); GdkWindow *w = GDK_WINDOW(main_window); gint width, height; gdk_drawable_get_size(GDK_DRAWABLE(w), &amp;width, &amp;height); GdkPixbuf *pb = gdk_pixbuf_get_from_drawable(NULL, GDK_DRAWABLE(w), NULL, 0,0,0,0,width,height); if(pb != NULL) { gdk_pixbuf_save(pb, "screenshot.png", "png", NULL); g_print("Screenshot saved to screenshot.png.\n"); } else { g_print("Unable to get the screenshot.\n"); } return 0; } </code></pre> <p>If it doesn't work you'll have to move the screenshot taking into an event handler that connects to some event (I'm not sure which probably <code>window-state-event</code> then you have to look at the event to figure out when to take the screenshot)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload