From 177c1f1d8f5703e5dcdb642adff85765f452e2ad Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Thu, 24 Sep 2009 17:42:24 +0330 Subject: [PATCH] move fb_init() and fb_free() to vncproto.c --- fbvnc.c | 46 ++++++++++++++++++++++++++++++---------------- fbvnc.h | 3 ++- vncproto.c | 7 +++++++ 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/fbvnc.c b/fbvnc.c index a865e22..35cbb0f 100644 --- a/fbvnc.c +++ b/fbvnc.c @@ -7,40 +7,56 @@ #include #include -#define byterate 1920 - #include "fbvnc.h" -#include "draw.h" + +static void term_setup(struct termios *ti) +{ + struct termios termios; + char *hide = "\x1b[?25l"; + char *clear = "\x1b[2J\x1b[H"; + char *msg = "\t\t\t*** fbvnc ***\r\n"; + + write(STDIN_FILENO, hide, strlen(hide)); + write(STDOUT_FILENO, clear, strlen(clear)); + write(STDOUT_FILENO, msg, strlen(msg)); + tcgetattr (0, &termios); + *ti = termios; + cfmakeraw(&termios); + tcsetattr(0, TCSANOW, &termios); +} + +static void term_cleanup(struct termios *ti) +{ + char *show = "\x1b[?25h"; + tcsetattr(0, TCSANOW, ti); + write(STDIN_FILENO, show, strlen(show)); +} int main(int argc, char * argv[]) { int port = DEF_PORT; char * host = "127.0.0.1"; int fd, retval; - struct termios ti1, ti2; fd_set sel_in; struct timeval tv; int already_requested = 0; int must_draw = 0; int must_redraw = 1; + struct termios ti; if (argc>=2) host = argv[1]; if (argc>=3) port = atoi(argv[2]); - fb_init(); fd = vncproto_init(host, port); if(fd==-1) return -1; - tcgetattr (0, &ti1); - ti2 = ti1; - cfmakeraw(&ti2); - - if (request_vnc_refresh(fd) == -1) + term_setup(&ti); + if (request_vnc_refresh(fd) == -1) { + term_cleanup(&ti); return -1; - tcsetattr(0, TCSANOW, &ti2); - + } tv.tv_sec = 0; tv.tv_usec = 500000; @@ -81,9 +97,7 @@ int main(int argc, char * argv[]) break; } } - fb_free(); - tcsetattr(0, TCSANOW, &ti1); -#define W(a,b) write((a),(b),strlen(b)) - W(1, "\n\x1bH\x1bJ"); + vncproto_free(); + term_cleanup(&ti); return 0; } diff --git a/fbvnc.h b/fbvnc.h index 7d560dc..e574f2c 100644 --- a/fbvnc.h +++ b/fbvnc.h @@ -6,7 +6,8 @@ #define DEF_PORT 5900 /* vncproto.c */ -int vncproto_init(char * addr, int port); +int vncproto_init(char *addr, int port); +int vncproto_free(void); int request_vnc_refresh(int fd); int parse_vnc_in(int fd); int parse_kbd_in(int kbdfd, int fd); diff --git a/vncproto.c b/vncproto.c index 0779c9e..075b7c0 100644 --- a/vncproto.c +++ b/vncproto.c @@ -108,6 +108,7 @@ int vncproto_init(char * addr, int port) read(servsock, &serverinit, sizeof(serverinit)); + fb_init(); fb_width = ntohs(serverinit.framebufferWidth); if (fb_width > fb_cols()) fb_width = fb_cols(); @@ -143,6 +144,12 @@ int vncproto_init(char * addr, int port) return servsock; } +int vncproto_free(void) +{ + fb_free(); + return 0; +} + int request_vnc_refresh(int fd) { rfbFramebufferUpdateRequestMsg updreq; -- 2.11.4.GIT