Debian Codegraph @

upstream/debian-unstable/man3/resizeterm.3ncurses

raw
1 .\"***************************************************************************
2 .\" Copyright 2018-2024,2025 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.65 2025/07/05 13:06:45 tom Exp $
33 .TH resizeterm 3NCURSES 2025-07-05 "ncurses 6.6" "Library calls"
34 .de bP
35 .ie n .IP \(bu 4
36 .el .IP \(bu 2
37 ..
38 .SH NAME
39 \fB\%is_term_resized\fP,
40 \fB\%resize_term\fP,
41 \fB\%resizeterm\fP \-
42 manage the terminal dimensions understood by \fIcurses\fR
43 .SH SYNOPSIS
44 .nf
45 \fB#include <curses.h>
46 .PP
47 \fBbool is_term_resized(int \fIlines\fP, int \fIcolumns\fP);
48 \fBint resize_term(int \fIlines\fP, int \fIcolumns\fP);
49 \fBint resizeterm(int \fIlines\fP, int \fIcolumns\fP);
50 .fi
51 .SH DESCRIPTION
52 This is an extension to the \fIcurses\fP library.
53 It provides callers with a hook into the \fI\%ncurses\fP data to resize
54 windows,
55 primarily for use by programs running in an X Window terminal (e.g., xterm)
56 when the terminal's screen size is changed by the user:
57 .bP
58 \fIcurses\fP windows cannot extend outside the screen.
59 If the terminal is shrunk, \fIcurses\fP windows must be shrunk to fit.
60 .bP
61 If the terminal is stretched,
62 rows and/or columns can be added to existing windows.
63 The added cells should match the current attributes of the windows.
64 .PP
65 If the application has not set up a handler for
66 .I \%SIGWINCH
67 when it initializes
68 .I \%ncurses
69 (by calling \fB\%initscr\fP(3NCURSES) or \fB\%newterm\fP(3NCURSES)),
70 then
71 .I \%ncurses
72 establishes a
73 .I \%SIGWINCH
74 handler that notifies the library
75 when a window-resizing event has occurred.
76 The library checks for this notification
77 .bP
78 when reading input data,
79 .bP
80 when implicitly resuming program mode
81 (e.g., between \fB\%endwin\fP(3NCURSES) and \fB\%wrefresh\fP(3NCURSES)),
82 and
83 .bP
84 when explicitly resuming program mode in \fB\%restartterm\fP(3NCURSES).
85 .PP
86 When the library has found that the terminal's window-size has
87 changed, it calls \fB\%resizeterm\fP to update its data structures.
88 .PP
89 An application which establishes its own
90 .I \%SIGWINCH
91 handler
92 can call \fB\%resizeterm\fP, but in that case, the library will not
93 see
94 .IR \%SIGWINCH ","
95 and proper layout will rely upon the application.
96 .SS resizeterm
97 The function \fB\%resizeterm\fP resizes the standard and current windows
98 (i.e., \fB\%stdscr\fP and \fB\%curscr\fP)
99 to the specified dimensions, and adjusts other bookkeeping data used by
100 the \fI\%ncurses\fP library that record the window dimensions
101 such as the \fB\%LINES\fP and \fB\%COLS\fP variables.
102 .SS resize_term
103 Most of the work for \fB\%resizeterm\fP is
104 done by the inner function \fB\%resize_term\fP.
105 The outer function \fB\%resizeterm\fP adds bookkeeping
106 for the
107 .I \%SIGWINCH
108 handler,
109 as well as repainting the soft-key area (see \fB\%slk_touch\fP(3NCURSES)).
110 .PP
111 The \fB\%resize_term\fP function attempts to resize all windows.
112 This helps with simple applications.
113 However:
114 .bP
115 It is not possible to automatically resize pads.
116 .bP
117 Applications which have complicated layouts should check for
118 \fB\%KEY_RESIZE\fP returned from \fB\%wgetch\fP,
119 and adjust their layout, e.g., using \fB\%wresize\fP and \fB\%mvwin\fP,
120 or by recreating the windows.
121 .PP
122 When resizing windows, \fB\%resize_term\fP recursively adjusts subwindows,
123 keeping them within the updated parent window's limits.
124 If a top-level window happens to extend to the screen's limits,
125 then on resizing the window, \fB\%resize_term\fP will keep the window
126 extending to the corresponding limit, regardless of whether the
127 screen has shrunk or grown.
128 .SS is_term_resized
129 A support function \fB\%is_term_resized\fP is provided so that applications
130 can check if the \fB\%resize_term\fP function would modify
131 the window structures.
132 It returns \fBTRUE\fP if the windows would be modified,
133 and \fBFALSE\fP otherwise.
134 .SH RETURN VALUE
135 Except as noted, these functions return
136 the integer \fBERR\fP upon failure and \fBOK\fP on success.
137 They will fail if either of the dimensions are less than or equal to zero,
138 or if an error occurs while (re)allocating memory for the windows.
139 .SH NOTES
140 While these functions are intended to be used to support a signal handler
141 (i.e., for
142 .IR \%SIGWINCH "),"
143 care should be taken to avoid invoking them in a
144 context where \fB\%malloc\fP or \fB\%realloc\fP may have been interrupted,
145 since it uses those functions.
146 .PP
147 If \fI\%ncurses\fP is configured to supply its own
148 .I \%SIGWINCH
149 handler,
150 .bP
151 on receipt of a
152 .IR \%SIGWINCH ","
153 the handler sets a flag
154 .bP
155 which is tested in
156 \fB\%wgetch\fP(3NCURSES),
157 \fB\%doupdate\fP(3NCURSES) and
158 \fB\%restartterm\fP(3NCURSES),
159 .bP
160 in turn, calling the \fB\%resizeterm\fP function,
161 .bP
162 which \fB\%ungetch\fP's a \fB\%KEY_RESIZE\fP which
163 will be read on the next call to \fB\%wgetch\fP.
164 .IP
165 The \fB\%KEY_RESIZE\fP alerts an application that the screen size has changed,
166 and that it should repaint special features such as pads that cannot
167 be done automatically.
168 .IP
169 Calling \fB\%resizeterm\fP or \fB\%resize_term\fP
170 directly from a signal handler is unsafe.
171 This indirect method is used to provide a safe way to resize the
172 \fI\%ncurses\fP data structures.
173 .PP
174 If the environment variables \fILINES\fP or \fI\%COLUMNS\fP are set,
175 this overrides the library's use of the window size obtained from
176 the operating system.
177 Thus, even if a
178 .I \%SIGWINCH
179 is received,
180 no screen size change may be recorded.
181 .SH PORTABILITY
182 It is possible to resize the screen with SVr4 \fIcurses\fP,
183 by
184 .bP
185 exiting \fIcurses\fP with \fB\%endwin\fP(3NCURSES) and
186 .bP
187 resuming using \fB\%refresh\fP(3NCURSES).
188 .PP
189 Doing that clears the screen and is visually distracting.
190 .PP
191 .I \%ncurses
192 introduced this extension in mid-1995.
193 NetBSD
194 .I curses
195 adopted it in 2001 and
196 .I \%PDCurses
197 in 2003.
198 .SH AUTHORS
199 Thomas Dickey (from an equivalent function written in 1988 for BSD \fIcurses\fP)
200 .SH SEE ALSO
201 \fB\%getch\fP(3NCURSES),
202 \fB\%curses_variables\fP(3NCURSES),
203 \fB\%wresize\fP(3NCURSES)