From a58f82b943dea3bd8ecc7ff60de765cb3d1780c1 Mon Sep 17 00:00:00 2001 From: Nathan Bryant Date: Thu, 14 Mar 2002 04:24:20 +0000 Subject: [PATCH] support window resizing in curses mode --- citadel/ChangeLog | 4 ++- citadel/citadel.c | 10 ++++---- citadel/citadel_decls.h | 1 + citadel/client_chat.c | 2 +- citadel/commands.c | 10 +++++++- citadel/screen.c | 55 +++++++++++++++++++++++++++-------------- citadel/screen.h | 15 ++++++++++- 7 files changed, 69 insertions(+), 28 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index d0743d797..6dcf25e69 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,7 @@ $Log$ + Revision 590.153 2002/03/14 04:24:20 nbryant + support window resizing in curses mode + Revision 590.152 2002/03/13 04:11:11 nbryant fix up minor gotcha introduced by fgets change @@ -3502,4 +3505,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/citadel.c b/citadel/citadel.c index 7f5b7dd43..59819c905 100644 --- a/citadel/citadel.c +++ b/citadel/citadel.c @@ -689,13 +689,10 @@ void check_screen_dims(void) unsigned short ypixels; /* pixels */ } xwinsz; - if (scr_set_windowsize()) - return; - if (have_xterm) { /* dynamically size screen if on an xterm */ if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) { if (xwinsz.height) - screenheight = (int) xwinsz.height; + screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height; if (xwinsz.width) screenwidth = (int) xwinsz.width; } @@ -950,7 +947,10 @@ int main(int argc, char **argv) sttybbs(SB_NO_INTR); /* Install the new ones */ signal(SIGHUP, dropcarr); /* Cleanup gracefully if carrier is dropped */ signal(SIGTERM, dropcarr); /* Cleanup gracefully if terminated */ - signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */ + signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */ +#ifdef SIGWINCH + signal(SIGWINCH, scr_winch); /* Window resize signal */ +#endif #ifdef HAVE_OPENSSL arg_encrypt = RC_DEFAULT; diff --git a/citadel/citadel_decls.h b/citadel/citadel_decls.h index ce789ac1e..94f9d260d 100644 --- a/citadel/citadel_decls.h +++ b/citadel/citadel_decls.h @@ -27,3 +27,4 @@ void logoff(int code); void formout(char *name); void sighandler(int which_sig); void do_system_configuration(void); +extern int secure; diff --git a/citadel/client_chat.c b/citadel/client_chat.c index 482bcdc26..7c4b02c56 100644 --- a/citadel/client_chat.c +++ b/citadel/client_chat.c @@ -111,7 +111,7 @@ void chatmode(void) goto RCL; } if (FD_ISSET(0, &rfds)) { - ch = scr_getc(); + ch = scr_getc(SCR_BLOCK); if ((ch == 10) || (ch == 13)) { send_complete_line = 1; } else if ((ch == 8) || (ch == 127)) { diff --git a/citadel/commands.c b/citadel/commands.c index 69a7340cf..ade3f26d1 100644 --- a/citadel/commands.c +++ b/citadel/commands.c @@ -460,7 +460,9 @@ int inkey(void) * necessary and then waits again. */ do { + scr_set_windowsize(); do_keepalive(); + scr_set_windowsize(); FD_ZERO(&rfds); FD_SET(0, &rfds); @@ -473,7 +475,7 @@ int inkey(void) /* At this point, there's input, so fetch it. * (There's a hole in the bucket...) */ - a = scr_getc(); + a = scr_getc(SCR_NOBLOCK); if (a == 127) a = 8; if (a > 126) @@ -483,6 +485,12 @@ int inkey(void) if (((a != 4) && (a != 10) && (a != 8) && (a != NEXT_KEY) && (a != STOP_KEY)) && ((a < 32) || (a > 126))) a = 0; + +#if defined(HAVE_CURSES_H) || defined(HAVE_NCURSES_H) + if (a == ERR) + a = 0; +#endif + } while (a == 0); return (a); } diff --git a/citadel/screen.c b/citadel/screen.c index c8cb29603..2c266b06d 100644 --- a/citadel/screen.c +++ b/citadel/screen.c @@ -5,12 +5,8 @@ */ #include "sysdep.h" -#ifdef HAVE_NCURSES_H -#include -#elif defined(HAVE_CURSES_H) -#include -#endif #include +#include #include #include #include @@ -27,6 +23,7 @@ #include "citadel.h" #include "commands.h" #include "screen.h" +#include "citadel_decls.h" #ifdef HAVE_CURSES_H static SCREEN *myscreen = NULL; @@ -279,18 +276,27 @@ int sln_printf_if(char *fmt, ...) } -int scr_getc(void) +int scr_getc(int delay) { char buf; + #ifdef HAVE_CURSES_H - if (mainwindow) + if (mainwindow) { + wtimeout(mainwindow, delay); return wgetch(mainwindow); + } #endif + buf = '\0'; read (0, &buf, 1); return buf; } +/* the following is unused and looks broken, but there may + be some input problems still lurking in curses mode, so + i'll leave it blocked out for now for informational + purposes. */ +#if 0 int scr_blockread(void) { int a = 0; @@ -307,6 +313,7 @@ int scr_blockread(void) #endif return a; } +#endif /* 0 */ /* * scr_putc() outputs a single character @@ -397,33 +404,43 @@ void sln_flush(void) fflush(stdout); } +static volatile int caught_sigwinch = 0; -int scr_set_windowsize(void) +/* + * this is not supposed to be called from a signal handler. + */ +int scr_set_windowsize() { #ifdef HAVE_CURSES_H - int y, x; - - if (mainwindow) { - getmaxyx(mainwindow, y, x); - screenheight = y; - screenwidth = x; + if (mainwindow && caught_sigwinch) { + caught_sigwinch = 0; + resizeterm(screenheight + 1, screenwidth); + wresize(mainwindow, screenheight, screenwidth); + wresize(statuswindow, 1, screenwidth); + mvwin(statuswindow, screenheight, 0); + status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, + room_name, secure, -1); + wnoutrefresh(mainwindow); + wnoutrefresh(statuswindow); + doupdate(); return 1; } #endif /* HAVE_CURSES_H */ return 0; } - /* * scr_winch() handles window size changes from SIGWINCH * resizes all our windows for us */ -RETSIGTYPE scr_winch(void) +RETSIGTYPE scr_winch(int signum) { -#ifdef HAVE_CURSES_H - /* FIXME: not implemented */ -#endif + /* if we receive this signal, we must be running + in a terminal that supports resizing. */ + have_xterm = 1; + caught_sigwinch = 1; check_screen_dims(); + signal(SIGWINCH, scr_winch); } diff --git a/citadel/screen.h b/citadel/screen.h index 9e565a006..3c47d710f 100644 --- a/citadel/screen.h +++ b/citadel/screen.h @@ -1,5 +1,13 @@ /* $Id$ */ +/* client code may need the ERR define: */ + +#ifdef HAVE_NCURSES_H +#include +#elif defined(HAVE_CURSES_H) +#include +#endif + void status_line(const char *humannode, const char *bbs_city, const char *room_name, int secure, int newmailcount); void screen_new(void); @@ -10,7 +18,11 @@ int scr_printf(char *fmt, ...); int err_printf(char *fmt, ...); int sln_printf(char *fmt, ...); int sln_printf_if(char *fmt, ...); -int scr_getc(void); + +#define SCR_NOBLOCK 0 +#define SCR_BLOCK -1 +int scr_getc(int delay); + int scr_putc(int c); int sln_putc(int c); int scr_color(int colornum); @@ -22,3 +34,4 @@ void windows_new(void); void windows_delete(void); int scr_blockread(void); int is_curses_enabled(void); +RETSIGTYPE scr_winch(int signum); -- 2.30.2