[Linux-decnet-commit] CVS: dnprogs/phone phone_ncurses.c,1.5,1.6
Brought to you by:
chrissie_c,
ph3-der-loewe
From: Patrick C. <pa...@us...> - 2006-01-26 14:55:11
|
Update of /cvsroot/linux-decnet/dnprogs/phone In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6503 Modified Files: phone_ncurses.c Log Message: Redraw the screen if the window is resized. Index: phone_ncurses.c =================================================================== RCS file: /cvsroot/linux-decnet/dnprogs/phone/phone_ncurses.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** phone_ncurses.c 23 Feb 2001 15:01:47 -0000 1.5 --- phone_ncurses.c 26 Jan 2006 14:55:01 -0000 1.6 *************** *** 7,10 **** --- 7,12 ---- #include <sys/types.h> #include <sys/time.h> + #include <sys/signal.h> + #include <sys/ioctl.h> #include <ctype.h> #include <string.h> *************** *** 41,45 **** static void display_line(char *text); static void rearrange_windows(int num); ! static int Finished = FALSE; static int Switch_Hook_Char = '%'; --- 43,49 ---- static void display_line(char *text); static void rearrange_windows(int num); ! ! static void draw_title(WINDOW *window); ! static int Finished = FALSE; static int Switch_Hook_Char = '%'; *************** *** 51,54 **** --- 55,59 ---- static WINDOW *display_window = NULL; static PANEL *display_panel = NULL; + static int sigwinch_happened = 0; /* Cursor position in command mode */ *************** *** 75,79 **** { int key; ! key = getch(); if (key == ERR) return 0; --- 80,84 ---- { int key; ! key = getch(); if (key == ERR) return 0; *************** *** 81,85 **** // If we are dialling then any key will cancel. cancel_dial(); ! // Display window is open - close it. if (display_window) --- 86,90 ---- // If we are dialling then any key will cancel. cancel_dial(); ! // Display window is open - close it. if (display_window) *************** *** 92,96 **** display_window = NULL; } ! // Deal with global key assignments first if (key == 4) // Ctrl-D --- 97,101 ---- display_window = NULL; } ! // Deal with global key assignments first if (key == 4) // Ctrl-D *************** *** 99,103 **** return 0 ; } ! if (key == 23) // Ctrl-W refreshes the screen { --- 104,108 ---- return 0 ; } ! if (key == 23) // Ctrl-W refreshes the screen { *************** *** 105,109 **** return 0; } ! if (key == 26) // Ctrl-Z is hangup { --- 110,114 ---- return 0; } ! if (key == 26) // Ctrl-Z is hangup { *************** *** 111,115 **** return 0; } ! // Switch-hook char - change mode to command if (state == STATE_TALK && key == Switch_Hook_Char) --- 116,120 ---- return 0; } ! // Switch-hook char - change mode to command if (state == STATE_TALK && key == Switch_Hook_Char) *************** *** 118,122 **** cmd_x=1; cmd_y=1; ! // Clear the last command wmove(Main_Window, cmd_y, cmd_x); --- 123,127 ---- cmd_x=1; cmd_y=1; ! // Clear the last command wmove(Main_Window, cmd_y, cmd_x); *************** *** 137,141 **** if (isprint(key)) wechochar(userinfo[0].window, key); ! // CR may need to scroll the window. if (key == '\r') --- 142,146 ---- if (isprint(key)) wechochar(userinfo[0].window, key); ! // CR may need to scroll the window. if (key == '\r') *************** *** 159,163 **** wmove(userinfo[0].window, 1, 0); } ! if (key == KEY_BACKSPACE && x > 0) { --- 164,168 ---- wmove(userinfo[0].window, 1, 0); } ! if (key == KEY_BACKSPACE && x > 0) { *************** *** 168,172 **** } wrefresh(userinfo[0].window); ! // Send char to remote system(s) for (i=1; i<num_users; i++) --- 173,177 ---- } wrefresh(userinfo[0].window); ! // Send char to remote system(s) for (i=1; i<num_users; i++) *************** *** 176,180 **** return 0; } ! if (state == STATE_COMMAND) { --- 181,185 ---- return 0; } ! if (state == STATE_COMMAND) { *************** *** 194,198 **** } ! if (key == '\r') // Action command { --- 199,203 ---- } ! if (key == '\r') // Action command { *************** *** 202,210 **** cmd_x=1; cmd_y=1; ! // Clear the last command wmove(Main_Window, cmd_y, cmd_x); wclrtoeol(Main_Window); ! if (num_connected_users > 1 && !userinfo[0].held) { --- 207,215 ---- cmd_x=1; cmd_y=1; ! // Clear the last command wmove(Main_Window, cmd_y, cmd_x); wclrtoeol(Main_Window); ! if (num_connected_users > 1 && !userinfo[0].held) { *************** *** 244,247 **** --- 249,267 ---- } + static void resize_screen(int rows, int cols) + { + resize_term(rows, cols); + Screen_Width = cols; + Screen_Height = rows; + wresize(stdscr, rows, cols); + + werase(Main_Window); + draw_title(Main_Window); + wrefresh(stdscr); + + /* Resize all sub-windows with conversations in */ + rearrange_windows(num_users); + wrefresh(curscr); + } // Main loop for ncurses display *************** *** 268,280 **** fd_set fds; int i; ! FD_ZERO(&fds); if (local_sock != -1) FD_SET(local_sock, &fds); for (i=0; i<num_users; i++) FD_SET(userinfo[i].fd, &fds); ! status = select(FD_SETSIZE, &fds, NULL, NULL, init_cmd?&tv:NULL); if (status < 0) { if (errno != EINTR && errno != ERESTART) { --- 288,310 ---- fd_set fds; int i; ! FD_ZERO(&fds); if (local_sock != -1) FD_SET(local_sock, &fds); for (i=0; i<num_users; i++) FD_SET(userinfo[i].fd, &fds); ! status = select(FD_SETSIZE, &fds, NULL, NULL, init_cmd?&tv:NULL); if (status < 0) { + if (sigwinch_happened) + { + struct winsize size; + + if (ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) { + resize_screen(size.ws_row, size.ws_col); + } + sigwinch_happened = 0; + } + if (errno != EINTR && errno != ERESTART) { *************** *** 288,292 **** if (local_sock != -1 && FD_ISSET(local_sock, &fds)) localsock_callback(local_sock); ! for (i=0; i<num_users; i++) { --- 318,322 ---- if (local_sock != -1 && FD_ISSET(local_sock, &fds)) localsock_callback(local_sock); ! for (i=0; i<num_users; i++) { *************** *** 315,321 **** close(userinfo[i].out_fd); } ! ! /* ! * Clear up after ncurses */ clear(); --- 345,351 ---- close(userinfo[i].out_fd); } ! ! /* ! * Clear up after ncurses */ clear(); *************** *** 324,332 **** if (end_message) ! printf("%s\n", end_message); ! return 0; } /* * Initialise ncurses and return the top-level window ID --- 354,398 ---- if (end_message) ! printf("%s\n", end_message); ! return 0; } + static void window_size_change(int sig) + { + sigwinch_happened = 1; + } + + static void draw_title(WINDOW *window) + { + char date[32]; + time_t the_time; + struct tm the_tm; + + /* Format the day */ + the_time = time(NULL); + the_tm = *localtime(&the_time); + strftime(date, sizeof(date), "%d-%b-%Y", &the_tm); + + /* Draw the main title */ + wattrset(window, A_BOLD | COLOR_PAIR(COLOR_YELLOW)); + mvwprintw(window, 0,Screen_Width/2-10,"%s", "Linux Phone Facility"); + + wattrset(window, A_BOLD | COLOR_PAIR(COLOR_WHITE)); + mvwprintw(window, 0,Screen_Width-11,"%s", date); + + /* Draw the prompt */ + wattrset(window, A_DIM | COLOR_PAIR(COLOR_WHITE)); + mvwprintw(window, 1,0,"%c", Switch_Hook_Char); + + wattrset(window, A_DIM | COLOR_PAIR(COLOR_WHITE)); + mvwprintw(window, 3,0,""); + + wmove(window, 3, 0); + wattrset(window, A_BOLD | COLOR_PAIR(COLOR_WHITE)); + whline(window, ACS_HLINE, Screen_Width); + wmove(window, 1, 1); + } + /* * Initialise ncurses and return the top-level window ID *************** *** 335,342 **** { WINDOW* window = NULL; ! char date[32]; ! time_t the_time; ! struct tm the_tm; ! window = initscr(); if (window == NULL) --- 401,405 ---- { WINDOW* window = NULL; ! window = initscr(); if (window == NULL) *************** *** 346,356 **** } - // Format the day - the_time = time(NULL); - the_tm = *localtime(&the_time); - strftime(date, sizeof(date), "%d-%b-%Y", &the_tm); - /* Setup terminal attributes */ ! start_color(); /* Enable colour processing */ noecho(); /* Don't echo input chars */ --- 409,414 ---- } /* Setup terminal attributes */ ! start_color(); /* Enable colour processing */ noecho(); /* Don't echo input chars */ *************** *** 362,365 **** --- 420,425 ---- getmaxyx(stdscr, Screen_Height, Screen_Width); /* Get the screen size */ + signal(SIGWINCH, window_size_change); + /* Set up colour pairs that match the foreground colours */ init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); *************** *** 372,397 **** init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); ! /* Draw the main title */ ! wattrset(window, A_BOLD | COLOR_PAIR(COLOR_YELLOW)); ! mvwprintw(window, 0,Screen_Width/2-10,"%s", "Linux Phone Facility"); - wattrset(window, A_BOLD | COLOR_PAIR(COLOR_WHITE)); - mvwprintw(window, 0,Screen_Width-11,"%s", date); - - /* Draw the prompt */ - wattrset(window, A_DIM | COLOR_PAIR(COLOR_WHITE)); - mvwprintw(window, 1,0,"%c", Switch_Hook_Char); - - wattrset(window, A_DIM | COLOR_PAIR(COLOR_WHITE)); - mvwprintw(window, 3,0,""); - - wmove(window, 3, 0); - wattrset(window, A_BOLD | COLOR_PAIR(COLOR_WHITE)); - whline(window, ACS_HLINE, Screen_Width); - wmove(window, 1, 1); - /* Update the whole screen now we have created all the windows. From now on all updates will be optimised */ - wrefresh(stdscr); Main_Window = window; --- 432,439 ---- init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); ! draw_title(window); /* Update the whole screen now we have created all the windows. From now on all updates will be optimised */ wrefresh(stdscr); Main_Window = window; *************** *** 426,434 **** win_height = (Screen_Height-4) / (num); ! // Impose a maximum height of half the display area. if (win_height > (Screen_Height-4)/2) win_height = (Screen_Height-4)/2; ! for (i=0; i<num; i++) { --- 468,476 ---- win_height = (Screen_Height-4) / (num); ! // Impose a maximum height of half the display area. if (win_height > (Screen_Height-4)/2) win_height = (Screen_Height-4)/2; ! for (i=0; i<num; i++) { *************** *** 443,447 **** wmove(userinfo[i].window, userinfo[i].window_bottom+1, 0); wclrtoeol(userinfo[i].window); ! wresize(userinfo[i].window, win_height, Screen_Width); wsetscrreg(userinfo[i].window, 1, win_height-2); --- 485,489 ---- wmove(userinfo[i].window, userinfo[i].window_bottom+1, 0); wclrtoeol(userinfo[i].window); ! wresize(userinfo[i].window, win_height, Screen_Width); wsetscrreg(userinfo[i].window, 1, win_height-2); *************** *** 468,474 **** userinfo[num_users].fd_callback = fdc; strcpy(userinfo[num_users].name, name); ! // Only create the window if the user has been answered. ! if (out_fd != -1) { new_talk_window(num_users, name); --- 510,516 ---- userinfo[num_users].fd_callback = fdc; strcpy(userinfo[num_users].name, name); ! // Only create the window if the user has been answered. ! if (out_fd != -1) { new_talk_window(num_users, name); *************** *** 502,506 **** { int i,j; ! for (i=0; i<num_users; i++) { --- 544,548 ---- { int i,j; ! for (i=0; i<num_users; i++) { *************** *** 508,519 **** { int x,y; ! wattrset(userinfo[i].window, A_NORMAL | COLOR_PAIR(COLOR_WHITE)); ! for (j=0; j<strlen(msg); j++) { if (isprint(msg[j])) wechochar(userinfo[i].window, msg[j]); ! if (msg[j] == '\r') { --- 550,561 ---- { int x,y; ! wattrset(userinfo[i].window, A_NORMAL | COLOR_PAIR(COLOR_WHITE)); ! for (j=0; j<strlen(msg); j++) { if (isprint(msg[j])) wechochar(userinfo[i].window, msg[j]); ! if (msg[j] == '\r') { *************** *** 536,540 **** wmove(userinfo[i].window, 1, 0); } ! if (msg[j] == 127) // Backspace { --- 578,582 ---- wmove(userinfo[i].window, 1, 0); } ! if (msg[j] == 127) // Backspace { *************** *** 583,587 **** update_panels(); } ! // Remove it from the list if (i != num_users) --- 625,629 ---- update_panels(); } ! // Remove it from the list if (i != num_users) *************** *** 628,637 **** wattrset(userinfo[win].window, A_NORMAL | COLOR_PAIR(COLOR_WHITE)); if (userinfo[win].held == 2) ! mvwprintw(userinfo[win].window, 0, 0, "%s", "(YOU HAVE HELD)"); else mvwprintw(userinfo[win].window, 0, Screen_Width-14, "%s", "(HAS YOU HELD)"); } ! wattrset(userinfo[win].window, A_BOLD | COLOR_PAIR(COLOR_WHITE)); wmove(userinfo[win].window, userinfo[win].window_bottom+1, 0); --- 670,679 ---- wattrset(userinfo[win].window, A_NORMAL | COLOR_PAIR(COLOR_WHITE)); if (userinfo[win].held == 2) ! mvwprintw(userinfo[win].window, 0, 0, "%s", "(YOU HAVE HELD)"); else mvwprintw(userinfo[win].window, 0, Screen_Width-14, "%s", "(HAS YOU HELD)"); } ! wattrset(userinfo[win].window, A_BOLD | COLOR_PAIR(COLOR_WHITE)); wmove(userinfo[win].window, userinfo[win].window_bottom+1, 0); *************** *** 649,653 **** else state = STATE_TALK; // back to command mode ! for (i=0; i<num_users; i++) { --- 691,695 ---- else state = STATE_TALK; // back to command mode ! for (i=0; i<num_users; i++) { *************** *** 655,659 **** { getyx(userinfo[i].window, y, x); ! userinfo[i].held = held; draw_window_decorations(i); --- 697,701 ---- { getyx(userinfo[i].window, y, x); ! userinfo[i].held = held; draw_window_decorations(i); |