# HG changeset patch # User Matti Hamalainen # Date 1373152126 -10800 # Node ID 199fd337103559091b0dadc69ed6c500c00accbd # Parent 6d23385c064348d864bb633e2eda9cc8120a9c09 Improve screen update economy by only refreshing when needed. diff -r 6d23385c0643 -r 199fd3371035 ui.c --- 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); }