zink has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I'm seeking help to write a script that read a portion of file/user input and make it as PRIMARY selection in x windows using Tk::Selection. It works when i paste the selection to Xterm, but it fail when i try to paste the selection into other clients like kwrite. It seems that kwrite's request is being ignored. So any ideas to work around? The code:
$widget->SelectionClear; $widget->SelectionOwn(-selection=>'PRIMARY'); $widget->SelectionHandle( -selection=> 'PRIMARY',-type=>'STRING',-form +at=>'STRING',sub {$data} );
Thanks

Replies are listed 'Best First'.
Re: Using X selection: copy and paste
by rovf (Priest) on Sep 18, 2008 at 09:10 UTC

    I darkly remember that K Desktop Apps maintain their own clipboard in parallel to the X Clipboard. There is an option to keep them in sync - it is somewhere in the K Desktop Settings - but I would not be surprised if there are cases where this fails. As I don't use KWrite, I don't know. Maybe this is best asked in a KDE forum.

    -- 
    Ronald Fischer <ynnor@mm.st>
Re: Using X selection: copy and paste
by zentara (Cardinal) on Sep 18, 2008 at 12:18 UTC
      I tried to used the text widget before, but it produces same result. Things only working when i turn on xclipboard and use Tk::Clipboard (malfunction without xclipboard), but i dun want to depend on the xclipboard. I used the Super Search and find similar case and none seems to have solution so far. Example: http://www.perlmonks.org/?node_id=121939
        You could try xclip and run it thru system. You may have to ask this on a KDE news/mail list.

        I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: Using X selection: copy and paste
by zentara (Cardinal) on Sep 18, 2008 at 14:41 UTC
    I just tried this script, and it worked to paste into kwrite. I use ICEWM, so I was running kwrite without KDE....if that makes a difference like rovf mentioned.
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Clipboard; my $mw = tkinit; $mw->withdraw; #use Tk without showing a window my $content = 'foobar'.time; print "$content\n"; $mw->clipboardClear; $mw->clipboardAppend($content); MainLoop;

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      No, it didn't work as well. I'm using FVWM (stable version)
        I used to use FVWM but switched to ICEWM after FVWM showed some non-compliance to X standards. Did xclip work?

        I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: Using X selection: copy and paste
by repellent (Priest) on Sep 20, 2008 at 01:46 UTC
    I had good luck with xsel by Conrad Parker. You can open pipes to read from and write to the different selection buffers (default is PRIMARY).