Click to See Complete Forum and Search --> : Paste stuff from X to black screen or vice versa; named pipes.


lugoteehalt
05-30-2008, 02:35 PM
It may be I am unusual in continually moving to and from the GUI and CLI but a big problem is moving stuff between the two - you can't copy and paste with the mouse in the normal way. Here is a solution:

Make a named pipe:

$ mkfifo pipe0 ('think this does it.)

Then, at an X virtual terminal emulator or at the black screen, do:

$ cat > pipe0 <return>

Then put - paste - whatever stuff you want in.

Then ctrl+alt+F1, say, to a black screen, and do:

$ cat < pipe0 <return>

Stuff appears on black screen. The pipe is still open you can do more stuff if needed.

Close the process with ctrl+D, end of file - I think.

Apologies for the simpleness, but has caused me much trouble in the past.

ph34r
05-30-2008, 03:26 PM
Or highlite it in X and middle click in a terminal...

mrrangerman43
05-30-2008, 04:39 PM
Yea anything you highlight in X text is stored in memory, if you have your mouse setup to emulate a three button mouse set your courser in the GUI app. and press both R + L buttons at the same time and it will paste to the GUI app.


Edit: I just highlighted this part of my /etc/X11/xorg.cong and pasted it here so you could see the emulation option.

Section "InputDevice"
Identifier "Configured Mouse"
Driver "mouse"
Option "CorePointer"
Option "Device" "/dev/input/mice"
Option "Protocol" "ImPS/2"
Option "Emulate3Buttons" "true"
EndSection

bs_texas
05-31-2008, 04:43 AM
mrrangerman, you should get a 3 button wheel mouse so you don't have to 'emulate' a 3 button mouse with your 2 button mouse. :cool:

Then just use:

Option "ZaxisMapping" "4 5".

The wheel is the third button that will paste anything that's highlighted.

Maybe I'm missing something here. :confused:

lugoteehalt
05-31-2008, 05:29 AM
Hang on, am I being missunderstood?

Surely if you highlight something before you have started X, to take one example. Then it is true you can paste it with the middle button, or the wheel if it's a wheel mouse.

But if you then startx and start an Xterm or Eterm or whatever and middle click then nothing will happen, surely. (Unless things have changed or it's only true in Debian.)

It's that I'm talking about - coppying stuff into and out of X. I have the habit of jumping back and forward from X to a plain, black screen, tty.

If this is wrong I apologies for wasting everybody's time.:confused:

bs_texas
05-31-2008, 06:38 AM
Heheheh... You're no more confused than I am. :D

I probably am misunderstanding the issue. And, unfortunately, I'm no where near my Linux machines to test it out. But, I do know that you don't need to emulate a 3 button mouse if'n you already got one.

But, fortunately, I am here:

http://bennie-smith.net/cpm/displayimage.php?album=30&pos=2

:cool:

mrrangerman43
05-31-2008, 06:55 AM
bs_texas
mrrangerman, you should get a 3 button wheel mouse so you don't have to 'emulate' a 3 button mouse with your 2 button mouse.

Then just use:

Option "ZaxisMapping" "4 5".

The wheel is the third button that will paste anything that's highlighted.

Maybe I'm missing something here.


I have one pc with the scroll mouse, its just all the others I use the two button mouse on :o :o I should even look into getting a wireless K+M, but I can see it now,

(me) HUN, do you know what happen to my mouse????

(wife) Yea I think the grandson was playing with it, using it as a space ship or something.

(me) But I need it!

(wife) Can't you just use something else until I find it?

(me) I would but I can't find my old two button mouse.

(wife) OH that old thing I put that in the garbage after you got the wireless thingy stuff.

(me) AHHHHHH

So you see, its to keep my sanity I still use the two button mouse :D

bs_texas
05-31-2008, 07:05 AM
[insert I-laughed-out-loud icon here]

;)

bwkaz
05-31-2008, 09:21 AM
FWIW:

Normally the middle-click-paste operation is handled by gpm when you're in a real console (ctrl-alt-f1, ctrl-alt-f2, etc.). gpm also handles the select-based copy operations in a console. When you select something in a real console, gpm does the highlighting, and it also stores away the text; you can then paste that text in the current console with a middle-click, or on any other console (again with a middle-click). gpm sees the middle-click, and emulates a bunch of keypresses to get the text to show up.

When you're in X, the X server (informed by the various programs that are connected to it) handles both selection-based copying and middle-click-based pasting. (It also handles ctrl-c/ctrl-v, if your programs are set up to do that. There are multiple clipboards available; one is taken by the selection, and another is taken by ctrl-c "copy" operations.) When you select text in an X program, the program informs the X server "I now have PRIMARY" (the name of the clipboard). When you middle-click in a program, that program asks the X server what text is stored in PRIMARY (and the X server asks the last client that said "I have PRIMARY" -- that's why you can't paste from a program that has exited), and does whatever is needed to perform a paste operation with that text.

But since that operation is mediated by the X server, you can't paste across X displays (since a single server can only run a single display, although that display can have multiple screens). You also can't ask gpm to paste in the text that you just selected in X -- gpm is not an X program, so it can't ask the X server what's in the clipboard. (It also wouldn't know which X server to ask -- a single machine can run almost any number of servers. Plus the X protocol is network-transparent, so you might want it to paste from an X server that runs on another machine entirely.)

Also, gpm does not inform the X server that it has PRIMARY (since again, it doesn't know which X server to talk to), so selections made in gpm are not available to programs running under X.

There may be a way to make what you're trying to do work -- you'd have to make gpm able to load the X libraries on-demand if asked to, and you'd have to figure out a way to tell gpm which X server to connect to. You'd also have issues with gpm running as root (so it can read from and write to all the consoles), and X's connection security not handling that very well at times. But some of that might be able to be figured out. Anyway, then you could have a separate "paste from X" operation in gpm, which would ask the X server what was in PRIMARY and paste that text.

Or, you could just use a named pipe/FIFO/whatever you want to call it. ;)

(One other thing to note, though: Pipes have a limited buffer available. If you try to paste more text into the FIFO from the X size than the size of that buffer, you'll overrun it, and the cat process will get some kind of signal; probably a SIGPIPE (which is a "the other end has disconnected" type of notification). You have to make sure you're draining the buffer fast enough to compensate for text being added to it. If you start up the cat process in the terminal emulator (xterm/Eterm/whatever), then start up the cat process on the real console (ctrl-alt-f1), and only then paste into the one inside the X server, then that should work fine for any arbitrarily-large amount of text. :))

bs_texas
05-31-2008, 10:06 AM
Dang. Deleted. No more late night posts!

lugoteehalt
06-02-2008, 08:20 AM
Thanks, that's definitively sorted.

Didn't know 'you can't paste from a program that has exited' that probably explains several of my nervous breakdowns.

bwkaz
06-02-2008, 08:52 PM
Didn't know 'you can't paste from a program that has exited' Well, I should amend that.

You can't paste from a program that has exited. But lots of desktop environments run a program that monitors the clipboard, and every time it changes, asks the program what text is selected. Then the monitor program takes over the clipboard, and provides that text (until it gets another change notification). Generally the term for this type of program is "clipboard manager" (and I haven't decided whether that name makes sense or not), and they are not required. But they do make the clipboards act a lot more like Windows (as long as the clipboard manager program doesn't exit, or crash).

So there is a way around it, which just involves running another program. :)