]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/resizeterm.3x
ncurses 6.4 - patch 20231021
[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.49 2023/10/21 10:31:22 tom Exp $
33 .TH resizeterm 3X 2023-10-21 "ncurses 6.4" "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 \fIncurses\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 \fIcurses\fP windows cannot extend outside the screen.
58 If the terminal is shrunk, \fIcurses\fP 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 \fB\%SIGWINCH\fP
65 when it initializes \fIncurses\fP
66 (e.g., using \fB\%initscr\fP(3X) or \fB\%newterm\fP(3X)),
67 then \fIncurses\fP sets a handler for \fB\%SIGWINCH\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 \fB\%endwin\fP(3X) and \fB\%wrefresh\fP(3X)),
75 and
76 .bP
77 when explicitly resuming program mode in \fB\%restartterm\fP(3X).
78 .PP
79 When the library has found that the terminal's window-size has
80 changed, it calls \fB\%resizeterm\fP to update its data structures.
81 .PP
82 An application which establishes its own \fB\%SIGWINCH\fP handler
83 can call \fB\%resizeterm\fP, but in that case, the library will not
84 see \fB\%SIGWINCH\fP, and proper layout will rely upon the application.
85 .SH FUNCTIONS
86 .SS resizeterm
87 The function \fB\%resizeterm\fP resizes the standard and current windows
88 (i.e., \fB\%stdscr\fP and \fB\%curscr\fP)
89 to the specified dimensions, and adjusts other bookkeeping data used by
90 the \fIncurses\fP library that record the window dimensions
91 such as the \fB\%LINES\fP and \fB\%COLS\fP variables.
92 .SS resize_term
93 Most of the work for \fB\%resizeterm\fP is
94 done by the inner function \fB\%resize_term\fP.
95 The outer function \fB\%resizeterm\fP adds bookkeeping
96 for the \fB\%SIGWINCH\fP handler,
97 as well as repainting the soft-key area (see \fB\%slk_touch\fP(3X)).
98 .PP
99 The \fB\%resize_term\fP function attempts to resize all windows.
100 This helps with simple applications.
101 However:
102 .bP
103 It is not possible to automatically resize pads.
104 .bP
105 Applications which have complicated layouts should check for
106 \fB\%KEY_RESIZE\fP returned from \fB\%wgetch\fP,
107 and adjust their layout, e.g., using \fB\%wresize\fP and \fB\%mvwin\fP,
108 or by recreating the windows.
109 .PP
110 When resizing windows, \fB\%resize_term\fP recursively adjusts subwindows,
111 keeping them within the updated parent window's limits.
112 If a top-level window happens to extend to the screen's limits,
113 then on resizing the window, \fB\%resize_term\fP will keep the window
114 extending to the corresponding limit, regardless of whether the
115 screen has shrunk or grown.
116 .SS is_term_resized
117 A support function \fB\%is_term_resized\fP is provided so that applications
118 can check if the \fB\%resize_term\fP function would modify
119 the window structures.
120 It returns \fBTRUE\fP if the windows would be modified,
121 and \fBFALSE\fP otherwise.
122 .SH RETURN VALUE
123 Except as noted, these functions return
124 the integer \fBERR\fP upon failure and \fBOK\fP on success.
125 They will fail if either of the dimensions are less than or equal to zero,
126 or if an error occurs while (re)allocating memory for the windows.
127 .SH NOTES
128 While these functions are intended to be used to support a signal handler
129 (i.e., for \fB\%SIGWINCH\fP), care should be taken to avoid invoking them in a
130 context where \fB\%malloc\fP or \fB\%realloc\fP may have been interrupted,
131 since it uses those functions.
132 .PP
133 If \fIncurses\fP is configured to supply its own \fB\%SIGWINCH\fP handler,
134 .bP
135 on receipt of a \fB\%SIGWINCH\fP, the handler sets a flag
136 .bP
137 which is tested in
138 \fB\%wgetch\fP(3X),
139 \fB\%doupdate\fP(3X) and
140 \fB\%restartterm\fP(3X),
141 .bP
142 in turn, calling the \fB\%resizeterm\fP function,
143 .bP
144 which \fB\%ungetch\fP's a \fB\%KEY_RESIZE\fP which
145 will be read on the next call to \fB\%wgetch\fP.
146 .IP
147 The \fB\%KEY_RESIZE\fP alerts an application that the screen size has changed,
148 and that it should repaint special features such as pads that cannot
149 be done automatically.
150 .IP
151 Calling \fB\%resizeterm\fP or \fB\%resize_term\fP
152 directly from a signal handler is unsafe.
153 This indirect method is used to provide a safe way to resize the \fIncurses\fP
154 data structures.
155 .PP
156 If the environment variables \fB\%LINES\fP or \fB\%COLUMNS\fP are set,
157 this overrides the library's use of the window size obtained from
158 the operating system.
159 Thus, even if a \fB\%SIGWINCH\fP is received,
160 no screen size change may be recorded.
161 .SH PORTABILITY
162 It is possible to resize the screen with SVr4 \fIcurses\fP,
163 by
164 .bP
165 exiting \fIcurses\fP with \fB\%endwin\fP(3X) and
166 .bP
167 resuming using \fB\%refresh\fP(3X).
168 .PP
169 Doing that clears the screen and is visually distracting.
170 .PP
171 This extension of \fIncurses\fP was introduced in mid-1995.
172 It was adopted in NetBSD \fIcurses\fP (2001) and PDCurses (2003).
173 .SH AUTHOR
174 Thomas Dickey (from an equivalent function written in 1988 for BSD \fIcurses\fP)
175 .SH SEE ALSO
176 \fB\%curs_getch\fP(3X),
177 \fB\%curs_variables\fP(3X),
178 \fB\%wresize\fP(3X)