draw the output to the framebuffer
[fbvnc.git] / vt52vnc.c
bloba9ada8912387885096807f01a5617880118274ea
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <termios.h>
5 #include <sys/time.h>
6 #include <sys/types.h>
7 #include <unistd.h>
8 #include <string.h>
10 #define byterate 1920
12 #include "vt52vnc.h"
13 #include "draw.h"
15 int main(int argc, char * argv[])
17 int port = DEF_PORT;
18 char * host = "127.0.0.1";
19 int fd, retval;
20 struct termios ti1, ti2;
21 fd_set sel_in;
22 struct timeval tv;
23 int already_requested = 0;
24 int must_draw = 0;
25 int must_redraw = 1;
27 if (argc>=2)
28 host = argv[1];
29 if (argc>=3)
30 port = atoi(argv[2]);
31 fb_init();
32 fd = vncproto_init(host, port);
33 if(fd==-1)
34 return -1;
36 tcgetattr (0, &ti1);
37 ti2 = ti1;
38 cfmakeraw(&ti2);
40 if (request_vnc_refresh(fd) == -1)
41 return -1;
42 tcsetattr(0, TCSANOW, &ti2);
44 tv.tv_sec = 0;
45 tv.tv_usec = 500000;
47 while(1) {
48 FD_ZERO(&sel_in);
49 FD_SET(fd, &sel_in);
50 FD_SET(0, &sel_in);
51 retval = select(fd+1, &sel_in, NULL, NULL, &tv);
52 if (retval == 0) {
53 if (!already_requested && !must_redraw && !must_draw) {
54 if (request_vnc_refresh(fd) == -1)
55 break;
56 already_requested = 1;
58 if (must_draw || must_redraw) {
59 must_draw = drawdelta();
60 if (!must_draw) {
61 must_draw=must_redraw;
62 must_redraw=0;
64 tv.tv_sec = 0;
65 tv.tv_usec = 200000;
66 } else {
67 tv.tv_sec = 0;
68 tv.tv_usec = 200000;
71 if (FD_ISSET(fd, &sel_in)) {
72 already_requested = 0;
73 if (parse_vnc_in(fd) == -1)
74 break;
75 must_redraw = 1;
76 tv.tv_sec = 0;
77 tv.tv_usec = 0;
79 if (FD_ISSET(0, &sel_in)) {
80 if (parse_kbd_in(0, fd) == -1)
81 break;
84 fb_free();
85 tcsetattr(0, TCSANOW, &ti1);
86 #define W(a,b) write((a),(b),strlen(b))
87 W(1, "\n\x1bH\x1bJ");
88 return 0;