You are not logged in.
Hello, everyone
Can anyone tell me why this ( see below ) code does not produce any visible output ( child window is not moving ) ?
#include <stdlib.h>
#include <stdio.h>
#include <curses.h>
int main(void) {
WINDOW * mainwin, * childwin;
int ch;
/* Set the dimensions and initial
position for our child window */
int width = 23, height = 7;
int rows = 25, cols = 80;
int x = (cols - width) / 2;
int y = (rows - height) / 2;
/* Initialize ncurses */
if ( (mainwin = initscr()) == NULL ) {
fprintf(stderr, "Error initialising ncurses.\n");
exit(EXIT_FAILURE);
}
/* Switch of echoing and enable keypad (for arrow keys) */
noecho();
keypad(mainwin, TRUE);
/* Make our child window, and add
a border and some text to it. */
childwin = subwin(mainwin, height, width, y, x);
box(childwin, 0, 0);
mvwaddstr(childwin, 1, 4, "Move the window");
mvwaddstr(childwin, 2, 2, "with the arrow keys");
mvwaddstr(childwin, 3, 6, "or HOME/END");
mvwaddstr(childwin, 5, 3, "Press 'q' to quit");
refresh();
/* Loop until user hits 'q' to quit */
while ( (ch = getch()) != 'q' ) {
switch ( ch ) {
case KEY_UP:
if ( y > 0 )
--y;
break;
case KEY_DOWN:
if ( y < (rows - height) )
++y;
break;
case KEY_LEFT:
if ( x > 0 )
--x;
break;
case KEY_RIGHT:
if ( x < (cols - width) )
++x;
break;
case KEY_HOME:
x = 0;
y = 0;
break;
case KEY_END:
x = (cols - width);
y = (rows - height);
break;
}
mvwin(childwin, y, x);
}
/* Clean up after ourselves */
delwin(childwin);
delwin(mainwin);
endwin();
refresh();
return EXIT_SUCCESS;
}
-- source paulgriffiths.net
EDIT: It seems that the problem is that it is not picking up arrow keys - if I bind those movements to any other keys everything works. Why ?
Last edited by Simple Boot (2012-06-29 17:39:37)
Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
Offline
Someone asked about this particular example early this year in another forum.
I pointed out that mvwin changed (per bug report) in 2006.
However, no comment was made about the keys.
In a quick check (replacing the mvwin with
move(y,x); printw("%d,%d", y, x);
I can see that the problem is that because the mvwin does not actually move the window (as the old behavior was), there is no visible effect.
For reference:
http://invisible-island.net/ncurses/NEW … #t20120114
+ several improvements to test/movewindow.c (prompted by discussion on
Linux Mint forum):
+ modify movement commands to make them continuous
+ rewrote the test for mvderwin
+ rewrote the test for recursive mvwin
http://invisible-island.net/ncurses/NEW … #t20060218
+ remove 970913 feature for copying subwindows as they are moved in
mvwin() (discussion with Bryan Christ).
http://invisible-island.net/ncurses/NEWS.html#t970913
+ Modified lib_mvwin.c: Disable move of a pad. Implement (costly)
move of subwindows. Fixed update behavior of movements of regular
windows.
Offline
Use wrefresh(childwin) just after mvwin(childwin, y, x);. But the box dox lines do not clean up automatically.
Offline
Use wrefresh(childwin) just after mvwin(childwin, y, x);. But the box dox lines do not clean up automatically.
A look here has a bit about cleaning up the box lines. In fact, that whole tutorial is a really awesome way to learn ncurses.
Last edited by /dev/zero (2012-06-29 02:49:56)
Offline
marxav wrote:Use wrefresh(childwin) just after mvwin(childwin, y, x);. But the box dox lines do not clean up automatically.
A look here has a bit about cleaning up the box lines. In fact, that whole tutorial is a really awesome way to learn ncurses.
Thank you both - everything's fine now
Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
Offline