1 #include <rfb/keysym.h>
8 static int tty_inject_device;
10 void do_key(rfbBool down,rfbKeySym keySym,rfbClientPtr cl)
12 static char isControl=0;
15 /* if(keySym==XK_Escape)
17 else */ if(keySym==XK_Control_L || keySym==XK_Control_R)
19 else if(tty_inject_device>=0) {
23 if(keySym>='a' && keySym<='z')
25 else if(keySym>='A' && keySym<='Z')
33 else if(keySym==XK_Return)
35 else if(keySym==XK_BackSpace)
37 else if(keySym==XK_Home || keySym==XK_KP_Home)
39 else if(keySym==XK_End || keySym==XK_KP_End)
41 else if(keySym==XK_Up || keySym==XK_KP_Up)
43 else if(keySym==XK_Down || keySym==XK_KP_Down)
45 else if(keySym==XK_Right || keySym==XK_KP_Right)
47 else if(keySym==XK_Left || keySym==XK_KP_Left)
52 ret=ioctl(tty_inject_device,TIOCSTI,&keySym);
54 static char device[64];
55 close(tty_inject_device);
56 sprintf(device,"/dev/tty%d",tty);
57 tty_inject_device=open(device,O_WRONLY);
58 ret=ioctl(tty_inject_device,TIOCSTI,&keySym);
60 rfbErr("Couldn't reopen device %s!\n",device);
64 } else if(keySym==XK_Control_L || keySym==XK_Control_R)
68 /* these colours are from linux kernel drivers/char/console.c */
69 unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7,
70 8,12,10,14, 9,13,11,15 };
71 /* the default colour table, for VGA+ colour systems */
72 int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,
73 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff};
74 int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa,
75 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff};
76 int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,
77 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff};
79 int main(int argc,char **argv)
81 int width=80,height=25;
83 vncConsolePtr console;
84 char tty_device[64],title[128];
87 struct winsize dimensions;
90 if((tty=atoi(argv[1]))<1) {
91 rfbErr("Usage: %s [tty_number [vnc args]]\n",argv[0]);
99 /* getopt goes here! */
101 sprintf(tty_device,"/dev/tty%d",tty);
102 if((tty_inject_device=open(tty_device,O_WRONLY))<0) {
103 rfbErr("Couldn't open tty device %s!\n",tty_device);
106 rfbLog("Using device %s.\n",tty_device);
108 if(ioctl(tty_inject_device,TIOCGWINSZ,&dimensions)>=0) {
109 width=dimensions.ws_col;
110 height=dimensions.ws_row;
113 sprintf(title,"LinuxVNC: /dev/tty%d",tty);
116 console=vcGetConsole(&argc,argv,width,height,&vgaFont,TRUE);
118 console->screen->colourMap.data.bytes[i*3+0]=default_red[color_table[i]];
119 console->screen->colourMap.data.bytes[i*3+1]=default_grn[color_table[i]];
120 console->screen->colourMap.data.bytes[i*3+2]=default_blu[color_table[i]];
122 console->screen->desktopName=title;
123 console->screen->kbdAddEvent=do_key;
124 console->selectTimeOut=100000;
125 console->wrapBottomToTop=TRUE;
127 buffer=malloc(width*height);
128 console->cursorActive=FALSE;
130 buffer=malloc(width*height*2+4);
131 console->cursorActive=TRUE;
133 /* memcpy(buffer,console->screenBuffer,width*height); */
136 sprintf(tty_device,"/dev/vcs%d",tty);
138 sprintf(tty_device,"/dev/vcsa%d",tty);
141 while(rfbIsActive(console->screen)) {
142 if(!console->currentlyMarking) {
143 tty_file=fopen(tty_device,"rb");
145 rfbErr("cannot open device \"%s\"\n",
150 fread(buffer,width,height,tty_file);
152 fread(buffer,width*height*2+4,1,tty_file);
153 vcHideCursor(console);
157 for(i=0;i<console->width*console->height;i++) {
160 (buffer[i]!=console->screenBuffer[i])
162 (buffer[4+2*i]!=console->screenBuffer[i] ||
163 buffer[5+2*i]!=console->attributeBuffer[i])
166 console->x=(i%console->width);
167 console->y=(i/console->width);
169 rfbLog("changes: %d,%d (%d!=%d || %d!=%d)\n",
170 console->x,console->y,
171 buffer[4+2*i],console->screenBuffer[i],
172 buffer[5+2*i],console->attributeBuffer[i]);
176 vcPutChar(console,buffer[i]);
178 vcPutCharColour(console,buffer[4+i*2],buffer[5+i*2]&0x7,buffer[5+i*2]>>4);
182 console->x=buffer[2];
183 console->y=buffer[3];
185 vcProcessEvents(console);