]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/resizeterm.3x
ncurses 6.3 - patch 20220305
[ncurses.git] / man / resizeterm.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2021,2022 Thomas E. Dickey                                *
3 .\" Copyright 1998-2015,2017 Free Software Foundation, Inc.                  *
4 .\"                                                                          *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
6 .\" copy of this software and associated documentation files (the            *
7 .\" "Software"), to deal in the Software without restriction, including      *
8 .\" without limitation the rights to use, copy, modify, merge, publish,      *
9 .\" distribute, distribute with modifications, sublicense, and/or sell       *
10 .\" copies of the Software, and to permit persons to whom the Software is    *
11 .\" furnished to do so, subject to the following conditions:                 *
12 .\"                                                                          *
13 .\" The above copyright notice and this permission notice shall be included  *
14 .\" in all copies or substantial portions of the Software.                   *
15 .\"                                                                          *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23 .\"                                                                          *
24 .\" Except as contained in this notice, the name(s) of the above copyright   *
25 .\" holders shall not be used in advertising or otherwise to promote the     *
26 .\" sale, use or other dealings in this Software without prior written       *
27 .\" authorization.                                                           *
28 .\"***************************************************************************
29 .\"
30 .\" Author: Thomas E. Dickey 1996-on
31 .\"
32 .\" $Id: resizeterm.3x,v 1.32 2022/02/20 00:32:18 tom Exp $
33 .TH resizeterm 3X ""
34 .de bP
35 .ie n  .IP \(bu 4
36 .el    .IP \(bu 2
37 ..
38 .SH NAME
39 \fBis_term_resized\fP,
40 \fBresize_term\fP,
41 \fBresizeterm\fP \- change the curses terminal size
42 .SH SYNOPSIS
43 \fB#include <curses.h>\fP
44 .sp
45 \fBbool is_term_resized(int \fIlines\fB, int \fIcolumns\fB);\fR
46 .br
47 \fBint resize_term(int \fIlines\fB, int \fIcolumns\fB);\fR
48 .br
49 \fBint resizeterm(int \fIlines\fB, int \fIcolumns\fB);\fR
50 .SH DESCRIPTION
51 .PP
52 This is an extension to the curses library.
53 It provides callers with a hook into the \fBncurses\fP data to resize windows,
54 primarily for use by programs running in an X Window terminal (e.g., xterm)
55 when the terminal's screen size is changed by the user:
56 .bP
57 Curses windows cannot extend outside the screen.
58 If the terminal is shrunk, curses windows must be shrunk to fit.
59 .bP
60 If the terminal is stretched,
61 rows and/or columns can be added to existing windows.
62 The added cells should match the current attributes of the windows.
63 .PP
64 If the calling program has not set up a handler for \fBSIGWINCH\fP
65 when it initializes \fBncurses\fP
66 (e.g., using \fBinitscr\fP(3X) or \fBnewterm\fP(3X)),
67 then \fBncurses\fP sets a handler for \fBSIGWINCH\fP which notifies
68 the library when a window-size event has occurred.
69 The library checks for this notification
70 .bP
71 when reading input data,
72 .bP
73 when implicitly resuming program mode
74 (e.g., between \fBendwin\fP(3X) and \fBwrefresh\fP(3X)),
75 and
76 .bP
77 when explicitly resuming program mode in \fBrestartterm\fP(3X).
78 .PP
79 When the library has found that the terminal's window-size has
80 changed, it calls \fBresizeterm\fP to update its data structures.
81 .PP
82 An application which establishes its own \fBSIGWINCH\fP handler
83 can call \fBresizeterm\fP, but in that case, the library will not
84 see \fBSIGWINCH\fP, and proper layout will rely upon the application.
85 .SH FUNCTIONS
86 .SS resizeterm
87 .PP
88 The function \fBresizeterm\fP resizes the standard and current windows
89 (i.e., \fBstdscr\fP and \fBcurscr\fP)
90 to the specified dimensions, and adjusts other bookkeeping data used by
91 the \fBncurses\fP library that record the window dimensions
92 such as the \fBLINES\fP and \fBCOLS\fP variables.
93 .SS resize_term
94 .PP
95 Most of the work for \fBresizeterm\fP is
96 done by the inner function \fBresize_term\fP.
97 The outer function \fBresizeterm\fP adds bookkeeping
98 for the \fBSIGWINCH\fP handler,
99 as well as repainting the soft-key area (see \fBslk_touch\fP(3X)).
100 .PP
101 The \fBresize_term\fP function attempts to resize all windows.
102 This helps with simple applications.
103 However:
104 .bP
105 It is not possible to automatically resize pads.
106 .bP
107 Applications which have complicated layouts should check for
108 \fBKEY_RESIZE\fP returned from \fBwgetch\fP,
109 and adjust their layout, e.g., using \fBwresize\fP and \fBmvwin\fP,
110 or by recreating the windows.
111 .PP
112 When resizing windows, \fBresize_term\fP recursively adjusts subwindows,
113 keeping them within the updated parent window's limits.
114 If a top-level window happens to extend to the screen's limits,
115 then on resizing the window, \fBresize_term\fP will keep the window
116 extending to the corresponding limit, regardless of whether the
117 screen has shrunk or grown.
118 .SS is_term_resized
119 .PP
120 A support function \fBis_term_resized\fP is provided so that applications
121 can check if the \fBresize_term\fP function would modify the window structures.
122 It returns \fBTRUE\fP if the windows would be modified,
123 and \fBFALSE\fP otherwise.
124 .SH RETURN VALUE
125 Except as noted, these functions return
126 the integer \fBERR\fP upon failure and \fBOK\fP on success.
127 They will fail if either of the dimensions are less than or equal to zero,
128 or if an error occurs while (re)allocating memory for the windows.
129 .SH NOTES
130 While these functions are intended to be used to support a signal handler
131 (i.e., for \fBSIGWINCH\fP), care should be taken to avoid invoking them in a
132 context where \fBmalloc\fP or \fBrealloc\fP may have been interrupted,
133 since it uses those functions.
134 .PP
135 If ncurses is configured to supply its own \fBSIGWINCH\fP handler,
136 .bP
137 on receipt of a \fBSIGWINCH\fP, the handler sets a flag
138 .bP
139 which is tested in
140 \fBwgetch\fP(3X),
141 \fBdoupdate\fP(3X) and
142 \fBrestartterm\fP(3X),
143 .bP
144 in turn, calling the \fBresizeterm\fP function,
145 .bP
146 which \fBungetch\fP's a \fBKEY_RESIZE\fP which
147 will be read on the next call to \fBwgetch\fP.
148 .IP
149 The \fBKEY_RESIZE\fP alerts an application that the screen size has changed,
150 and that it should repaint special features such as pads that cannot
151 be done automatically.
152 .IP
153 Calling \fBresizeterm\fP or \fBresize_term\fP
154 directly from a signal handler is unsafe.
155 This indirect method is used to provide a safe way to resize the ncurses
156 data structures.
157 .PP
158 If the environment variables \fBLINES\fP or \fBCOLUMNS\fP are set,
159 this overrides the library's use of the window size obtained from
160 the operating system.
161 Thus, even if a \fBSIGWINCH\fP is received,
162 no screen size change may be recorded.
163 .SH PORTABILITY
164 .PP
165 It is possible to resize the screen with SVr4 curses,
166 by
167 .bP
168 exiting curses with \fBendwin\fP(3X) and
169 .bP
170 resuming using \fBrefresh\fP(3X).
171 .PP
172 Doing that clears the screen and is visually distracting.
173 .PP
174 This extension of ncurses was introduced in mid-1995.
175 It was adopted in NetBSD curses (2001) and PDCurses (2003).
176 .SH SEE ALSO
177 \fBcurs_getch\fP(3X),
178 \fBcurs_variables\fP(3X),
179 \fBwresize\fP(3X).
180 .SH AUTHOR
181 Thomas Dickey (from an equivalent function written in 1988 for BSD curses).