Using the GTK clipboard from terminal



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>

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;
}



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