]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/resizeterm.3x
ncurses 6.4 - patch 20230701
[ncurses.git] / man / resizeterm.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2022,2023 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.36 2023/07/01 15:46:10 tom Exp $
33 .TH resizeterm 3X 2023-07-01 "ncurses 6.4" "Library calls"
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 This is an extension to the curses library.
52 It provides callers with a hook into the \fBncurses\fP data to resize windows,
53 primarily for use by programs running in an X Window terminal (e.g., xterm)
54 when the terminal's screen size is changed by the user:
55 .bP
56 Curses windows cannot extend outside the screen.
57 If the terminal is shrunk, curses windows must be shrunk to fit.
58 .bP
59 If the terminal is stretched,
60 rows and/or columns can be added to existing windows.
61 The added cells should match the current attributes of the windows.
62 .PP
63 If the calling program has not set up a handler for \fBSIGWINCH\fP
64 when it initializes \fBncurses\fP
65 (e.g., using \fBinitscr\fP(3X) or \fBnewterm\fP(3X)),
66 then \fBncurses\fP sets a handler for \fBSIGWINCH\fP which notifies
67 the library when a window-size event has occurred.
68 The library checks for this notification
69 .bP
70 when reading input data,
71 .bP
72 when implicitly resuming program mode
73 (e.g., between \fBendwin\fP(3X) and \fBwrefresh\fP(3X)),
74 and
75 .bP
76 when explicitly resuming program mode in \fBrestartterm\fP(3X).
77 .PP
78 When the library has found that the terminal's window-size has
79 changed, it calls \fBresizeterm\fP to update its data structures.
80 .PP
81 An application which establishes its own \fBSIGWINCH\fP handler
82 can call \fBresizeterm\fP, but in that case, the library will not
83 see \fBSIGWINCH\fP, and proper layout will rely upon the application.
84 .SH FUNCTIONS
85 .SS resizeterm
86 The function \fBresizeterm\fP resizes the standard and current windows
87 (i.e., \fBstdscr\fP and \fBcurscr\fP)
88 to the specified dimensions, and adjusts other bookkeeping data used by
89 the \fBncurses\fP library that record the window dimensions
90 such as the \fBLINES\fP and \fBCOLS\fP variables.
91 .SS resize_term
92 Most of the work for \fBresizeterm\fP is
93 done by the inner function \fBresize_term\fP.
94 The outer function \fBresizeterm\fP adds bookkeeping
95 for the \fBSIGWINCH\fP handler,
96 as well as repainting the soft-key area (see \fBslk_touch\fP(3X)).
97 .PP
98 The \fBresize_term\fP function attempts to resize all windows.
99 This helps with simple applications.
100 However:
101 .bP
102 It is not possible to automatically resize pads.
103 .bP
104 Applications which have complicated layouts should check for
105 \fBKEY_RESIZE\fP returned from \fBwgetch\fP,
106 and adjust their layout, e.g., using \fBwresize\fP and \fBmvwin\fP,
107 or by recreating the windows.
108 .PP
109 When resizing windows, \fBresize_term\fP recursively adjusts subwindows,
110 keeping them within the updated parent window's limits.
111 If a top-level window happens to extend to the screen's limits,
112 then on resizing the window, \fBresize_term\fP will keep the window
113 extending to the corresponding limit, regardless of whether the
114 screen has shrunk or grown.
115 .SS is_term_resized
116 A support function \fBis_term_resized\fP is provided so that applications
117 can check if the \fBresize_term\fP function would modify the window structures.
118 It returns \fBTRUE\fP if the windows would be modified,
119 and \fBFALSE\fP otherwise.
120 .SH RETURN VALUE
121 Except as noted, these functions return
122 the integer \fBERR\fP upon failure and \fBOK\fP on success.
123 They will fail if either of the dimensions are less than or equal to zero,
124 or if an error occurs while (re)allocating memory for the windows.
125 .SH NOTES
126 While these functions are intended to be used to support a signal handler
127 (i.e., for \fBSIGWINCH\fP), care should be taken to avoid invoking them in a
128 context where \fBmalloc\fP or \fBrealloc\fP may have been interrupted,
129 since it uses those functions.
130 .PP
131 If ncurses is configured to supply its own \fBSIGWINCH\fP handler,
132 .bP
133 on receipt of a \fBSIGWINCH\fP, the handler sets a flag
134 .bP
135 which is tested in
136 \fBwgetch\fP(3X),
137 \fBdoupdate\fP(3X) and
138 \fBrestartterm\fP(3X),
139 .bP
140 in turn, calling the \fBresizeterm\fP function,
141 .bP
142 which \fBungetch\fP's a \fBKEY_RESIZE\fP which
143 will be read on the next call to \fBwgetch\fP.
144 .IP
145 The \fBKEY_RESIZE\fP alerts an application that the screen size has changed,
146 and that it should repaint special features such as pads that cannot
147 be done automatically.
148 .IP
149 Calling \fBresizeterm\fP or \fBresize_term\fP
150 directly from a signal handler is unsafe.
151 This indirect method is used to provide a safe way to resize the ncurses
152 data structures.
153 .PP
154 If the environment variables \fBLINES\fP or \fBCOLUMNS\fP are set,
155 this overrides the library's use of the window size obtained from
156 the operating system.
157 Thus, even if a \fBSIGWINCH\fP is received,
158 no screen size change may be recorded.
159 .SH PORTABILITY
160 It is possible to resize the screen with SVr4 curses,
161 by
162 .bP
163 exiting curses with \fBendwin\fP(3X) and
164 .bP
165 resuming using \fBrefresh\fP(3X).
166 .PP
167 Doing that clears the screen and is visually distracting.
168 .PP
169 This extension of ncurses was introduced in mid-1995.
170 It was adopted in NetBSD curses (2001) and PDCurses (2003).
171 .SH SEE ALSO
172 \fBcurs_getch\fP(3X),
173 \fBcurs_variables\fP(3X),
174 \fBwresize\fP(3X).
175 .SH AUTHOR
176 Thomas Dickey (from an equivalent function written in 1988 for BSD curses).