Using gdk_pixbuf_xlib_get_from_drawable()


I have a problem using the function from the subject. I think I'm
just missing something about how the function works. Here is the
code (it's just a short program to test the function):

### BEGIN CODE ###

#include <gdk-pixbuf-xlib/gdk-pixbuf-xlib.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>

static void
screenshot (GtkWidget *widget)
  GdkPixbuf *image;
  XWindowAttributes wa;
  Window win;
  win = GDK_WINDOW_XID (widget->window);
  XGetWindowAttributes (GDK_DISPLAY(), win, &wa);
  image = gdk_pixbuf_xlib_get_from_drawable (NULL, 
                                             win, 0, NULL,
                                             0, 0, 0, 0,
                                             wa.width, wa.height);
  gdk_pixbuf_save (image, "test.png", "png", NULL, NULL);

main (int argc, char *argv[])
  GtkWidget *window, *button;
  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  button = gtk_button_new_with_label ("Hello");
  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (screenshot), NULL);
  gtk_container_add (GTK_CONTAINER (window), button);
  gtk_widget_show_all (window);
  gtk_main ();
  return 0;

### END CODE ###

It is crashing in the .._from_drawable() function as you can
see here:

Program received signal SIGSEGV, Segmentation fault.
0x004943dd in XGetWindowAttributes () from /usr/lib/
(gdb) where
#0  0x004943dd in XGetWindowAttributes () from /usr/lib/
#1  0x004651d9 in gdk_pixbuf_xlib_get_from_drawable ()
   from /usr/lib/
#2  0x080488ab in screenshot (widget=0x9caed68) at test.c:36

I am compiling with:
gcc -Wall -g test.c -o exe `pkg-config --cflags --libs gtk+-2.0

Thank you for any help you can give me! - Andrew

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]