Deleted Added
full compact
resizeterm.c (174993) resizeterm.c (176187)
1/****************************************************************************
1/****************************************************************************
2 * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
2 * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *

--- 25 unchanged lines hidden (view full) ---

36 * running in an X Window terminal (e.g., xterm). I abstracted this module
37 * from my application library for NCURSES because it must be compiled with
38 * the private data structures -- T.Dickey 1995/7/4.
39 */
40
41#include <curses.priv.h>
42#include <term.h>
43
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *

--- 25 unchanged lines hidden (view full) ---

36 * running in an X Window terminal (e.g., xterm). I abstracted this module
37 * from my application library for NCURSES because it must be compiled with
38 * the private data structures -- T.Dickey 1995/7/4.
39 */
40
41#include <curses.priv.h>
42#include <term.h>
43
44MODULE_ID("$Id: resizeterm.c,v 1.24 2007/12/22 23:20:31 tom Exp $")
44MODULE_ID("$Id: resizeterm.c,v 1.30 2008/01/12 22:26:56 tom Exp $")
45
46#define stolen_lines (screen_lines - SP->_lines_avail)
47
48/*
49 * If we're trying to be reentrant, do not want any local statics.
50 */
51#if USE_REENTRANT
52#define EXTRA_ARGS , CurLines, CurCols

--- 23 unchanged lines hidden (view full) ---

76 (long) wp->win._maxx + 1,
77 (long) wp->win._begy,
78 (long) wp->win._begx);
79 }
80 _nc_unlock_global(windowlist);
81}
82#endif
83
45
46#define stolen_lines (screen_lines - SP->_lines_avail)
47
48/*
49 * If we're trying to be reentrant, do not want any local statics.
50 */
51#if USE_REENTRANT
52#define EXTRA_ARGS , CurLines, CurCols

--- 23 unchanged lines hidden (view full) ---

76 (long) wp->win._maxx + 1,
77 (long) wp->win._begy,
78 (long) wp->win._begx);
79 }
80 _nc_unlock_global(windowlist);
81}
82#endif
83
84/*
85 * Return true if the given dimensions do not match the internal terminal
86 * structure's size.
87 */
84NCURSES_EXPORT(bool)
85is_term_resized(int ToLines, int ToCols)
86{
87 T((T_CALLED("is_term_resized(%d, %d)"), ToLines, ToCols));
88 returnCode(ToLines > 0
89 && ToCols > 0
90 && (ToLines != screen_lines
91 || ToCols != screen_columns));
92}
93
94/*
88NCURSES_EXPORT(bool)
89is_term_resized(int ToLines, int ToCols)
90{
91 T((T_CALLED("is_term_resized(%d, %d)"), ToLines, ToCols));
92 returnCode(ToLines > 0
93 && ToCols > 0
94 && (ToLines != screen_lines
95 || ToCols != screen_columns));
96}
97
98/*
99 */
100static ripoff_t *
101ripped_window(WINDOW *win)
102{
103 ripoff_t *result = 0;
104 ripoff_t *rop;
105
106 if (win != 0) {
107 for (rop = ripoff_stack; (rop - ripoff_stack) < N_RIPS; rop++) {
108 if (rop->win == win && rop->line != 0) {
109 result = rop;
110 break;
111 }
112 }
113 }
114 return result;
115}
116
117/*
118 * Returns the number of lines from the bottom for the beginning of a ripped
119 * off window.
120 */
121static int
122ripped_bottom(WINDOW *win)
123{
124 int result = 0;
125 ripoff_t *rop;
126
127 if (win != 0) {
128 for (rop = ripoff_stack; (rop - ripoff_stack) < N_RIPS; rop++) {
129 if (rop->line < 0) {
130 result -= rop->line;
131 if (rop->win == win) {
132 break;
133 }
134 }
135 }
136 }
137 return result;
138}
139
140/*
95 * Return the number of levels of child-windows under the current window.
96 */
97static int
98child_depth(WINDOW *cmp)
99{
100 int depth = 0;
101
102 if (cmp != 0) {

--- 33 unchanged lines hidden (view full) ---

136 */
137static int
138adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen EXTRA_DCLS)
139{
140 int result;
141 int bottom = CurLines + SP->_topstolen - stolen;
142 int myLines = win->_maxy + 1;
143 int myCols = win->_maxx + 1;
141 * Return the number of levels of child-windows under the current window.
142 */
143static int
144child_depth(WINDOW *cmp)
145{
146 int depth = 0;
147
148 if (cmp != 0) {

--- 33 unchanged lines hidden (view full) ---

182 */
183static int
184adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen EXTRA_DCLS)
185{
186 int result;
187 int bottom = CurLines + SP->_topstolen - stolen;
188 int myLines = win->_maxy + 1;
189 int myCols = win->_maxx + 1;
190 ripoff_t *rop = ripped_window(win);
144
191
145 T((T_CALLED("adjust_window(%p,%d,%d) currently %ldx%ld at %ld,%ld"),
192 T((T_CALLED("adjust_window(%p,%d,%d)%s depth %d/%d currently %ldx%ld at %ld,%ld"),
146 win, ToLines, ToCols,
193 win, ToLines, ToCols,
194 (rop != 0) ? " (rip)" : "",
195 parent_depth(win),
196 child_depth(win),
147 (long) getmaxy(win), (long) getmaxx(win),
197 (long) getmaxy(win), (long) getmaxx(win),
148 (long) getbegy(win), (long) getbegx(win)));
198 (long) getbegy(win) + win->_yoffset, (long) getbegx(win)));
149
199
150 if (win->_begy >= bottom) {
200 if (rop != 0 && rop->line < 0) {
201 /*
202 * If it is a ripped-off window at the bottom of the screen, simply
203 * move it to the same relative position.
204 */
205 win->_begy = ToLines - ripped_bottom(win) - 0 - win->_yoffset;
206 } else if (win->_begy >= bottom) {
207 /*
208 * If it is below the bottom of the new screen, move up by the same
209 * amount that the screen shrank.
210 */
151 win->_begy += (ToLines - CurLines);
152 } else {
211 win->_begy += (ToLines - CurLines);
212 } else {
153 if (myLines == CurLines - stolen
154 && ToLines != CurLines)
213 if (myLines == (CurLines - stolen)
214 && ToLines != CurLines) {
155 myLines = ToLines - stolen;
215 myLines = ToLines - stolen;
156 else if (myLines == CurLines
157 && ToLines != CurLines)
216 } else if (myLines == CurLines
217 && ToLines != CurLines) {
158 myLines = ToLines;
218 myLines = ToLines;
219 }
159 }
160
220 }
221
161 if (myLines > ToLines)
222 if (myLines > ToLines) {
162 myLines = ToLines;
223 myLines = ToLines;
224 }
163
164 if (myCols > ToCols)
165 myCols = ToCols;
166
225
226 if (myCols > ToCols)
227 myCols = ToCols;
228
167 if (myLines == CurLines
168 && ToLines != CurLines)
169 myLines = ToLines;
170
171 if (myCols == CurCols
172 && ToCols != CurCols)
173 myCols = ToCols;
174
175 result = wresize(win, myLines, myCols);
176 returnCode(result);
177}
178

--- 163 unchanged lines hidden (view full) ---

342 ToLines, ToCols,
343 screen_lines, screen_columns));
344
345 if (SP != 0) {
346 result = OK;
347 SP->_sig_winch = FALSE;
348
349 if (is_term_resized(ToLines, ToCols)) {
229 if (myCols == CurCols
230 && ToCols != CurCols)
231 myCols = ToCols;
232
233 result = wresize(win, myLines, myCols);
234 returnCode(result);
235}
236

--- 163 unchanged lines hidden (view full) ---

400 ToLines, ToCols,
401 screen_lines, screen_columns));
402
403 if (SP != 0) {
404 result = OK;
405 SP->_sig_winch = FALSE;
406
407 if (is_term_resized(ToLines, ToCols)) {
408#if USE_SIGWINCH
409 ripoff_t *rop;
410 bool slk_visible = (SP != 0
411 && SP->_slk != 0
412 && !(SP->_slk->hidden));
350
413
414 if (slk_visible) {
415 slk_clear();
416 }
417#endif
418 result = resize_term(ToLines, ToCols);
419
351#if USE_SIGWINCH
352 ungetch(KEY_RESIZE); /* so application can know this */
353 clearok(curscr, TRUE); /* screen contents are unknown */
420#if USE_SIGWINCH
421 ungetch(KEY_RESIZE); /* so application can know this */
422 clearok(curscr, TRUE); /* screen contents are unknown */
354#endif
355
423
356 result = resize_term(ToLines, ToCols);
424 /* ripped-off lines are a special case: if we did not lengthen
425 * them, we haven't moved them either. repaint them, too.
426 *
427 * for the rest - stdscr and other windows - the client has to
428 * decide which to repaint, since without panels, ncurses does
429 * not know which are really on top.
430 */
431 for (rop = ripoff_stack; (rop - ripoff_stack) < N_RIPS; rop++) {
432 if (rop->win != stdscr
433 && rop->win != 0
434 && rop->line < 0) {
435
436 if (rop->hook != _nc_slk_initialize) {
437 touchwin(rop->win);
438 wnoutrefresh(rop->win);
439 }
440 }
441 }
442
443 /* soft-keys are a special case: we _know_ how to repaint them */
444 if (slk_visible) {
445 slk_restore();
446 slk_touch();
447
448 slk_refresh();
449 }
450#endif
357 }
358 }
359
360 returnCode(result);
361}
451 }
452 }
453
454 returnCode(result);
455}