Re: [NEWBIE] How to put text onto system-wide clipboard?
- From: "Freddie Unpenstein" <fredderic excite com>
- To: neo_in_matrix fastmail fm
- Cc: gtk-app-devel-list gnome org
- Subject: Re: [NEWBIE] How to put text onto system-wide clipboard?
- Date: Mon, 11 Apr 2005 10:58:36 -0400 (EDT)
The short of it is that in both Linux and Windows, there is no
"system-wide" clipboard (there's no clipboard in the Windows
console-level step-by-step boot before the GUI starts). However,
there is a lovely clipboard mechanism provided by the X GUI, and
supported by GTK+. You can find the API here:
http://developer.gnome.org/doc/API/2.0/gtk/gtk-Clipboards.html
Thanks. Can someone give me a few lines of sample code?
GtkClipboard *clip = gtk_clipboard_get(clip_atom);
To fetch simple text content, use:
char *text = gtk_clipboard_wait_for_text(clip);
To put text into the clipboard, use:
gtk_clipboard_set_text(clip, bufr, len);
If you want to hang around after you quit, it's supposed to go something like this (although I've never
gotten it to work):
gtk_clipboard_set_can_store(clip, NULL, 0);
...or...
gtk_clipboard_store(clip);
The "can store" is supposed to do it automatically just before you quit, or something. The straight "store"
one is supposed to do make it stick immediately. Sticking it means copying the content into a clipboard
manager if one exists, hence the preference for "can store", which only does the handoff once the program's
no longer going to be running.
It works for me just fine while the program is running (which is fine for many applications), but I've never
gotten it to preserve the text once the program quits -- note that you NEED a clipboard manager running in
order to have any chance of the text staying after program close. I tested it with gEdit... Without the
clipboard manager, the text vanishes from the clipboard as soon as gEdit closes. With the clipboard manager
loaded, the text is still available to paste.
Fredderic
_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]