--------------------------------------------------------------------------- Stop Signal under Curses SIGRET sigtstp() { SIGRET (*func)(); func = signal(SIGTSTP,SIG_DFL); tstp(); (void) signal(SIGTSTP,func); } Define SIGRET as either int or void to make your compiler happy. Do signal(SIGTSTP,sigtstp) early on in main(). Race condition free SigStop SIGRET sigtstp() { int i; /* do whatever tty manipulations you want */ sigdfl_tstp(); i = getpgrp(getpid()); ioctl(fdtty,TIOCSPGRP,&i); /* do whatever tty manipulations you want */ } sigdfl_tstp() is the same as sigdfl(SIGTSTP). It depends on my sigdfl library, which you can pick up as part of (e.g.) my multitee package, wuarchive.wustl.edu:usenet/alt.sources/articles/4233.Z. It does what you'd expect, but better: it works whether or not the signal is blocked, caught, or ignored. sigdfl(SIGABRT) guarantees a core dump, for instance, exactly as if your process had received SIGABRT with an action of SIG_DFL. The getpgrp() and TIOCSPGRP manipulations are there for a subtle but important reason. If you typento the background, it'll hang. That's because rn doesn't make sure that it's back in the foreground before attempting to manipulate the tty. TIOCSPGRP makes sure that it's back in the foreground. You do need a descriptor for the current tty, fdtty. Most programs assume that fdtty = 0 will work. Also, getpgrp(getpid()) can be replaced by getpgrp(0) on most systems, though I've seen BSD variants where this is buggy. --- Dan Bernstein brnstnd@nyu.edu --------------------------------------------------------------------------- Pop-up dialog window over the top of the main (or other) windows Generaly the best (whatever that meens ;-) method for overlaying windows is to use the overlay() or overwrite() functions. One thing to remember is that the process of overlaying windows causes the contents of any overlapping section of the new window (your popup) to be written into the one you are overlaying. The contents they overwrite are lost for ever ! overlay(w1,w2) and overwrite(w1,w2) both permanently copy the overlapping part of w1 into w2. overlay() does it *non* destructively, blank chars are not copied so w2's characaters in the overlayed area may show through. overwrite() does it destructively, ie. blanks *are* copied. werase() is useful in this context, it's like wclear() in that it cpoies blanks to the window, but it does not generate the clear-screen sequence at the next wrefresh() which can be a real pain. So, to get down to cases. I think you need to do something like this : wrefresh(main_window); ... /* code that may generate the popup */ { WINDOW *popup_window= subwin(main_window,lines,cols,begx,begy); mvwprintw(popup_window,1,1,"Yes to continue, No to wimp out "); box(popup_window); overwrite(popup_window,main_window); wrefesh(popup_window); wgetch(popup_window); ... /* switch on the reply */ delwin(popup_window); erase(main_window); /* clear the junk out of the display */ ... /* re-generate the main_window contents */ wrefresh(main_window); } ... /* carry on */ --------------------------------------------------------------------------- Window Resizing under curses For a purely technical answer, the trick is to avoid using initscr() to initialize curses. The various man pages on the topic expressly forbid applications from making successive calls to this routine and my experimentaion resulted in failure. There is another mildly more complicated interface which can be used to re-initialize curses which does work called newterm(). In short, when you know the screen size has changed, call endwin() to close the current curses environment, then invoke: newterm(getenv("TERM"), stdout, stdin); My only failure was that I could not get the signal handling to work correctly under Sunview with scrollable cmdtool windows. I did see reference to an alternative signal facility for Sunview called the Notifier, but was unable to get that working before I was shifted to other work. jmd@wrkgrp.COM (Joseph M DeAngelo) --------------------------------------------------------------------------- Sys V 3.2 curses doesn't really resize nicely. The problem is that curses pretty much expects the screen size to be static between initscr() and the final endwin(). If your Unix system implements SIGWINCH then you are half way home. --------------------------------------------------------------------------- I would like to be able to know within a C program the number of text lines available within a given window (Xterm,vt100,etc) just as "more" does. Unfortunately, this is somewhat system-specific. The recommended algorithm is (omitting required declarations): lines = 0; if ( (tty_fd = open( "/dev/tty", O_RDONLY )) >= 0 ) { if ( ioctl( tty_fd, TIOCGWINSZ, &window_info ) == 0 ) /* may be some other ioctl on your system, e.g. JWINSIZE */ lines = window_info.ws_row; /* or .bytesy, etc. */ close( tty_fd ); } if ( lines == 0 && (s = getenv( "LINES" )) != NULL && isdigit( *s ) ) lines = atoi( s ); if ( lines == 0 && (s = getenv( "TERM" )) != NULL && (bp = malloc( 1024 )) != NULL ) { if ( tgetent( bp, s ) == 0 ) lines = tgetnum( "li" ); free( bp ); } /* if lines == 0 at this point, assume continuous forms (ASR-33) */ --- gwyn@smoke.brl.mil (Doug Gwyn) ---------------------------------------------------------------------------