From 1f3e745f526629522593c82a81a2abc1ab0df365 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 25 May 2006 19:58:21 +0000 Subject: [PATCH] * Minor cosmetic changes in the test programs. * Code enhancements in the ncurses driver. * Added a comment to explain why slang has a higher priority than ncurses. --- caca/caca.c | 2 + caca/driver_ncurses.c | 166 ++++++++++-------------------------------- test/colors.c | 2 +- test/input.c | 2 +- 4 files changed, 42 insertions(+), 130 deletions(-) diff --git a/caca/caca.c b/caca/caca.c index d0d411b..631314e 100644 --- a/caca/caca.c +++ b/caca/caca.c @@ -161,6 +161,8 @@ static int caca_init_driver(caca_display_t *dp) #if defined(USE_GL) if(gl_install(dp) == 0) return 0; #endif + /* slang has a higher priority than ncurses because though ncurses handles + * color a bit better across terminals, its UTF-8 supports seems broken. */ #if defined(USE_SLANG) if(slang_install(dp) == 0) return 0; #endif diff --git a/caca/driver_ncurses.c b/caca/driver_ncurses.c index 6155885..096d451 100644 --- a/caca/driver_ncurses.c +++ b/caca/driver_ncurses.c @@ -255,136 +255,44 @@ static int ncurses_get_event(caca_display_t *dp, caca_event_t *ev) switch(mevent.bstate) { - case BUTTON1_PRESSED: - ev->data.mouse.button = 1; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - break; - case BUTTON1_RELEASED: - ev->data.mouse.button = 1; - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON1_CLICKED: - ev->data.mouse.button = 1; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON1_DOUBLE_CLICKED: - ev->data.mouse.button = 1; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON1_TRIPLE_CLICKED: - ev->data.mouse.button = 1; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON1_RESERVED_EVENT: - break; - - case BUTTON2_PRESSED: - ev->data.mouse.button = 2; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - break; - case BUTTON2_RELEASED: - ev->data.mouse.button = 2; - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON2_CLICKED: - ev->data.mouse.button = 2; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON2_DOUBLE_CLICKED: - ev->data.mouse.button = 2; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON2_TRIPLE_CLICKED: - ev->data.mouse.button = 2; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON2_RESERVED_EVENT: - break; - - case BUTTON3_PRESSED: - ev->data.mouse.button = 3; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - break; - case BUTTON3_RELEASED: - ev->data.mouse.button = 3; - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON3_CLICKED: - ev->data.mouse.button = 3; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON3_DOUBLE_CLICKED: - ev->data.mouse.button = 3; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON3_TRIPLE_CLICKED: - ev->data.mouse.button = 3; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON3_RESERVED_EVENT: - break; - - case BUTTON4_PRESSED: - ev->data.mouse.button = 4; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - break; - case BUTTON4_RELEASED: - ev->data.mouse.button = 4; - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON4_CLICKED: - ev->data.mouse.button = 4; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON4_DOUBLE_CLICKED: - ev->data.mouse.button = 4; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON4_TRIPLE_CLICKED: - ev->data.mouse.button = 4; - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); - ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); - break; - case BUTTON4_RESERVED_EVENT: - break; +#define PRESS(x) ev->data.mouse.button = x; \ + ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev) +#define RELEASE(x) ev->data.mouse.button = x; \ + ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev) +#define CLICK(x) PRESS(x); RELEASE(x) + case BUTTON1_PRESSED: PRESS(1); break; + case BUTTON1_RELEASED: RELEASE(1); break; + case BUTTON1_CLICKED: CLICK(1); break; + case BUTTON1_DOUBLE_CLICKED: CLICK(1); CLICK(1); break; + case BUTTON1_TRIPLE_CLICKED: CLICK(1); CLICK(1); CLICK(1); break; + case BUTTON1_RESERVED_EVENT: break; + + case BUTTON2_PRESSED: PRESS(2); break; + case BUTTON2_RELEASED: RELEASE(2); break; + case BUTTON2_CLICKED: CLICK(2); break; + case BUTTON2_DOUBLE_CLICKED: CLICK(2); CLICK(2); break; + case BUTTON2_TRIPLE_CLICKED: CLICK(2); CLICK(2); CLICK(2); break; + case BUTTON2_RESERVED_EVENT: break; + + case BUTTON3_PRESSED: PRESS(3); break; + case BUTTON3_RELEASED: RELEASE(3); break; + case BUTTON3_CLICKED: CLICK(3); break; + case BUTTON3_DOUBLE_CLICKED: CLICK(3); CLICK(3); break; + case BUTTON3_TRIPLE_CLICKED: CLICK(3); CLICK(3); CLICK(3); break; + case BUTTON3_RESERVED_EVENT: break; + + case BUTTON4_PRESSED: PRESS(4); break; + case BUTTON4_RELEASED: RELEASE(4); break; + case BUTTON4_CLICKED: CLICK(4); break; + case BUTTON4_DOUBLE_CLICKED: CLICK(4); CLICK(4); break; + case BUTTON4_TRIPLE_CLICKED: CLICK(4); CLICK(4); CLICK(4); break; + case BUTTON4_RESERVED_EVENT: break; default: break; +#undef PRESS +#undef RELEASE +#undef CLICK } if(dp->mouse.x == (unsigned int)mevent.x && @@ -429,7 +337,9 @@ static int ncurses_get_event(caca_display_t *dp, caca_event_t *ev) case KEY_F(11): ev->data.key.ch = CACA_KEY_F11; break; case KEY_F(12): ev->data.key.ch = CACA_KEY_F12; break; - default: ev->type = CACA_EVENT_NONE; return 0; + default: + /* Unknown key */ + ev->type = CACA_EVENT_NONE; return 0; } ev->type = CACA_EVENT_KEY_PRESS; diff --git a/test/colors.c b/test/colors.c index 7bff1f6..05c75fa 100644 --- a/test/colors.c +++ b/test/colors.c @@ -46,7 +46,7 @@ int main(int argc, char **argv) { cucul_set_color(cv, i, j); cucul_putstr(cv, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), - "# "); + "Aa"); } } diff --git a/test/input.c b/test/input.c index f4fdcfb..0795eae 100644 --- a/test/input.c +++ b/test/input.c @@ -74,7 +74,7 @@ int main(void) } /* Put the cursor on the active textentry */ - cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_WHITE); + cucul_set_color(cv, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_LIGHTRED); cucul_putchar(cv, 2 + entries[e].cursor, 3 * e + 4, ' '); caca_refresh_display(dp);