blob: 5e23d9fb37bb91123e4c2967f92d61536114986e [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301.\"***************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002.\" Copyright 2018-2023,2024 Thomas E. Dickey *
3.\" Copyright 1998-2015,2017 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304.\" *
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.\"
Steve Kondikae271bc2015-11-15 02:50:53 +010030.\" Author: Thomas E. Dickey 1996-on
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053031.\"
micky3879b9f5e72025-07-08 18:04:53 -040032.\" $Id: resizeterm.3x,v 1.56 2024/03/16 15:35:01 tom Exp $
33.TH resizeterm 3X 2024-03-16 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls"
34.de bP
35.ie n .IP \(bu 4
36.el .IP \(bu 2
37..
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053038.SH NAME
micky3879b9f5e72025-07-08 18:04:53 -040039\fB\%is_term_resized\fP,
40\fB\%resize_term\fP,
41\fB\%resizeterm\fP \-
42manage the terminal dimensions understood by \fIcurses\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053043.SH SYNOPSIS
micky3879b9f5e72025-07-08 18:04:53 -040044.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
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053051.SH DESCRIPTION
micky3879b9f5e72025-07-08 18:04:53 -040052This is an extension to the \fIcurses\fP library.
53It provides callers with a hook into the \fI\%ncurses\fP data to resize
54windows,
55primarily for use by programs running in an X Window terminal (e.g., xterm)
56when the terminal's screen size is changed by the user:
57.bP
58\fIcurses\fP windows cannot extend outside the screen.
59If the terminal is shrunk, \fIcurses\fP windows must be shrunk to fit.
60.bP
61If the terminal is stretched,
62rows and/or columns can be added to existing windows.
63The added cells should match the current attributes of the windows.
Steve Kondikae271bc2015-11-15 02:50:53 +010064.PP
micky3879b9f5e72025-07-08 18:04:53 -040065If the calling program has not set up a handler for \fB\%SIGWINCH\fP
66when it initializes \fI\%ncurses\fP
67(e.g., using \fB\%initscr\fP(3X) or \fB\%newterm\fP(3X)),
68then \fI\%ncurses\fP sets a handler for \fB\%SIGWINCH\fP which notifies
69the library when a window-size event has occurred.
70The library checks for this notification
71.bP
72when reading input data,
73.bP
74when implicitly resuming program mode
75(e.g., between \fB\%endwin\fP(3X) and \fB\%wrefresh\fP(3X)),
76and
77.bP
78when explicitly resuming program mode in \fB\%restartterm\fP(3X).
79.PP
80When the library has found that the terminal's window-size has
81changed, it calls \fB\%resizeterm\fP to update its data structures.
82.PP
83An application which establishes its own \fB\%SIGWINCH\fP handler
84can call \fB\%resizeterm\fP, but in that case, the library will not
85see \fB\%SIGWINCH\fP, and proper layout will rely upon the application.
86.SH FUNCTIONS
Steve Kondikae271bc2015-11-15 02:50:53 +010087.SS resizeterm
micky3879b9f5e72025-07-08 18:04:53 -040088The function \fB\%resizeterm\fP resizes the standard and current windows
89(i.e., \fB\%stdscr\fP and \fB\%curscr\fP)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053090to the specified dimensions, and adjusts other bookkeeping data used by
micky3879b9f5e72025-07-08 18:04:53 -040091the \fI\%ncurses\fP library that record the window dimensions
92such as the \fB\%LINES\fP and \fB\%COLS\fP variables.
Steve Kondikae271bc2015-11-15 02:50:53 +010093.SS resize_term
micky3879b9f5e72025-07-08 18:04:53 -040094Most of the work for \fB\%resizeterm\fP is
95done by the inner function \fB\%resize_term\fP.
96The outer function \fB\%resizeterm\fP adds bookkeeping
97for the \fB\%SIGWINCH\fP handler,
98as well as repainting the soft-key area (see \fB\%slk_touch\fP(3X)).
Steve Kondikae271bc2015-11-15 02:50:53 +010099.PP
micky3879b9f5e72025-07-08 18:04:53 -0400100The \fB\%resize_term\fP function attempts to resize all windows.
101This helps with simple applications.
102However:
103.bP
104It is not possible to automatically resize pads.
105.bP
106Applications which have complicated layouts should check for
107\fB\%KEY_RESIZE\fP returned from \fB\%wgetch\fP,
108and adjust their layout, e.g., using \fB\%wresize\fP and \fB\%mvwin\fP,
109or by recreating the windows.
110.PP
111When resizing windows, \fB\%resize_term\fP recursively adjusts subwindows,
112keeping them within the updated parent window's limits.
113If a top-level window happens to extend to the screen's limits,
114then on resizing the window, \fB\%resize_term\fP will keep the window
115extending to the corresponding limit, regardless of whether the
116screen has shrunk or grown.
Steve Kondikae271bc2015-11-15 02:50:53 +0100117.SS is_term_resized
micky3879b9f5e72025-07-08 18:04:53 -0400118A support function \fB\%is_term_resized\fP is provided so that applications
119can check if the \fB\%resize_term\fP function would modify
120the window structures.
121It returns \fBTRUE\fP if the windows would be modified,
122and \fBFALSE\fP otherwise.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530123.SH RETURN VALUE
Steve Kondikae271bc2015-11-15 02:50:53 +0100124Except as noted, these functions return
micky3879b9f5e72025-07-08 18:04:53 -0400125the integer \fBERR\fP upon failure and \fBOK\fP on success.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530126They will fail if either of the dimensions are less than or equal to zero,
127or if an error occurs while (re)allocating memory for the windows.
128.SH NOTES
129While these functions are intended to be used to support a signal handler
micky3879b9f5e72025-07-08 18:04:53 -0400130(i.e., for \fB\%SIGWINCH\fP), care should be taken to avoid invoking them in a
131context where \fB\%malloc\fP or \fB\%realloc\fP may have been interrupted,
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530132since it uses those functions.
133.PP
micky3879b9f5e72025-07-08 18:04:53 -0400134If \fI\%ncurses\fP is configured to supply its own \fB\%SIGWINCH\fP
135handler,
136.bP
137on receipt of a \fB\%SIGWINCH\fP, the handler sets a flag
138.bP
139which is tested in
140\fB\%wgetch\fP(3X),
141\fB\%doupdate\fP(3X) and
142\fB\%restartterm\fP(3X),
143.bP
144in turn, calling the \fB\%resizeterm\fP function,
145.bP
146which \fB\%ungetch\fP's a \fB\%KEY_RESIZE\fP which
147will be read on the next call to \fB\%wgetch\fP.
148.IP
149The \fB\%KEY_RESIZE\fP alerts an application that the screen size has changed,
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530150and that it should repaint special features such as pads that cannot
151be done automatically.
micky3879b9f5e72025-07-08 18:04:53 -0400152.IP
153Calling \fB\%resizeterm\fP or \fB\%resize_term\fP
154directly from a signal handler is unsafe.
155This indirect method is used to provide a safe way to resize the
156\fI\%ncurses\fP data structures.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530157.PP
micky3879b9f5e72025-07-08 18:04:53 -0400158If the environment variables \fILINES\fP or \fI\%COLUMNS\fP are set,
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530159this overrides the library's use of the window size obtained from
160the operating system.
micky3879b9f5e72025-07-08 18:04:53 -0400161Thus, even if a \fB\%SIGWINCH\fP is received,
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530162no screen size change may be recorded.
micky3879b9f5e72025-07-08 18:04:53 -0400163.SH PORTABILITY
164It is possible to resize the screen with SVr4 \fIcurses\fP,
165by
166.bP
167exiting \fIcurses\fP with \fB\%endwin\fP(3X) and
168.bP
169resuming using \fB\%refresh\fP(3X).
170.PP
171Doing that clears the screen and is visually distracting.
172.PP
173This extension of \fI\%ncurses\fP was introduced in mid-1995.
174It was adopted in NetBSD \fIcurses\fP (2001) and PDCurses (2003).
175.SH AUTHORS
176Thomas Dickey (from an equivalent function written in 1988 for BSD \fIcurses\fP)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530177.SH SEE ALSO
micky3879b9f5e72025-07-08 18:04:53 -0400178\fB\%curs_getch\fP(3X),
179\fB\%curs_variables\fP(3X),
180\fB\%wresize\fP(3X)