ctk-curses: Cleanup + fixes

* Cleanup
* Fix warnings
* Fix indentation
* Only wait 1ms for keyboard timeout
* Hide text cursor
* Pump mouse events just in case
* Add F9 as menu key since F10 is used as menu trigger by Gnome
This commit is contained in:
François Revol 2012-06-23 13:07:19 +02:00
parent db982f7b82
commit 1c5d6a9db7

View file

@ -78,6 +78,7 @@ console_init(void)
{
mmask_t oldmask;
static unsigned char done;
if(done) {
return;
}
@ -87,13 +88,19 @@ console_init(void)
stdouthandle = STDOUT_FILENO;
/* will display an error and exit if the term can't be initialized */
/*setupterm((char *)0, STDOUT_FILENO, (int *)0);*/
/*setupterm((char *)0, STDOUT_FILENO, (int *)0); */
initscr();
start_color();
cbreak();
/* don't echo typed characters */
noecho();
/*nonl();*/
/*nonl(); */
/* hide text cursor, CTK draws its own */
curs_set(0);
intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);
@ -105,14 +112,17 @@ console_init(void)
/* curses color handling is weird... */
{
int bg, fg;
for (fg = 0; fg < 8; fg++)
for (bg = 0; bg < 8; bg++)
for(fg = 0; fg < 8; fg++)
for(bg = 0; bg < 8; bg++)
init_pair(MKPAIR(bg, fg), fg, bg);
}
/* set window title */
putp("\033]0;Contiki\a");
timeout(25);
/* don't block on read, just timeout 1ms */
timeout(1);
signal(SIGINT, ctrlhandler);
atexit(console_exit);
@ -145,8 +155,7 @@ console_resize(void)
screensize(&new_width, &new_height);
if(new_width != width ||
new_height != height) {
if(new_width != width || new_height != height) {
width = new_width;
height = new_height;
return 1;
@ -160,11 +169,12 @@ setcolor(void)
{
int bg, fg;
int attrs;
fg = (color & 0x0F);
bg = (color & 0xF0) >> 4;
attrs = COLOR_PAIR(MKPAIR(bg, fg));
if (reversed)
if(reversed)
attrs |= WA_REVERSE;
attrset(attrs);
}
@ -173,7 +183,9 @@ unsigned char
wherex(void)
{
int x, y;
getyx(stdscr, y, x);
(void)y;
return (unsigned char)x;
}
/*-----------------------------------------------------------------------------------*/
@ -181,7 +193,9 @@ unsigned char
wherey(void)
{
int x, y;
getyx(stdscr, y, x);
(void)x;
return (unsigned char)y;
}
/*-----------------------------------------------------------------------------------*/
@ -194,6 +208,8 @@ clrscr(void)
void
bgcolor(unsigned char c)
{
color = ((c << 4) | (color & 0xF0));
/* Presume this to be one of the first calls. */
console_init();
}
@ -209,6 +225,7 @@ void
screensize(unsigned char *x, unsigned char *y)
{
int mx, my;
getmaxyx(stdscr, my, mx);
*x = (unsigned char)mx;
*y = (unsigned char)my;
@ -225,6 +242,7 @@ void
console_cputc(char c)
{
int ch = c;
/* usually ACS_* don't fit in a char */
switch (c) {
case CH_ULCORNER:
@ -243,7 +261,7 @@ console_cputc(char c)
break;
}
addch(ch);
/*refresh();*/
/*refresh(); */
}
/*-----------------------------------------------------------------------------------*/
void
@ -257,7 +275,7 @@ void
cclear(unsigned char length)
{
hline(' ', length);
/*refresh();*/
/*refresh(); */
}
/*-----------------------------------------------------------------------------------*/
void
@ -326,20 +344,25 @@ console_readkey(int k)
{
ctk_arch_key_t key;
key = (ctk_arch_key_t)k;
/*fprintf(stderr, "key: %d\n", k);*/
key = (ctk_arch_key_t) k;
/*fprintf(stderr, "key: %d\n", k); */
switch (k) {
case KEY_MOUSE:
{
MEVENT event;
if (getmouse(&event) == OK) {
if(getmouse(&event) == OK) {
xpos = event.x;
ypos = event.y;
button = event.bstate & BUTTON1_PRESSED
|| event.bstate & BUTTON1_CLICKED
|| event.bstate & BUTTON1_DOUBLE_CLICKED;
/*fprintf(stderr, "mevent: %d: %d, %d, %d, %x ; %d\n",
event.id, event.x, event.y, event.z, (int)event.bstate, button);*/
/*fprintf(stderr, "mevent: %d: %d, %d, %d, %lx ; %d\n",
event.id, event.x, event.y, event.z, event.bstate, button); */
}
/* just in case */
while(getmouse(&event) == OK) {
/*fprintf(stderr, "pumped mevent\n"); */
}
return;
}
@ -355,6 +378,7 @@ console_readkey(int k)
case KEY_DOWN:
key = CH_CURS_DOWN;
break;
case KEY_F(9): /* Gnome uses F10 as menu trigger now... */
case KEY_F(10):
key = CTK_CONF_MENU_KEY;
break;
@ -397,8 +421,9 @@ static void
console_read(void)
{
int k;
k = getch();
if (k != ERR)
if(k != ERR)
console_readkey(k);
}
/*-----------------------------------------------------------------------------------*/
@ -407,6 +432,7 @@ ctk_arch_getkey(void)
{
console_read();
char k = keys[keys_out++];
available--;
return k;
}