]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/resizeterm.c
ncurses 5.6 - patch 20071222
[ncurses.git] / ncurses / base / resizeterm.c
index 01b5cb60f28d4d194e39add0667436288001f98c..8bea743a3d22552b0ea39441e6f2c37334291609 100644 (file)
@@ -41,7 +41,7 @@
 #include <curses.priv.h>
 #include <term.h>
 
-MODULE_ID("$Id: resizeterm.c,v 1.21 2007/03/10 23:45:14 tom Exp $")
+MODULE_ID("$Id: resizeterm.c,v 1.24 2007/12/22 23:20:31 tom Exp $")
 
 #define stolen_lines (screen_lines - SP->_lines_avail)
 
@@ -66,6 +66,7 @@ show_window_sizes(const char *name)
 {
     WINDOWLIST *wp;
 
+    _nc_lock_global(windowlist);
     _tracef("%s resizing: %2d x %2d (%2d x %2d)", name, LINES, COLS,
            screen_lines, screen_columns);
     for (wp = _nc_windows; wp != 0; wp = wp->next) {
@@ -76,6 +77,7 @@ show_window_sizes(const char *name)
                (long) wp->win._begy,
                (long) wp->win._begx);
     }
+    _nc_unlock_global(windowlist);
 }
 #endif
 
@@ -250,19 +252,28 @@ NCURSES_EXPORT(int)
 resize_term(int ToLines, int ToCols)
 {
     int result = OK EXTRA_ARGS;
-    int was_stolen = (screen_lines - SP->_lines_avail);
+    int was_stolen;
 
     T((T_CALLED("resize_term(%d,%d) old(%d,%d)"),
        ToLines, ToCols,
        screen_lines, screen_columns));
 
+    if (SP == 0) {
+       returnCode(ERR);
+    }
+
+    _nc_lock_global(windowlist);
+
+    was_stolen = (screen_lines - SP->_lines_avail);
     if (is_term_resized(ToLines, ToCols)) {
        int myLines = CurLines = screen_lines;
        int myCols = CurCols = screen_columns;
 
 #ifdef TRACE
-       if (_nc_tracing & TRACE_UPDATE)
+       if (USE_TRACEF(TRACE_UPDATE)) {
            show_window_sizes("before");
+           _nc_unlock_global(tracef);
+       }
 #endif
        if (ToLines > screen_lines) {
            increase_size(myLines = ToLines, myCols, was_stolen EXTRA_ARGS);
@@ -293,10 +304,11 @@ resize_term(int ToLines, int ToCols)
            FreeAndNull(SP->newhash);
        }
 #ifdef TRACE
-       if (_nc_tracing & TRACE_UPDATE) {
+       if (USE_TRACEF(TRACE_UPDATE)) {
            SET_LINES(ToLines - was_stolen);
            SET_COLS(ToCols);
            show_window_sizes("after");
+           _nc_unlock_global(tracef);
        }
 #endif
     }
@@ -308,6 +320,8 @@ resize_term(int ToLines, int ToCols)
     SET_LINES(ToLines - was_stolen);
     SET_COLS(ToCols);
 
+    _nc_unlock_global(windowlist);
+
     returnCode(result);
 }
 
@@ -322,22 +336,25 @@ resize_term(int ToLines, int ToCols)
 NCURSES_EXPORT(int)
 resizeterm(int ToLines, int ToCols)
 {
-    int result = OK;
-
-    SP->_sig_winch = FALSE;
+    int result = ERR;
 
     T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"),
        ToLines, ToCols,
        screen_lines, screen_columns));
 
-    if (is_term_resized(ToLines, ToCols)) {
+    if (SP != 0) {
+       result = OK;
+       SP->_sig_winch = FALSE;
+
+       if (is_term_resized(ToLines, ToCols)) {
 
 #if USE_SIGWINCH
-       ungetch(KEY_RESIZE);    /* so application can know this */
-       clearok(curscr, TRUE);  /* screen contents are unknown */
+           ungetch(KEY_RESIZE);        /* so application can know this */
+           clearok(curscr, TRUE);      /* screen contents are unknown */
 #endif
 
-       result = resize_term(ToLines, ToCols);
+           result = resize_term(ToLines, ToCols);
+       }
     }
 
     returnCode(result);