Re: Using the GTK clipboard from terminal



On Mon, 2005-08-01 at 18:53 -0300, Leonel Gayard wrote:
> Hey all,
> 
> I have been trying to play with the gtk clipboard from a terminal
> program. So I have this little application, gclip, that reads from
> stdin and writes to the clipboard. It does not work yet, and I intend
> to use it like this:
> 
> $ cat some_file.txt | gclip
> <Then paste the clipboard contents using C-v>

Just as a heads-up, there's a program called xsel that does this.

> The source is below, and does not work yet. What's wrong ? Did I
> forget to call any start-up functions ? Does the clipboard fail if
> there isn't a widget application running ?
> 
> /* headers */
> int main(int argc, char **argv) {
>     char buf[_MY_MAX_ + 1], c;
>     int i;
>     GtkClipboard *clip;
> 
>     for (i = 0; i < _MY_MAX_; i++) {
>         if (EOF == (c = getchar())) {
>             break;
>         }
>         buf[i] = c;
>     }
>     clip = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
>     gtk_clipboard_set_text(clip, "Hello World", -1);
>     gtk_clipboard_store(clip);
> 
>     return 0;
> }

Well, you never say what you mean by "does not work".  But this
code certainly wouldn't set the clipboard.  Instead, it would
set the PRIMARY selection.  PRIMARY is the thing that allows
you to select stuff and then paste it with the middle mouse
button.

The clipboard, the one you have to copy to explicitly, is a
seperate selection in X.  To get it using GDK, you need to
use GDK_SELECTION_CLIPBOARD.

--
Shaun





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