Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xselection

17 views
Skip to first unread message

Ulli Horlacher

unread,
Feb 27, 2012, 9:56:13 AM2/27/12
to
Is there a native way to read the contens of the X selection (mouse)
buffer?

I can access it via:

if (`xprop -root CUT_BUFFER0` =~ /"(.*)"/) {
print "X selection: $1\n";
}

but this needs an extra sub process.

--
Ullrich Horlacher Informationssysteme und Serverbetrieb
Rechenzentrum E-Mail: horl...@rus.uni-stuttgart.de
Universitaet Stuttgart Tel: ++49-711-685-65868
Allmandring 30 Fax: ++49-711-682357
70550 Stuttgart (Germany) WWW: http://www.rus.uni-stuttgart.de/

$Bill

unread,
Feb 28, 2012, 9:29:20 PM2/28/12
to
On 02/27/2012 06:56, Ulli Horlacher wrote:
> Is there a native way to read the contens of the X selection (mouse)
> buffer?
>
> I can access it via:
>
> if (`xprop -root CUT_BUFFER0` =~ /"(.*)"/) {
> print "X selection: $1\n";
> }
>
> but this needs an extra sub process.

I assume you're on a *NIX system. On Win32, you can for example
get the selected text line in a Listbox widget thusly:

$sel = $lb2->getSelected (Text widget in a Listbox)
to get the currently selected text in a text widget
(not sure what it does with multiple lines for separator)
or
my @sel = $lb2->curselection (Listbox widget)
returns a list of line numbers selected in the list box

I hope that correlates to your situation. The docs aren't good in
this area.



Ulli Horlacher

unread,
Feb 29, 2012, 2:43:04 AM2/29/12
to
$Bill <ne...@todbe.com> wrote:
> On 02/27/2012 06:56, Ulli Horlacher wrote:
> > Is there a native way to read the contens of the X selection (mouse)
> > buffer?
> >
> > I can access it via:
> >
> > if (`xprop -root CUT_BUFFER0` =~ /"(.*)"/) {
> > print "X selection: $1\n";
> > }
> >
> > but this needs an extra sub process.
>
> I assume you're on a *NIX system. On Win32, you can for example
> get the selected text line in a Listbox widget thusly:

No, I do not mean text within a Tk window, but the generic X11 clipboard,
used by all programs. X is not UNIX specific, it exists on a broad range
of systems.

$Bill

unread,
Feb 29, 2012, 7:22:08 AM2/29/12
to
On 02/28/2012 23:43, Ulli Horlacher wrote:
> $Bill<ne...@todbe.com> wrote:
>> On 02/27/2012 06:56, Ulli Horlacher wrote:
>>> Is there a native way to read the contens of the X selection (mouse)
>>> buffer?
>>>
>>> I can access it via:
>>>
>>> if (`xprop -root CUT_BUFFER0` =~ /"(.*)"/) {
>>> print "X selection: $1\n";
>>> }
>>>
>>> but this needs an extra sub process.
>>
>> I assume you're on a *NIX system. On Win32, you can for example
>> get the selected text line in a Listbox widget thusly:
>
> No, I do not mean text within a Tk window, but the generic X11 clipboard,
> used by all programs. X is not UNIX specific, it exists on a broad range
> of systems.

But mostly NIX. I used XWindows back in my Sparc days.

Still out of my immediate area of expertise, but what does Tk::clipboard
'clipboardGet' method do for you under X ? Anything helpful ?



Marc Dashevsky

unread,
Feb 29, 2012, 9:52:45 AM2/29/12
to
In article <jikku8$oq1$1...@news.belwue.de>, fram...@rus.uni-stuttgart.de says...
> $Bill <ne...@todbe.com> wrote:
> > On 02/27/2012 06:56, Ulli Horlacher wrote:
> > > Is there a native way to read the contens of the X selection (mouse)
> > > buffer?
> > >
> > > I can access it via:
> > >
> > > if (`xprop -root CUT_BUFFER0` =~ /"(.*)"/) {
> > > print "X selection: $1\n";
> > > }
> > >
> > > but this needs an extra sub process.
> >
> > I assume you're on a *NIX system. On Win32, you can for example
> > get the selected text line in a Listbox widget thusly:
>
> No, I do not mean text within a Tk window, but the generic X11 clipboard,
> used by all programs. X is not UNIX specific, it exists on a broad range
> of systems.

Configuring a widget with -exportselection => 1 makes the Tk selection
available to the X clipboard I believe. I would think that it is
bidirectional. However, in modern version of perl/Tk exportselection
is enabled by default, so there is likely no help from me here.

--
Go to http://MarcDashevsky.com to send me e-mail.

Ulli Horlacher

unread,
Mar 1, 2012, 8:10:37 AM3/1/12
to
$Bill <ne...@todbe.com> wrote:

> > No, I do not mean text within a Tk window, but the generic X11 clipboard,
> > used by all programs. X is not UNIX specific, it exists on a broad range
> > of systems.
>
> But mostly NIX.

And VMS
And BS2000
And MVS
And RTOS
And QNX
And Windows
And ...

X was first introduced on VMS and later ported to UNIX.
I started with both, X11 and perl, on VMS.


> Still out of my immediate area of expertise, but what does Tk::clipboard
> 'clipboardGet' method do for you under X ? Anything helpful ?

When I use:

use Tk;
$X = tkinit;
$x = $X->clipboardGet(-type=>'STRING');
print "$x\n";

I get:

Failed to AUTOLOAD 'MainWindow::clipboardGet'

But this one works:

use Tk;
$X = tkinit;
$x = $X->SelectionGet(-selection=>'CLIPBOARD',-type=>'STRING');
print "$x\n";

... for certain programs. Firefox: yes, xterm: no :-(
Wired...

V. Ul. Peculus

unread,
Mar 2, 2012, 10:19:38 AM3/2/12
to
On 01.03.12 14:10, Ulli Horlacher wrote:
> But this one works:
>
> use Tk;
> $X = tkinit;
> $x = $X->SelectionGet(-selection=>'CLIPBOARD',-type=>'STRING');
> print "$x\n";
>
> ... for certain programs. Firefox: yes, xterm: no:-(


For me it works even with xterm (Solaris)

$Bill

unread,
Mar 2, 2012, 9:22:47 PM3/2/12
to
It works on Win32 also, but we have
my $x = Win32::Clipboard();
as an alternative, which can be used even without Tk.

$Bill

unread,
Mar 2, 2012, 9:26:37 PM3/2/12
to
Left off a line - ya needs ta call get:

my $clip = Win32::Clipboard();
my $x = $clip->Get();
or
my $x = $clip->GetText();

0 new messages