Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | .\"*************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | .\" Copyright 2018-2023,2024 Thomas E. Dickey * |
| 3 | .\" Copyright 1998-2015,2017 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 | .\" |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 30 | .\" Author: Thomas E. Dickey 1996-on |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 31 | .\" |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 32 | .\" $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 Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 38 | .SH NAME |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 39 | \fB\%is_term_resized\fP, |
| 40 | \fB\%resize_term\fP, |
| 41 | \fB\%resizeterm\fP \- |
| 42 | manage the terminal dimensions understood by \fIcurses\fR |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 43 | .SH SYNOPSIS |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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 |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 51 | .SH DESCRIPTION |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 64 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 65 | If the calling program has not set up a handler for \fB\%SIGWINCH\fP |
| 66 | when it initializes \fI\%ncurses\fP |
| 67 | (e.g., using \fB\%initscr\fP(3X) or \fB\%newterm\fP(3X)), |
| 68 | then \fI\%ncurses\fP sets a handler for \fB\%SIGWINCH\fP which notifies |
| 69 | the library when a window-size event has occurred. |
| 70 | The library checks for this notification |
| 71 | .bP |
| 72 | when reading input data, |
| 73 | .bP |
| 74 | when implicitly resuming program mode |
| 75 | (e.g., between \fB\%endwin\fP(3X) and \fB\%wrefresh\fP(3X)), |
| 76 | and |
| 77 | .bP |
| 78 | when explicitly resuming program mode in \fB\%restartterm\fP(3X). |
| 79 | .PP |
| 80 | When the library has found that the terminal's window-size has |
| 81 | changed, it calls \fB\%resizeterm\fP to update its data structures. |
| 82 | .PP |
| 83 | An application which establishes its own \fB\%SIGWINCH\fP handler |
| 84 | can call \fB\%resizeterm\fP, but in that case, the library will not |
| 85 | see \fB\%SIGWINCH\fP, and proper layout will rely upon the application. |
| 86 | .SH FUNCTIONS |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 87 | .SS resizeterm |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 88 | The function \fB\%resizeterm\fP resizes the standard and current windows |
| 89 | (i.e., \fB\%stdscr\fP and \fB\%curscr\fP) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 90 | to the specified dimensions, and adjusts other bookkeeping data used by |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 91 | the \fI\%ncurses\fP library that record the window dimensions |
| 92 | such as the \fB\%LINES\fP and \fB\%COLS\fP variables. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 93 | .SS resize_term |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 94 | Most of the work for \fB\%resizeterm\fP is |
| 95 | done by the inner function \fB\%resize_term\fP. |
| 96 | The outer function \fB\%resizeterm\fP adds bookkeeping |
| 97 | for the \fB\%SIGWINCH\fP handler, |
| 98 | as well as repainting the soft-key area (see \fB\%slk_touch\fP(3X)). |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 99 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 100 | The \fB\%resize_term\fP function attempts to resize all windows. |
| 101 | This helps with simple applications. |
| 102 | However: |
| 103 | .bP |
| 104 | It is not possible to automatically resize pads. |
| 105 | .bP |
| 106 | Applications which have complicated layouts should check for |
| 107 | \fB\%KEY_RESIZE\fP returned from \fB\%wgetch\fP, |
| 108 | and adjust their layout, e.g., using \fB\%wresize\fP and \fB\%mvwin\fP, |
| 109 | or by recreating the windows. |
| 110 | .PP |
| 111 | When resizing windows, \fB\%resize_term\fP recursively adjusts subwindows, |
| 112 | keeping them within the updated parent window's limits. |
| 113 | If a top-level window happens to extend to the screen's limits, |
| 114 | then on resizing the window, \fB\%resize_term\fP will keep the window |
| 115 | extending to the corresponding limit, regardless of whether the |
| 116 | screen has shrunk or grown. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 117 | .SS is_term_resized |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 118 | A support function \fB\%is_term_resized\fP is provided so that applications |
| 119 | can check if the \fB\%resize_term\fP function would modify |
| 120 | the window structures. |
| 121 | It returns \fBTRUE\fP if the windows would be modified, |
| 122 | and \fBFALSE\fP otherwise. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 123 | .SH RETURN VALUE |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 124 | Except as noted, these functions return |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 125 | the integer \fBERR\fP upon failure and \fBOK\fP on success. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 126 | They will fail if either of the dimensions are less than or equal to zero, |
| 127 | or if an error occurs while (re)allocating memory for the windows. |
| 128 | .SH NOTES |
| 129 | While these functions are intended to be used to support a signal handler |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 130 | (i.e., for \fB\%SIGWINCH\fP), care should be taken to avoid invoking them in a |
| 131 | context where \fB\%malloc\fP or \fB\%realloc\fP may have been interrupted, |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 132 | since it uses those functions. |
| 133 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 134 | If \fI\%ncurses\fP is configured to supply its own \fB\%SIGWINCH\fP |
| 135 | handler, |
| 136 | .bP |
| 137 | on receipt of a \fB\%SIGWINCH\fP, the handler sets a flag |
| 138 | .bP |
| 139 | which is tested in |
| 140 | \fB\%wgetch\fP(3X), |
| 141 | \fB\%doupdate\fP(3X) and |
| 142 | \fB\%restartterm\fP(3X), |
| 143 | .bP |
| 144 | in turn, calling the \fB\%resizeterm\fP function, |
| 145 | .bP |
| 146 | which \fB\%ungetch\fP's a \fB\%KEY_RESIZE\fP which |
| 147 | will be read on the next call to \fB\%wgetch\fP. |
| 148 | .IP |
| 149 | The \fB\%KEY_RESIZE\fP alerts an application that the screen size has changed, |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 150 | and that it should repaint special features such as pads that cannot |
| 151 | be done automatically. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 152 | .IP |
| 153 | Calling \fB\%resizeterm\fP or \fB\%resize_term\fP |
| 154 | directly from a signal handler is unsafe. |
| 155 | This indirect method is used to provide a safe way to resize the |
| 156 | \fI\%ncurses\fP data structures. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 157 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 158 | If the environment variables \fILINES\fP or \fI\%COLUMNS\fP are set, |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 159 | this overrides the library's use of the window size obtained from |
| 160 | the operating system. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 161 | Thus, even if a \fB\%SIGWINCH\fP is received, |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 162 | no screen size change may be recorded. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 163 | .SH PORTABILITY |
| 164 | It is possible to resize the screen with SVr4 \fIcurses\fP, |
| 165 | by |
| 166 | .bP |
| 167 | exiting \fIcurses\fP with \fB\%endwin\fP(3X) and |
| 168 | .bP |
| 169 | resuming using \fB\%refresh\fP(3X). |
| 170 | .PP |
| 171 | Doing that clears the screen and is visually distracting. |
| 172 | .PP |
| 173 | This extension of \fI\%ncurses\fP was introduced in mid-1995. |
| 174 | It was adopted in NetBSD \fIcurses\fP (2001) and PDCurses (2003). |
| 175 | .SH AUTHORS |
| 176 | Thomas Dickey (from an equivalent function written in 1988 for BSD \fIcurses\fP) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 177 | .SH SEE ALSO |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 178 | \fB\%curs_getch\fP(3X), |
| 179 | \fB\%curs_variables\fP(3X), |
| 180 | \fB\%wresize\fP(3X) |