Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ncurses - trying to understand wgetch()

Tags:

ncurses

I created a single-window menu scheme using ncurses and got it working. When I added a second window, I can no longer get my wgetch call to fire (or so it seems).

Somewhat confusing to me is the function prototype :

int wgetch(WINDOW *win);

which says wgetch somehow depends on the window but I don't get the relationship - how does "the window" matter? If it does, and I have more than one window, which one do I use? Also, https://linux.die.net/man/3/wgetch says "There is just one input queue for all windows." which tells me "the window" is a "don't care".

Can someone explain?

Thanks.

like image 822
mike65535 Avatar asked Sep 15 '25 00:09

mike65535


1 Answers

The window matters because wgetch refreshes the window before reading characters. That's in the wgetch manual page:

If the window is not a pad, and it has been moved or modified since the last call to wrefresh, wrefresh will be called before another character is read.

Each window (including stdscr) may have been altered since the last call to wrefresh. If you make changes in one window without refreshing it, and then call wgetch in another window, the changes to the first window are not automatically displayed. You can use wnoutrefresh to combine refreshes, e.g., using that for the first window and then use the wrefresh done automatically for the second window to refresh both.

like image 140
Thomas Dickey Avatar answered Sep 17 '25 18:09

Thomas Dickey