引用自INSTALL:
--enable-sigwinch
Compile support for ncurses' SIGWINCH handler. If your application has
its own SIGWINCH handler, ncurses will not use its own. The ncurses
handler causes wgetch() to return KEY_RESIZE when the screen-size
changes. This option is the default, unless you have disabled the
extended functions.
Run Code Online (Sandbox Code Playgroud)
如果它不存在,则它已被禁用。原则上,您可以按照test/view.cCAN_RESIZE文件中最近删除(早已过时)的部分所示进行操作。ncurses 库比这做得更好;该示例于 1995 年 7 月添加。注释引用了 SunOS 4:
/*
* This uses functions that are "unsafe", but it seems to work on SunOS.
* Usually: the "unsafe" refers to the functions that POSIX lists which may be
* called from a signal handler. Those do not include buffered I/O, which is
* used for instance in wrefresh(). To be really portable, you should use the
* KEY_RESIZE return (which relies on ncurses' sigwinch handler).
*
* The 'wrefresh(curscr)' is needed to force the refresh to start from the top
* of the screen -- some xterms mangle the bitmap while resizing.
*/
Run Code Online (Sandbox Code Playgroud)
现代的等效方法只是在信号处理程序中设置一个标志,如库中所做的那样:
#if USE_SIGWINCH
static void
handle_SIGWINCH(int sig GCC_UNUSED)
{
_nc_globals.have_sigwinch = 1;
# if USE_PTHREADS_EINTR
if (_nc_globals.read_thread) {
if (!pthread_equal(pthread_self(), _nc_globals.read_thread))
pthread_kill(_nc_globals.read_thread, SIGWINCH);
_nc_globals.read_thread = 0;
}
# endif
}
#endif /* USE_SIGWINCH */
Run Code Online (Sandbox Code Playgroud)
顺便说一下,包脚本没有显示该功能已被禁用:
./configure --prefix=/usr --mandir=/usr/share/man \
--with-pkg-config-libdir=/usr/lib/pkgconfig \
--with-static --with-normal --without-debug --without-ada \
--enable-widec --enable-pc-files --with-cxx-binding --with-cxx-static \
--with-shared --with-cxx-shared
Run Code Online (Sandbox Code Playgroud)
回顾一下库,SIGWINCH如果信号是默认(未设置)值,它会初始化其处理程序:
#if USE_SIGWINCH
CatchIfDefault(SIGWINCH, handle_SIGWINCH);
#endif
Run Code Online (Sandbox Code Playgroud)
如果已经有一个SIGWINCH处理程序,ncurses 将不会执行任何操作。