Hi,
I have a question regarding the function
void gtk_clipboard_request_text (GtkClipboard *clipboard,
GtkClipboardTextReceivedFunc callback,
gpointer user_data);
How long is the lifetime of the clipboard data we get via this function?
Is it as long as the function call to GtkClipboardTextReceivedFunc?
I wrote two test cases as below:
====== test case 1 ======
#include <gtk/gtk.h>
#define TEXT "Hello"
static gchar *global_text;
void global_text_receive (GtkClipboard *clipboard, const gchar *text, gpointer data)
{
global_text = (gchar *)text;
}
int main(int argc, char *argv[])
{
GtkClipboard* clipboard;
gtk_init (&argc, &argv);
clipboard = gtk_clipboard_get (GDK_NONE);
gtk_clipboard_set_text (clipboard, TEXT, strlen (TEXT));
gtk_clipboard_request_text (clipboard, global_text_receive, NULL);
if (strcmp (TEXT, global_text))
g_printf ("Texts not equal, TEXT=%s, clipdata=%s\n", TEXT, global_text);
else
g_printf ("Texts equal\n");
return 0;
}
Outputs of running the compiled code for 4 times are as the following
$ ./a.out
Texts not equal, TEXT=Hello, clipdata= S\uffff o
$ ./a.out
Texts not equal, TEXT=Hello, clipdata= so
$ ./a.out
Texts not equal, TEXT=Hello, clipdata= \uffffo
$ ./a.out
Texts not equal, TEXT=Hello, clipdata= 3\uffff o
====== test case 2 ======
#include <gtk/gtk.h>
#define TEXT "Hello"
void global_text_receive (GtkClipboard *clipboard, const gchar *text, gpointer data)
{
if (strcmp (TEXT, (const gchar *)data))
g_printf ("Texts not equal, TEXT=%s, clipdata=%s\n", TEXT, (const gchar *)data);
else
g_printf ("Texts equal\n");
}
int main(int argc, char *argv[])
{
GtkClipboard* clipboard;
gtk_init (&argc, &argv);
clipboard = gtk_clipboard_get (GDK_NONE);
gtk_clipboard_set_text (clipboard, TEXT, strlen (TEXT));
gtk_clipboard_request_text (clipboard, global_text_receive, TEXT);
return 0;
}
Output is as below
$ ./a.out
Texts equal
Is my understanding correct?
Thanks
Yong