How can I read and write blocks of plain text into the clipboard?
If there is no easy cross-platform way of doing it, it must be specific to *nix systems.
I tried searching the Web but all the results are in C++/C# and Windows-specific.
Printable View
How can I read and write blocks of plain text into the clipboard?
If there is no easy cross-platform way of doing it, it must be specific to *nix systems.
I tried searching the Web but all the results are in C++/C# and Windows-specific.
Well, two of the more popular Desktop environments (KDE, and Gnome) for *nix systems, use their own clipboard system, klipper, and Gnome clipboard manager, respectively. Of course, if you are running one of these DE's, then you are also running X, and therefore you also have xclipboard available for use as well. That should get you started anyway.
I guess that xclipboard would be better because it it would be desktop manager-independent. But would it be able to copy and paste with my GNOME applications?
GNOME uses gtk, which is (I think) the stuff abachler refers to is, altho I don't have a DE installed so can't confirm that.
This is the xclipboard; if you use xclipboard you can check the contents, they are the same. There is, in fact, another clipboard which does not rely on the GUI or the use of cut n' paste in a menu. I think many linux users may be unaware of it, but if you simply highlight some text somewhere, leave it highlighted, then go somewhere else and click button 3/both buttons, you will get the contents of the highlighted region. However, that text is not in the xclipboard. I have never investigated how to program it, but I make use of this a lot (the fact that you can have two different clipboard buffers and access them with different methods), but the uncommon one (no GUI interaction using mouse button 3) is not consistent, and that is not what you want. Sorry if that is unnecessarily confusing.Code:void copytoX (GtkWidget *ignored, int opt) {
GdkDisplay *display = gdk_display_get_default();
GtkClipboard *clipboard = gtk_clipboard_get_for_display(display,GDK_SELECTION_CLIPBOARD);
if (opt) { gtk_text_buffer_get_bounds(Tbuf,&start,&finish);
gtk_text_buffer_select_range(Tbuf,(const GtkTextIter*)&start,(const GtkTextIter*)&finish); }
gtk_text_buffer_copy_clipboard(Tbuf,clipboard);
}
Anyway, I think the GNOME clipboard viewer is just a "nicer" GUI for xclipboard, it is not really separate, so don't worry -- it is all, in fact, the xclipboard. Which presumably you can access it with Xlib() as well as gtk, and I suppose any other GUI toolkit. But they will all be using the same clipboard, the xclipboard.