changeset 585:199fd3371035

Improve screen update economy by only refreshing when needed.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 07 Jul 2013 02:08:46 +0300
parents 6d23385c0643
children 7c593c9303e8
files ui.c
diffstat 1 files changed, 20 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ui.c	Sun Jul 07 02:08:09 2013 +0300
+++ b/ui.c	Sun Jul 07 02:08:46 2013 +0300
@@ -332,17 +332,24 @@
 void nnwin_update(BOOL force, BOOL mask, nn_editbuf_t *ebuf, char *username, int usercolor)
 {
     int sx, sy;
-    
-    // Save cursor position
-    getyx(stdscr, sy, sx);
+    BOOL changed = FALSE;
 
     // Clear screen if forced or main or editbuf are dirty
     if (force || (currWin != NULL && currWin->dirty) || (ebuf != NULL && ebuf->dirty))
     {
+        // Save cursor position
+        getyx(stdscr, sy, sx);
+
         wattrset(stdscr, A_NORMAL);
         wbkgdset(stdscr, COLOR_PAIR(0));
         werase(stdscr);
         force = TRUE;
+        changed = TRUE;
+    }
+    else
+    {
+        // Save cursor position
+        getyx(stdscr, sy, sx);
     }
     
     // Check if update is forced or if the window is dirty
@@ -351,6 +358,8 @@
         int y, offs;
         qringbuf_t *buf = currWin->data;
 
+        changed = TRUE;
+
         for (y = scrHeight - 4, offs = buf->size - 1 - currWin->pos; offs >= 0 && y > 0; offs--)
         {
             nn_line_t *line = (nn_line_t *) buf->data[offs];
@@ -389,6 +398,7 @@
     }
 
     // Update statusline
+    if (changed || force)
     {
         char tmpStamp[32], tmpStr[128];
         int i;
@@ -428,13 +438,13 @@
                 waddstr(stdscr, tmpStr);
             }
         }
+    
+        // Restore cursor position
+        wmove(stdscr, sy, sx);
     }
-    
-    // Restore cursor position
-    wmove(stdscr, sy, sx);
 
     // Update editbuf if needed
-    if (appCursesInit && ebuf != NULL && (force || ebuf->dirty))
+    if (ebuf != NULL && (force || ebuf->dirty))
     {
         int yoffs = ebuf->pos / scrWidth,
             xoffs = ebuf->pos % scrWidth;
@@ -460,9 +470,11 @@
         }
         wmove(stdscr, scrHeight - 3 + yoffs, xoffs);
 
+        changed = TRUE;
     }
 
-    wrefresh(stdscr);
+    if (changed)
+        wrefresh(stdscr);
 }