bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

wbkgd() does not refresh Color Pair attribute for all cells of the Windo


From: Dweep Advani
Subject: wbkgd() does not refresh Color Pair attribute for all cells of the Window
Date: Tue, 30 Jun 2020 08:09:36 +0000
User-agent: Microsoft-MacOutlook/16.38.20061401

Summary:

wbkgd() keeps parent window garbled, when a child window, which was overlapping parent window and having different Color Pair attribute, gets closed

 

Description:

When a child window gets closed, which was overlapping a parent window, and a subsequent call to wbkgd() on parent window with original Color Pair does not reset all the cells with that color pair. That leaves the parent window garbled until the entire parent window gets re-rendered by the application. This is a behavior I observed in ncurses 6.1. However, on ncurses-5.7, things work as expected.

 

I looked into some code of ncurses and found that static function wbkgrnd() in ncurses/base/lib_bkgd.c is causing this issue. The commit https://github.com/mirror/ncurses/commit/9d37907c2305ee3dc7b829e98a465c3def2074f0#diff-ca68190e8e79f85594b5ee0e6f8b32eeR148 has the change where the attribute settings for the blank and non-blank characters of a window are short circuited in the below pasted code –

 

ncurses/base/lib_bkgd.c

148  if (!memcmp(&old_bkgd, &new_bkgd, sizeof(new_bkgd))) {

149      T(("...unchanged"));

150      returnCode(OK);

151  }

 

Without the above short circuiting, the attributes for all the cells would have been set in the nested for loops in the same function wbkgrnd(), which is called by wbkgd().

 

Removing the above short circuiting code fixes the garbled window issue.

 

I have written a test code, which works fine in ncurses-5.7, but, has the garbled window issue on ncurses-6.1. The $TERM had always been xterm-256color. I am pasting the test code below –

 

/*------------------------------------------ subWinTest.c ------------------------------*/

#include <ncurses.h>

#include <locale.h>

#include <time.h>

 

void sleepForNanoSecs(time_t sec, long nsec)

{

  struct timespec req = {0, 0}, rem = {0, 0};

  int rc = -1;

  rem.tv_sec = req.tv_sec = sec;

  rem.tv_nsec = req.tv_nsec = nsec;

  while ( rc != 0 && (rem.tv_sec > 0 || rem.tv_nsec > 0 ) ) {

    rc = nanosleep( &req, &rem);

  }

}

 

void showMsgInStatusLine(WINDOW *w, const char *msg)

{

  int y, x;

  getmaxyx(w, y, x);

  if ( y > 4 ) {

    int r, c;

    getyx(w, r, c);

    wmove(w, y-2, 1);

    wclrtoeol(w);

    wprintw(w, "%s", msg);

    wmove(w, r, c);

    wrefresh(w);

  }

}

 

void makeBoxAndWriteMessage(WINDOW *w, chtype cp, const char* msg, int isBordered)

{

  wbkgd(w, cp);

  werase(w);

  if ( isBordered ) {

    wborder(w, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE, 0, 0, 0, 0);

  }

  mvwprintw(w, 1, 1, msg);

  wrefresh(w); 

}

 

int main(void)

{

  WINDOW  *w1;

  initscr();

  noecho();

  setlocale (LC_ALL, "");

  start_color();

  init_pair(1, COLOR_BLUE, COLOR_WHITE);

  init_pair(2, COLOR_RED, COLOR_YELLOW);

  init_pair(3, COLOR_CYAN, COLOR_RED);

  init_pair(32767, COLOR_BLACK, COLOR_BLACK);

  makeBoxAndWriteMessage(stdscr, COLOR_PAIR(1), longname(), 1);

  showMsgInStatusLine(stdscr, "Creating child window");

  sleepForNanoSecs(1, 0);

  w1 = subwin(stdscr, 5, 40, (LINES - 5)/2, (COLS - 40)/2);

  makeBoxAndWriteMessage(w1, COLOR_PAIR(3), "changing to color pair 3", 1);

  sleepForNanoSecs(1, 0);

  showMsgInStatusLine(stdscr, "Erashing child window");

  werase(w1);

  sleepForNanoSecs(1, 0);

  showMsgInStatusLine(stdscr, "Deleting child window");

  delwin(w1);

  touchwin(stdscr);

  wbkgd(stdscr, COLOR_PAIR(1));

  showMsgInStatusLine(stdscr, "Setting background color to color pair 1");

  wrefresh(stdscr);

  sleepForNanoSecs(1, 0);

  showMsgInStatusLine(stdscr, "Press any key to exit");

  wrefresh(stdscr);

  getch();

  endwin();

  return 0;

}

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]