]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/resizeterm.c
ncurses 5.5
[ncurses.git] / ncurses / base / resizeterm.c
index 9cc8081b9115ef48de76a567706d89feb6491978..09ba6007e53381c0f27bb01198e8fbddb115664e 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2002,2004 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
 #include <curses.priv.h>
 #include <term.h>
 
-MODULE_ID("$Id: resizeterm.c,v 1.14 2002/07/13 21:32:57 tom Exp $")
+MODULE_ID("$Id: resizeterm.c,v 1.17 2004/07/31 20:24:38 tom Exp $")
 
 #define stolen_lines (screen_lines - SP->_lines_avail)
 
+static int current_lines;
+static int current_cols;
+
+#ifdef TRACE
+static void
+show_window_sizes(const char *name)
+{
+    WINDOWLIST *wp;
+
+    _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) {
+       _tracef("  window %p is %2d x %2d at %2d,%2d",
+               &(wp->win),
+               wp->win._maxy + 1,
+               wp->win._maxx + 1,
+               wp->win._begy,
+               wp->win._begx);
+    }
+}
+#endif
+
 NCURSES_EXPORT(bool)
 is_term_resized(int ToLines, int ToCols)
 {
-    return (ToLines != screen_lines
-           || ToCols != screen_columns);
+    T((T_CALLED("is_term_resized(%d, %d)"), ToLines, ToCols));
+    returnCode(ToLines > 0
+              && ToCols > 0
+              && (ToLines != screen_lines
+                  || ToCols != screen_columns));
 }
 
 /*
@@ -99,7 +124,7 @@ static int
 adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen)
 {
     int result;
-    int bottom = screen_lines + SP->_topstolen - stolen;
+    int bottom = current_lines + SP->_topstolen - stolen;
     int myLines = win->_maxy + 1;
     int myCols = win->_maxx + 1;
 
@@ -109,13 +134,13 @@ adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen)
        getbegy(win), getbegx(win)));
 
     if (win->_begy >= bottom) {
-       win->_begy += (ToLines - screen_lines);
+       win->_begy += (ToLines - current_lines);
     } else {
-       if (myLines == screen_lines - stolen
-           && ToLines != screen_lines)
+       if (myLines == current_lines - stolen
+           && ToLines != current_lines)
            myLines = ToLines - stolen;
-       else if (myLines == screen_lines
-                && ToLines != screen_lines)
+       else if (myLines == current_lines
+                && ToLines != current_lines)
            myLines = ToLines;
     }
 
@@ -125,12 +150,12 @@ adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen)
     if (myCols > ToCols)
        myCols = ToCols;
 
-    if (myLines == screen_lines
-       && ToLines != screen_lines)
-       myCols = ToLines;
+    if (myLines == current_lines
+       && ToLines != current_lines)
+       myLines = ToLines;
 
-    if (myCols == screen_columns
-       && ToCols != screen_columns)
+    if (myCols == current_cols
+       && ToCols != current_cols)
        myCols = ToCols;
 
     result = wresize(win, myLines, myCols);
@@ -159,6 +184,7 @@ decrease_size(int ToLines, int ToCols, int stolen)
 
            if (!(win->_flags & _ISPAD)) {
                if (child_depth(win) == depth) {
+                   found = TRUE;
                    if (adjust_window(win, ToLines, ToCols, stolen) != OK)
                        returnCode(ERR);
                }
@@ -191,6 +217,7 @@ increase_size(int ToLines, int ToCols, int stolen)
 
            if (!(win->_flags & _ISPAD)) {
                if (parent_depth(win) == depth) {
+                   found = TRUE;
                    if (adjust_window(win, ToLines, ToCols, stolen) != OK)
                        returnCode(ERR);
                }
@@ -216,15 +243,23 @@ resize_term(int ToLines, int ToCols)
        screen_lines, screen_columns));
 
     if (is_term_resized(ToLines, ToCols)) {
-       int myLines = screen_lines;
-       int myCols = screen_columns;
+       int myLines = current_lines = screen_lines;
+       int myCols = current_cols = screen_columns;
 
+#ifdef TRACE
+       if (_nc_tracing & TRACE_UPDATE)
+           show_window_sizes("before");
+#endif
        if (ToLines > screen_lines) {
            increase_size(myLines = ToLines, myCols, was_stolen);
+           current_lines = myLines;
+           current_cols = myCols;
        }
 
        if (ToCols > screen_columns) {
            increase_size(myLines, myCols = ToCols, was_stolen);
+           current_lines = myLines;
+           current_cols = myCols;
        }
 
        if (ToLines < myLines ||
@@ -243,6 +278,13 @@ resize_term(int ToLines, int ToCols)
        if (SP->newhash) {
            FreeAndNull(SP->newhash);
        }
+#ifdef TRACE
+       if (_nc_tracing & TRACE_UPDATE) {
+           LINES = ToLines - was_stolen;
+           COLS = ToCols;
+           show_window_sizes("after");
+       }
+#endif
     }
 
     /*