Get selection to buffer addition
Subsystems (2)
Hi all:
What I'm looking for:
I'm looking for comments and approval for a small addition to the console
driver (drivers/char/console.c).
Small description:
The included patches adds a couple of new services to the TIOCLINUX ioctl
call, they are:
13 (get selection into a buffer): It copies the contents of the selection buffer (maintained in kernel space) into a user space provided buffer. Is something like "paste to a buffer" instead of just paste to the current console.
14 (get selection length): Returns the length of the selection buffer (0 if none selected).
-----------
The included file (compressed and uuencoded) contains diffs that apply without offsets into 2.4.7 kernel, they are valid for 2.2.18 too (with offset).
I also include a simple test program that calls the new services. The test program is really simple and assumes you can open /dev/tty1 (you are there or you are root ;-)
Additional question: Why the switch uses numbers? Shouldn't these values be defined as something like TIOCLINUX_GET_SELECTION in a header?
What's the purpose? Just allow pasting in text editors using menues or without the mouse middle button and avoiding to missinterpret the pasted text as keystrokes.
SET
begin 664 patchConsole-2.4.7.txt.gz M'XL("/K,83L"W!A=&-H0V]N<V]L92TR+C0N-RYT>'0E57?C]HX$'Z&OV*D MOA!"0F!9V++M'JM3M^VINH?>MB_5*0K)D%@--N<?['+5_N\W=K*0](+:(@*Q M/?.-9[[/GB(H&3</;3<!8N0B%9/LXDVZ-4X[1(Y#@57(D2P[1W;Q#^,!PF M4YA<+B<+^L(TBB9]W_>;(&?]"T/^)4SG0,X7%\O9O/)?K2"8S$9S\.GW"E:K M/L#0/O"[V!T@X1GL$J41-H:[email protected]/<\DSB[Q+#B5J/7+F$IL$97"4]Q MBUPK9UJB4H0B!7PT:\99V/>==8X:%)98@3*N!22P-IL-2A>U1)[K@B!J>_OY M*RGW228DOGA7HH=)O!*U7,K@F!A+O9A(F\:260(!)T6F'Z%#;EFS(:@[<&> M92B"-)&9@JU0NCS8#;]-*#*\,[S.ZU4>%#18(89&)T6(F;EQ59M.(U<W^I^/ M)I$K7:_7DZB-Y!!=VU&:*"3.EKWQT"6\R>.:$QB.F^:GA>N^_^QW<?0[5R@" M\4\@9!D?+>/*9)#(W&M@SCHPZU*WP79&QT810!NULAUX(Q@8KEC.,;-[@J$W M&%C-T0M%!!\FGF=+\$1/C1B\>?_GY]L/-/O4#WZH_6-(4N^=9'"':X"7,)DO M+Z+E=/H3ZF\BM/5_V=;_].K*$4E_LTG%8X-%RJ#OC^OSHL$(DH[>8N-&Y\* M6;-2<>1T:RL(:I>D6"]6\G_/]^(K58[TQD2JRX'GYHD6\M.'JT\-!QK7@J> M@^6V[W\CVJK29ZBTY;K%3,68G:8\>FP#CE%';;74065%H6+_HM@X6CWZ6'4< MJ;R[_?3AWH&"A;61X34\2Z#X#1L!O.<-NM]U3J\L16MTXY+7;C]=KK[]8:
MWJ<%#VQ)W&1*I,5:5.G:38X:*.Z-E5J';D]99T:+ZU-A"Y%7KB^'A&_E]( MQ\^92EJD\!\PG(">TN'LE-/%?J/E-/BL//0[@7+:KW4X4^U@-^^JRPLCYN# ML8U+>>I?T#^MN/OS'X/4NVI3K:FE*"52EFC:Z0.C.[22'<E/S<LY]F5:N>] MP7A:F@S';J%Q[MW<;AC']F+@X[]Y;S[XC@/T;XY9M$R6C0ZY\)USD7=.?%1 MHW1WM"MF*9*L-/KLT;UN>6P%22F6N!-2,YY7;)U,[+!E,U!:FE3;FL;UZ]. M1@YM;:@Q5[CR\?GE8*77"/E+%\W)]2>51GOOPXL,-XQCU6QC;K;4YTJSY:HW FV*>NYWVQY-N7O\,LN'&3I?*Z/(D<5+WSCE(\D.-_G[[YF5<)```` `
end
-------------------------------------------
Test program:
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i,res,fd,largo;
char buffer[sizeof(unsigned int)+2],*s;
unsigned int *lg=(unsigned int *)(buffer+1);
fd=open("/dev/tty1",O_RDWR);
printf("Finding the length of the selection:\n"); buffer[0]=14; res=ioctl(fd,TIOCLINUX,&buffer); printf("The iotcl returns %d\n",res); printf("Length: %u\n",*lg);
largo=*lg;
if (*lg==0) return 0;
printf("Asking for the selection:\n");
s=(char *)malloc(largo+sizeof(unsigned int)+2);
s[0]=13;
lg=(unsigned int *)(s+1);
*lg=largo;
res=ioctl(fd,TIOCLINUX,s);
printf("The iotcl returns %d\n",res);
largo=*lg;
printf("Length returned: %d\n",largo);
s+=1+sizeof(unsigned int);
s[largo]=0;
for (i=0; s[i]; i++)
if (s[i]==13) s[i]=10;
printf("Selection: '%s' (%d)\n",s,s[0]);
return 0;
}
--
Salvador Eduardo Tropea (SET). (Electronics Engineer) Visit my home page: http://welcome.to/SetSoft or
http://www.geocities.com/SiliconValley/Vista/6552/
Alternative e-mail: [email protected] [email protected]
[email protected]
Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA Phone: +(5411) 4759 0013
RFC 1/1 Get selection to buffer addition
Hi all:
I'm sending this mail again with the patch in plain text and not gzip+uuencoded, sorry for any inconvenience.
What I'm looking for:
I'm looking for comments and approval for a small addition to the console
driver (drivers/char/console.c).
Small description:
The included patches adds a couple of new services to the TIOCLINUX ioctl
call, they are:
13 (get selection into a buffer): It copies the contents of the selection buffer (maintained in kernel space) into a user space provided buffer. Is something like "paste to a buffer" instead of just paste to the current console.
14 (get selection length): Returns the length of the selection buffer (0 if none selected).
-----------
The included file contains diffs that apply
without offsets into 2.4.7 kernel, they are valid for 2.2.18 too (with offset).
I also include a simple test program that calls the new services. The test program is really simple and assumes you can open /dev/tty1 (you are there or you are root ;-)
Additional question: Why the switch uses numbers? Shouldn't these values be defined as something like TIOCLINUX_GET_SELECTION in a header?
What's the purpose? Just allow pasting in text editors using menues or without the mouse middle button and avoiding to missinterpret the pasted text as keystrokes.
SET
Patch (about 77 lines):
-------------------------------------------
drivers/char/console.c Thu Jul 26 17:33:46 2001 renamed from drivers/char/console.c Tue Jun 12 15:17:17 2001 +6 -0
@@ -14,6 +14,8 @@ * * Copy and paste function by Andrew Haylett, * some enhancements by Alessandro Rubini. + * get selection into a buffer and length by + * Salvador E. Tropea <[email protected]> * * Code to check for different video-cards mostly by Galen Hunt, * <[email protected]>
@@ -2204,6 +2206,10 @@ return 0; case 12: /* get fg_console */ return fg_console; + case 13: /* get selection into a buffer */ + return get_selection_buffer(arg); + case 14: /* get selection length */ + return put_user(get_selection_length(), (unsigned int
*)((char *)arg + 1));
}
return -EINVAL;}
drivers/char/selection.c Thu Jul 26 17:53:46 2001 renamed from drivers/char/selection.c Fri Feb 9 16:30:22 2001 +35 -0
@@ -288,6 +288,41 @@ return 0; } +/* Copy the contents of the selection buffer into a + * user space buffer. + * Invoked by ioctl(). + */ +int get_selection_buffer(const unsigned long arg) +{ + char *dest; + unsigned int length; + + if (get_user(length, (unsigned int *)(arg + sizeof(char)))) + return -EFAULT; + + dest = (char *)(arg + sizeof(char) + sizeof(unsigned int)); + + if (length > sel_buffer_lth) + length = sel_buffer_lth; + + if (sel_buffer) { + if (copy_to_user(dest, sel_buffer, length)) + return -EFAULT; + } else { + length = 0; + } + __put_user(length, (unsigned long *)(arg + sizeof(char))); + return 0; +} + +/* Get the selection buffer length. + * Invoked by ioctl(). + */ +unsigned int get_selection_length(void) +{ + return sel_buffer ? sel_buffer_lth : 0; +} + /* Insert the contents of the selection buffer into the * queue of the tty associated with the current console. * Invoked by ioctl().
include/linux/selection.h Thu Jul 26 17:40:07 2001 renamed from include/linux/selection.h Fri Jul 20 16:53:56 2001 +0 -0
@@ -17,6 +17,8 @@ extern int sel_loadlut(const unsigned long arg); extern int mouse_reporting(void); extern void mouse_report(struct tty_struct * tty, int butt, int mrx, int
mry);
+extern int get_selection_buffer(const unsigned long arg); +extern unsigned int get_selection_length(void);
#define video_num_columns (vc_cons[currcons].d->vc_cols)
#define video_num_lines (vc_cons[currcons].d->vc_rows)
-------------------------------------------
End of patch.
Test program:
-------------------------------------------
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i,res,fd,largo;
char buffer[sizeof(unsigned int)+2],*s;
unsigned int *lg=(unsigned int *)(buffer+1);
fd=open("/dev/tty1",O_RDWR);
printf("Finding the length of the selection:\n"); buffer[0]=14; res=ioctl(fd,TIOCLINUX,&buffer); printf("The iotcl returns %d\n",res); printf("Length: %u\n",*lg);
largo=*lg;
if (*lg==0) return 0;
printf("Asking for the selection:\n");
s=(char *)malloc(largo+sizeof(unsigned int)+2);
s[0]=13;
lg=(unsigned int *)(s+1);
*lg=largo;
res=ioctl(fd,TIOCLINUX,s);
printf("The iotcl returns %d\n",res);
largo=*lg;
printf("Length returned: %d\n",largo);
s+=1+sizeof(unsigned int);
s[largo]=0;
for (i=0; s[i]; i++)
if (s[i]==13) s[i]=10;
printf("Selection: '%s' (%d)\n",s,s[0]);
return 0;
}
--
Salvador Eduardo Tropea (SET). (Electronics Engineer) Visit my home page: http://welcome.to/SetSoft or
http://www.geocities.com/SiliconValley/Vista/6552/
Alternative e-mail: [email protected] [email protected]
[email protected]
Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA Phone: +(5411) 4759 0013
I plan to make selection go away in 2.5.X. It should be done in userland. When I get time I will rework gpm.
-----------------------------------------------------------------------------
Crap can work. Given enough thrust pigs will fly, but it's not necessary a
good idea. [ Alexander Viro on linux-kernel ]
Quoted 2 lines · James Simmons
I plan to make selection go away in 2.5.X. It should be done in userland. When I get time I will rework gpm.
Hmmm... ok, it changes all the thing. So I doubt the patch will be accepted. In fact I started looking gpm sources when I wanted to do it ;-)
I would like to know when you start with it and I could contribute some ideas/code.
SET
--
Salvador Eduardo Tropea (SET). (Electronics Engineer) Visit my home page: http://welcome.to/SetSoft or
http://www.geocities.com/SiliconValley/Vista/6552/
Alternative e-mail: [email protected] [email protected]
[email protected]
Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA Phone: +(5411) 4759 0013
Quoted 8 lines
Quoted 3 lines
I plan to make selection go away in 2.5.X. It should be done in userland. When I get time I will rework gpm.
Hmmm... ok, it changes all the thing. So I doubt the patch will be accepted. In fact I started looking gpm sources when I wanted to do it ;-)
I would like to know when you start with it and I could contribute some ideas/code.
Look at http://www.sf.net/projects/linuxconsole
We have patches for gpm in CVS. It needs alot of work.
Hi!
Quoted 11 lines
I'm sending this mail again with the patch in plain text and not gzip+uuencoded, sorry for any inconvenience.
What I'm looking for:
I'm looking for comments and approval for a small addition to the console
driver (drivers/char/console.c).Small description:
The included patches adds a couple of new services to the TIOCLINUX ioctl
call, they are:
Quoted 7 lines
13 (get selection into a buffer): It copies the contents of the selection buffer (maintained in kernel space) into a user space provided buffer. Is something like "paste to a buffer" instead of just paste to the current console.
14 (get selection length): Returns the length of the selection buffer (0 if none selected).
Looks good to me. Now, all I want is utility to share clipboard between X and text console...
Pavel
Signature · 2 lines
Philips Velo 1: 1"x4"x8", 300gram, 60, 12MB, 40bogomips, linux, mutt, details at http://atrey.karlin.mff.cuni.cz/~pavel/velo/index.html.
Quoted 18 lines · Pavel Machek
Hi!
Quoted 16 lines
I'm sending this mail again with the patch in plain text and not gzip+uuencoded, sorry for any inconvenience.
What I'm looking for:
I'm looking for comments and approval for a small addition to the console
driver (drivers/char/console.c).Small description:
The included patches adds a couple of new services to the TIOCLINUX ioctl
call, they are:13 (get selection into a buffer): It copies the contents of the selection buffer (maintained in kernel space) into a user space provided buffer. Is something like "paste to a buffer" instead of just paste to the current console.
Quoted 5 lines
Quoted 2 lines
14 (get selection length): Returns the length of the selection buffer (0 if none selected).
Looks good to me. Now, all I want is utility to share clipboard between X and text console...
Umm, silly question, but why not put this stuff into something similar to gpm, rather than have unswappable kernel memory sucked up just for cut and paste (possibly very large cut and paste under X).
--
Russell King ([email protected]) The developer of ARM Linux
http://www.arm.linux.org.uk/personal/aboutme.html
Quoted 1 line · Russell King
On Sat, Jan 01, 2000 at 01:24:46AM +0000, Pavel Machek wrote:
[snip]
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
What I'm looking for:
I'm looking for comments and approval for a small addition to the console
driver (drivers/char/console.c).
[snip]
Quoted 6 lines
Quoted 2 lines
Looks good to me. Now, all I want is utility to share clipboard between X and text console...
Umm, silly question, but why not put this stuff into something similar to gpm, rather than have unswappable kernel memory sucked up just for cut and paste (possibly very large cut and paste under X).
According to James Simmons (he is maintaining a console development CVS tree in Sourge Force) the selection stuff will go away in 2.5.x series and the code will be moved to user space (gpm) as Russell sugest.
As things will be changing in 2.5.x I don't think we should introduce my change. My idea was towards what Pavel says: adding some kind of clipboard facility, after all it was already there but not accesible. I sent this patch first and already designed the IOCTL calls for the reverse: set the selection buffer. When I started it I thinked this was part of gpm. I was very surprised when I discovered the kernel was doing the real job.
As the 2.5.x code will remove it I don't know if we should add features that will go away. The only problem for me is how many time I'll must wait before 2.6.x is released and the users of my text editor will enjoy this facility (a clipboard between consoles and different applications).
SET
--
Salvador Eduardo Tropea (SET). (Electronics Engineer) Visit my home page: http://welcome.to/SetSoft or
http://www.geocities.com/SiliconValley/Vista/6552/
Alternative e-mail: [email protected] [email protected]
[email protected]
Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA Phone: +(5411) 4759 0013