5 static void selection_received( GtkWidget *widget,
6 GtkSelectionData *selection_data,
9 /* Signal handler invoked when user clicks on the "Get Targets" button */
10 static void get_targets( GtkWidget *widget,
13 static GdkAtom targets_atom = GDK_NONE;
14 GtkWidget *window = (GtkWidget *)data;
16 /* Get the atom corresponding to the string "TARGETS" */
17 if (targets_atom == GDK_NONE)
18 targets_atom = gdk_atom_intern ("TARGETS", FALSE);
20 /* And request the "TARGETS" target for the primary selection */
21 gtk_selection_convert (window, GDK_SELECTION_PRIMARY, targets_atom,
25 /* Signal handler called when the selections owner returns the data */
26 static void selection_received( GtkWidget *widget,
27 GtkSelectionData *selection_data,
34 /* **** IMPORTANT **** Check to see if retrieval succeeded */
35 if (selection_data->length < 0)
37 g_print ("Selection retrieval failed\n");
40 /* Make sure we got the data in the expected form */
41 if (selection_data->type != GDK_SELECTION_TYPE_ATOM)
43 g_print ("Selection \"TARGETS\" was not returned as atoms!\n");
47 /* Print out the atoms we received */
48 atoms = (GdkAtom *)selection_data->data;
51 for (i = 0; i < selection_data->length / sizeof(GdkAtom); i++)
54 name = gdk_atom_name (atoms[i]);
56 g_print ("%s\n",name);
58 g_print ("(bad atom)\n");
70 gtk_init (&argc, &argv);
72 /* Create the toplevel window */
74 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
75 gtk_window_set_title (GTK_WINDOW (window), "Event Box");
76 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
78 g_signal_connect (window, "destroy",
79 G_CALLBACK (exit), NULL);
81 /* Create a button the user can click to get targets */
83 button = gtk_button_new_with_label ("Get Targets");
84 gtk_container_add (GTK_CONTAINER (window), button);
86 g_signal_connect (button, "clicked",
87 G_CALLBACK (get_targets), (gpointer) window);
88 g_signal_connect (window, "selection-received",
89 G_CALLBACK (selection_received), NULL);
91 gtk_widget_show (button);
92 gtk_widget_show (window);