I'm working on getting main-gcu.c to handle resizing of the term window. This is for S, but it should be relevant to all variants.
I have made a fair bit of progress, but I'm having some problems.
First, let's take a look at the NCURSES FAQ:
Now the first approach seems complicated, so I want to focus on the resizeterm one. The Ncurses 5.0 KEY_RESIZE approach seems also limiting because of the strict version requirement.
So, I should need the following:
- A signal handler for SIGWINCH - check.
- Check LINES & COLS for new size - check.
- Call resizeterm to set new size - check.
- Use wresize and Term_resize on the sub-windows - check.
But, it doesn't work!
I suspect that there's something work in the signal code itself, but I'm not sure.
Does anyone have had problems with the signals? Any hints at all?
I have made a fair bit of progress, but I'm having some problems.
First, let's take a look at the NCURSES FAQ:
It is possible to make an application resize when running in a windowing environment (e.g., in an xterm). This is not a feature of standard SVr4 curses, though some curses implementations (e.g., HP-UX) support this.
Within ncurses, there are two ways to accomplish this. One relies on side-effects of the library functions, and is moderately portable. The other is an extension to SVr4 curses.
* endwin/refresh when invoked will briefly exit curses and reinitialize the display, picking up the new screen size. Ncurses will reallocate the WINDOW data (e.g., curscr, stdscr) to reflect the new limits.
* resizeterm can be invoked directly to make ncurses resize its WINDOW data. I use it in my directory editor ded to achieve flicker-free resizing via a signal handler for SIGWINCH. (The documentation for HP-UX curses implies that they use a similar approach; I have been unable to make it work.)
Ncurses 5.0 can be configured to establish its own SIGWINCH hander. In this configuration, the wgetch function will return a special keycode KEY_RESIZE when a resizing event is detected. The signal handler also calls resizeterm (Caveat: malloc and free are not guaranteed to be safe for use in a signal handler).
Within ncurses, there are two ways to accomplish this. One relies on side-effects of the library functions, and is moderately portable. The other is an extension to SVr4 curses.
* endwin/refresh when invoked will briefly exit curses and reinitialize the display, picking up the new screen size. Ncurses will reallocate the WINDOW data (e.g., curscr, stdscr) to reflect the new limits.
* resizeterm can be invoked directly to make ncurses resize its WINDOW data. I use it in my directory editor ded to achieve flicker-free resizing via a signal handler for SIGWINCH. (The documentation for HP-UX curses implies that they use a similar approach; I have been unable to make it work.)
Ncurses 5.0 can be configured to establish its own SIGWINCH hander. In this configuration, the wgetch function will return a special keycode KEY_RESIZE when a resizing event is detected. The signal handler also calls resizeterm (Caveat: malloc and free are not guaranteed to be safe for use in a signal handler).
So, I should need the following:
- A signal handler for SIGWINCH - check.
- Check LINES & COLS for new size - check.
- Call resizeterm to set new size - check.
- Use wresize and Term_resize on the sub-windows - check.
But, it doesn't work!
I suspect that there's something work in the signal code itself, but I'm not sure.
Code:
/* * Handle signals -- term resize (SIGWINCH) -CJN- */ static void handle_signal_resize(int sig) { /* Protect errno from library calls in signal handler */ int save_errno = errno; /* Disable handler */ (void)(*signal_aux)(sig, SIG_IGN); /* React to changes */ (void)Term_xtra(TERM_XTRA_REACT, 0); /* Restore handler */ (void)(*signal_aux)(sig, handle_signal_resize); /* Restore errno */ errno = save_errno; }
Code:
#ifdef SIGWINCH (void)(*signal_aux)(SIGWINCH, handle_signal_resize); #endif
Comment