@@ -74,9 +74,9 @@ caca_t * caca_attach(cucul_t * qq) | |||||
kk->events.key_timer.last_usec = 0; | kk->events.key_timer.last_usec = 0; | ||||
kk->events.last_key_ticks = 0; | kk->events.last_key_ticks = 0; | ||||
kk->events.autorepeat_ticks = 0; | kk->events.autorepeat_ticks = 0; | ||||
kk->events.last_key = 0; | kk->events.last_key_event.type = CACA_EVENT_NONE; | ||||
#endif | #endif | ||||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) | #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) | ||||
kk->events.queue = 0; | kk->events.queue = 0; | ||||
#endif | #endif | ||||
@@ -113,16 +113,29 @@ extern "C" | |||||
* | * | ||||
* Event types returned by caca_get_event(). | * Event types returned by caca_get_event(). | ||||
*/ | */ | ||||
enum caca_event | enum caca_event_type | ||||
{ | { | ||||
CACA_EVENT_NONE = 0x00000000, /**< No event. */ | CACA_EVENT_NONE = 0x0000, /**< No event. */ | ||||
CACA_EVENT_KEY_PRESS = 0x01000000, /**< A key was pressed. */ | CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */ | ||||
CACA_EVENT_KEY_RELEASE = 0x02000000, /**< A key was released. */ | CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */ | ||||
CACA_EVENT_MOUSE_PRESS = 0x04000000, /**< A mouse button was pressed. */ | CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */ | ||||
CACA_EVENT_MOUSE_RELEASE = 0x08000000, /**< A mouse button was released. */ | CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */ | ||||
CACA_EVENT_MOUSE_MOTION = 0x10000000, /**< The mouse was moved. */ | CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */ | ||||
CACA_EVENT_RESIZE = 0x20000000, /**< The window was resized. */ | CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */ | ||||
CACA_EVENT_ANY = 0xff000000 /**< Bitmask for any event. */ | CACA_EVENT_ANY = 0xffff /**< Bitmask for any event. */ | ||||
}; | |||||
struct caca_event | |||||
{ | |||||
enum caca_event_type type; | |||||
union | |||||
{ | |||||
struct { unsigned int x, y, button; } mouse; | |||||
struct { unsigned int w, h; } resize; | |||||
struct { unsigned int c; unsigned long int ucs4; char utf8[8]; } key; | |||||
} data; | |||||
}; | }; | ||||
/** \brief Special key values. | /** \brief Special key values. | ||||
@@ -196,8 +209,8 @@ int caca_set_window_title(caca_t *kk, char const *); | |||||
* clicks. | * clicks. | ||||
* | * | ||||
* @{ */ | * @{ */ | ||||
unsigned int caca_get_event(caca_t *kk, unsigned int); | int caca_get_event(caca_t *kk, unsigned int, struct caca_event *); | ||||
unsigned int caca_wait_event(caca_t *kk, unsigned int); | int caca_wait_event(caca_t *kk, unsigned int, struct caca_event *); | ||||
unsigned int caca_get_mouse_x(caca_t *kk); | unsigned int caca_get_mouse_x(caca_t *kk); | ||||
unsigned int caca_get_mouse_y(caca_t *kk); | unsigned int caca_get_mouse_y(caca_t *kk); | ||||
/* @} */ | /* @} */ | ||||
@@ -115,7 +115,7 @@ struct caca_context | |||||
unsigned int (* get_window_height) (caca_t *); | unsigned int (* get_window_height) (caca_t *); | ||||
void (* display) (caca_t *); | void (* display) (caca_t *); | ||||
void (* handle_resize) (caca_t *); | void (* handle_resize) (caca_t *); | ||||
unsigned int (* get_event) (caca_t *); | int (* get_event) (caca_t *, struct caca_event *); | ||||
} drv; | } drv; | ||||
/* Mouse position */ | /* Mouse position */ | ||||
@@ -139,15 +139,15 @@ struct caca_context | |||||
struct events | struct events | ||||
{ | { | ||||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) | #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) | ||||
unsigned int buf[EVENTBUF_LEN]; | struct caca_event buf[EVENTBUF_LEN]; | ||||
int queue; | int queue; | ||||
#endif | #endif | ||||
#if defined(USE_SLANG) || defined(USE_NCURSES) | #if defined(USE_SLANG) || defined(USE_NCURSES) | ||||
struct caca_timer key_timer; | struct caca_timer key_timer; | ||||
unsigned int last_key_ticks; | unsigned int last_key_ticks; | ||||
unsigned int autorepeat_ticks; | unsigned int autorepeat_ticks; | ||||
unsigned int last_key; | struct caca_event last_key_event; | ||||
#endif | #endif | ||||
} events; | } events; | ||||
}; | }; | ||||
@@ -158,9 +158,9 @@ extern unsigned int _caca_getticks(struct caca_timer *); | |||||
/* Internal event functions */ | /* Internal event functions */ | ||||
extern void _caca_handle_resize(caca_t *); | extern void _caca_handle_resize(caca_t *); | ||||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) | #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) | ||||
extern void _push_event(caca_t *, unsigned int); | extern void _push_event(caca_t *, struct caca_event *); | ||||
extern unsigned int _pop_event(caca_t *); | extern int _pop_event(caca_t *, struct caca_event *); | ||||
#endif | #endif | ||||
#endif /* __CACA_INTERNALS_H__ */ | #endif /* __CACA_INTERNALS_H__ */ |
@@ -121,16 +121,30 @@ static void conio_handle_resize(caca_t *kk) | |||||
kk->resize.h = kk->qq->height; | kk->resize.h = kk->qq->height; | ||||
} | } | ||||
static unsigned int conio_get_event(caca_t *kk) | static int conio_get_event(caca_t *kk, struct caca_event *ev) | ||||
{ | { | ||||
unsigned int event; | unsigned char ch; | ||||
struct caca_event release; | |||||
if(!_conio_kbhit()) | if(!_conio_kbhit()) | ||||
return CACA_EVENT_NONE; | { | ||||
ev->type = CACA_EVENT_NONE; | |||||
return 0; | |||||
} | |||||
ch = getch(); | |||||
ev->type = CACA_EVENT_KEY_PRESS; | |||||
ev->data.key.c = ch; | |||||
ev->data.key.ucs4 = (uint32_t)ch; | |||||
ev->data.key.utf8[0] = ch; | |||||
ev->data.key.utf8[1] = '\0'; | |||||
release = *ev; | |||||
release.type = CACA_EVENT_KEY_RELEASE; | |||||
_push_event(kk, &release); | |||||
event = getch(); | return 1; | ||||
_push_event(kk, CACA_EVENT_KEY_RELEASE | event); | |||||
return CACA_EVENT_KEY_PRESS | event; | |||||
} | } | ||||
/* | /* | ||||
@@ -308,62 +308,80 @@ static void gl_handle_resize(caca_t *kk) | |||||
glMatrixMode(GL_MODELVIEW); | glMatrixMode(GL_MODELVIEW); | ||||
} | } | ||||
static unsigned int gl_get_event(caca_t *kk) | static int gl_get_event(caca_t *kk, struct caca_event *ev) | ||||
{ | { | ||||
unsigned int event = 0; | |||||
glutMainLoopEvent(); | glutMainLoopEvent(); | ||||
if(kk->resize.resized) | if(kk->resize.resized) | ||||
return CACA_EVENT_RESIZE; | { | ||||
ev->type = CACA_EVENT_RESIZE; | |||||
ev->data.resize.w = kk->qq->width; | |||||
ev->data.resize.h = kk->qq->height; | |||||
return 1; | |||||
} | |||||
if(kk->drv.p->mouse_changed) | if(kk->drv.p->mouse_changed) | ||||
{ | { | ||||
ev->type = CACA_EVENT_MOUSE_MOTION; | |||||
ev->data.mouse.x = kk->mouse.x; | |||||
ev->data.mouse.y = kk->mouse.y; | |||||
kk->drv.p->mouse_changed = 0; | |||||
if(kk->drv.p->mouse_clicked) | if(kk->drv.p->mouse_clicked) | ||||
{ | { | ||||
event |= CACA_EVENT_MOUSE_PRESS | kk->drv.p->mouse_button; | _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_PRESS; | |||||
ev->data.mouse.button = kk->drv.p->mouse_button; | |||||
kk->drv.p->mouse_clicked = 0; | kk->drv.p->mouse_clicked = 0; | ||||
} | } | ||||
kk->mouse.x = kk->drv.p->mouse_x; | return 1; | ||||
kk->mouse.y = kk->drv.p->mouse_y; | |||||
event |= CACA_EVENT_MOUSE_MOTION | (kk->mouse.x << 12) | kk->mouse.y; | |||||
kk->drv.p->mouse_changed = 0; | |||||
} | } | ||||
if(kk->drv.p->key != 0) | if(kk->drv.p->key != 0) | ||||
{ | { | ||||
event |= CACA_EVENT_KEY_PRESS; | ev->type = CACA_EVENT_KEY_PRESS; | ||||
event |= kk->drv.p->key; | ev->data.key.c = kk->drv.p->key; | ||||
ev->data.key.ucs4 = (uint32_t)kk->drv.p->key; | |||||
ev->data.key.utf8[0] = kk->drv.p->key; | |||||
ev->data.key.utf8[1] = '\0'; | |||||
kk->drv.p->key = 0; | kk->drv.p->key = 0; | ||||
return event; | return 1; | ||||
} | } | ||||
if(kk->drv.p->special_key != 0) | if(kk->drv.p->special_key != 0) | ||||
{ | { | ||||
event |= CACA_EVENT_KEY_PRESS; | |||||
switch(kk->drv.p->special_key) | switch(kk->drv.p->special_key) | ||||
{ | { | ||||
case GLUT_KEY_F1 : kk->drv.p->special_key = 0; return event | CACA_KEY_F1; | case GLUT_KEY_F1 : ev->data.key.c = CACA_KEY_F1; break; | ||||
case GLUT_KEY_F2 : kk->drv.p->special_key = 0; return event | CACA_KEY_F2; | case GLUT_KEY_F2 : ev->data.key.c = CACA_KEY_F2; break; | ||||
case GLUT_KEY_F3 : kk->drv.p->special_key = 0; return event | CACA_KEY_F3; | case GLUT_KEY_F3 : ev->data.key.c = CACA_KEY_F3; break; | ||||
case GLUT_KEY_F4 : kk->drv.p->special_key = 0; return event | CACA_KEY_F4; | case GLUT_KEY_F4 : ev->data.key.c = CACA_KEY_F4; break; | ||||
case GLUT_KEY_F5 : kk->drv.p->special_key = 0; return event | CACA_KEY_F5; | case GLUT_KEY_F5 : ev->data.key.c = CACA_KEY_F5; break; | ||||
case GLUT_KEY_F6 : kk->drv.p->special_key = 0; return event | CACA_KEY_F6; | case GLUT_KEY_F6 : ev->data.key.c = CACA_KEY_F6; break; | ||||
case GLUT_KEY_F7 : kk->drv.p->special_key = 0; return event | CACA_KEY_F7; | case GLUT_KEY_F7 : ev->data.key.c = CACA_KEY_F7; break; | ||||
case GLUT_KEY_F8 : kk->drv.p->special_key = 0; return event | CACA_KEY_F8; | case GLUT_KEY_F8 : ev->data.key.c = CACA_KEY_F8; break; | ||||
case GLUT_KEY_F9 : kk->drv.p->special_key = 0; return event | CACA_KEY_F9; | case GLUT_KEY_F9 : ev->data.key.c = CACA_KEY_F9; break; | ||||
case GLUT_KEY_F10: kk->drv.p->special_key = 0; return event | CACA_KEY_F10; | case GLUT_KEY_F10: ev->data.key.c = CACA_KEY_F10; break; | ||||
case GLUT_KEY_F11: kk->drv.p->special_key = 0; return event | CACA_KEY_F11; | case GLUT_KEY_F11: ev->data.key.c = CACA_KEY_F11; break; | ||||
case GLUT_KEY_F12: kk->drv.p->special_key = 0; return event | CACA_KEY_F12; | case GLUT_KEY_F12: ev->data.key.c = CACA_KEY_F12; break; | ||||
case GLUT_KEY_LEFT : kk->drv.p->special_key = 0; return event | CACA_KEY_LEFT; | case GLUT_KEY_LEFT : ev->data.key.c = CACA_KEY_LEFT; break; | ||||
case GLUT_KEY_RIGHT: kk->drv.p->special_key = 0; return event | CACA_KEY_RIGHT; | case GLUT_KEY_RIGHT: ev->data.key.c = CACA_KEY_RIGHT; break; | ||||
case GLUT_KEY_UP : kk->drv.p->special_key = 0; return event | CACA_KEY_UP; | case GLUT_KEY_UP : ev->data.key.c = CACA_KEY_UP; break; | ||||
case GLUT_KEY_DOWN : kk->drv.p->special_key = 0; return event | CACA_KEY_DOWN; | case GLUT_KEY_DOWN : ev->data.key.c = CACA_KEY_DOWN; break; | ||||
default: return CACA_EVENT_NONE; | default: ev->type = CACA_EVENT_NONE; return 0; | ||||
} | } | ||||
ev->type = CACA_EVENT_KEY_PRESS; | |||||
ev->data.key.ucs4 = 0; | |||||
ev->data.key.utf8[0] = '\0'; | |||||
kk->drv.p->special_key = 0; | |||||
return 1; | |||||
} | } | ||||
return CACA_EVENT_NONE; | ev->type = CACA_EVENT_NONE; | ||||
return 0; | |||||
} | } | ||||
/* | /* | ||||
@@ -226,18 +226,22 @@ static void ncurses_handle_resize(caca_t *kk) | |||||
kk->resize.h = kk->qq->height; | kk->resize.h = kk->qq->height; | ||||
} | } | ||||
static unsigned int ncurses_get_event(caca_t *kk) | static int ncurses_get_event(caca_t *kk, struct caca_event *ev) | ||||
{ | { | ||||
unsigned int event; | |||||
int intkey; | int intkey; | ||||
intkey = getch(); | intkey = getch(); | ||||
if(intkey == ERR) | if(intkey == ERR) | ||||
return CACA_EVENT_NONE; | { | ||||
ev->type = CACA_EVENT_NONE; | |||||
return 0; | |||||
} | |||||
if(intkey < 0x100) | if(intkey < 0x100) | ||||
{ | { | ||||
return CACA_EVENT_KEY_PRESS | intkey; | ev->type = CACA_EVENT_KEY_PRESS; | ||||
ev->data.key.c = intkey; | |||||
return 1; | |||||
} | } | ||||
if(intkey == KEY_MOUSE) | if(intkey == KEY_MOUSE) | ||||
@@ -248,109 +252,129 @@ static unsigned int ncurses_get_event(caca_t *kk) | |||||
switch(mevent.bstate) | switch(mevent.bstate) | ||||
{ | { | ||||
case BUTTON1_PRESSED: | case BUTTON1_PRESSED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | ev->data.mouse.button = 1; | ||||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON1_RELEASED: | case BUTTON1_RELEASED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | ev->data.mouse.button = 1; | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON1_CLICKED: | case BUTTON1_CLICKED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | ev->data.mouse.button = 1; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON1_DOUBLE_CLICKED: | case BUTTON1_DOUBLE_CLICKED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | ev->data.mouse.button = 1; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON1_TRIPLE_CLICKED: | case BUTTON1_TRIPLE_CLICKED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | ev->data.mouse.button = 1; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON1_RESERVED_EVENT: | case BUTTON1_RESERVED_EVENT: | ||||
break; | break; | ||||
case BUTTON2_PRESSED: | case BUTTON2_PRESSED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | ev->data.mouse.button = 2; | ||||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON2_RELEASED: | case BUTTON2_RELEASED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | ev->data.mouse.button = 2; | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON2_CLICKED: | case BUTTON2_CLICKED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | ev->data.mouse.button = 2; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON2_DOUBLE_CLICKED: | case BUTTON2_DOUBLE_CLICKED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | ev->data.mouse.button = 2; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON2_TRIPLE_CLICKED: | case BUTTON2_TRIPLE_CLICKED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | ev->data.mouse.button = 2; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON2_RESERVED_EVENT: | case BUTTON2_RESERVED_EVENT: | ||||
break; | break; | ||||
case BUTTON3_PRESSED: | case BUTTON3_PRESSED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | ev->data.mouse.button = 3; | ||||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON3_RELEASED: | case BUTTON3_RELEASED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | ev->data.mouse.button = 3; | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON3_CLICKED: | case BUTTON3_CLICKED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | ev->data.mouse.button = 3; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON3_DOUBLE_CLICKED: | case BUTTON3_DOUBLE_CLICKED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | ev->data.mouse.button = 3; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON3_TRIPLE_CLICKED: | case BUTTON3_TRIPLE_CLICKED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | ev->data.mouse.button = 3; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON3_RESERVED_EVENT: | case BUTTON3_RESERVED_EVENT: | ||||
break; | break; | ||||
case BUTTON4_PRESSED: | case BUTTON4_PRESSED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | ev->data.mouse.button = 4; | ||||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON4_RELEASED: | case BUTTON4_RELEASED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | ev->data.mouse.button = 4; | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON4_CLICKED: | case BUTTON4_CLICKED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | ev->data.mouse.button = 4; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON4_DOUBLE_CLICKED: | case BUTTON4_DOUBLE_CLICKED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | ev->data.mouse.button = 4; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON4_TRIPLE_CLICKED: | case BUTTON4_TRIPLE_CLICKED: | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | ev->data.mouse.button = 4; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | ||||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||||
break; | break; | ||||
case BUTTON4_RESERVED_EVENT: | case BUTTON4_RESERVED_EVENT: | ||||
break; | break; | ||||
@@ -361,45 +385,51 @@ static unsigned int ncurses_get_event(caca_t *kk) | |||||
if(kk->mouse.x == (unsigned int)mevent.x && | if(kk->mouse.x == (unsigned int)mevent.x && | ||||
kk->mouse.y == (unsigned int)mevent.y) | kk->mouse.y == (unsigned int)mevent.y) | ||||
return _pop_event(kk); | return _pop_event(kk, ev); | ||||
kk->mouse.x = mevent.x; | kk->mouse.x = mevent.x; | ||||
kk->mouse.y = mevent.y; | kk->mouse.y = mevent.y; | ||||
return CACA_EVENT_MOUSE_MOTION | (kk->mouse.x << 12) | kk->mouse.y; | ev->type = CACA_EVENT_MOUSE_MOTION; | ||||
ev->data.mouse.x = kk->mouse.x; | |||||
ev->data.mouse.y = kk->mouse.y; | |||||
return 1; | |||||
} | } | ||||
event = CACA_EVENT_KEY_PRESS; | |||||
switch(intkey) | switch(intkey) | ||||
{ | { | ||||
case KEY_UP: return event | CACA_KEY_UP; | case KEY_UP: ev->data.key.c = CACA_KEY_UP; break; | ||||
case KEY_DOWN: return event | CACA_KEY_DOWN; | case KEY_DOWN: ev->data.key.c = CACA_KEY_DOWN; break; | ||||
case KEY_LEFT: return event | CACA_KEY_LEFT; | case KEY_LEFT: ev->data.key.c = CACA_KEY_LEFT; break; | ||||
case KEY_RIGHT: return event | CACA_KEY_RIGHT; | case KEY_RIGHT: ev->data.key.c = CACA_KEY_RIGHT; break; | ||||
case KEY_IC: ev->data.key.c = CACA_KEY_INSERT; break; | |||||
case KEY_IC: return event | CACA_KEY_INSERT; | case KEY_DC: ev->data.key.c = CACA_KEY_DELETE; break; | ||||
case KEY_DC: return event | CACA_KEY_DELETE; | case KEY_HOME: ev->data.key.c = CACA_KEY_HOME; break; | ||||
case KEY_HOME: return event | CACA_KEY_HOME; | case KEY_END: ev->data.key.c = CACA_KEY_END; break; | ||||
case KEY_END: return event | CACA_KEY_END; | case KEY_PPAGE: ev->data.key.c = CACA_KEY_PAGEUP; break; | ||||
case KEY_PPAGE: return event | CACA_KEY_PAGEUP; | case KEY_NPAGE: ev->data.key.c = CACA_KEY_PAGEDOWN; break; | ||||
case KEY_NPAGE: return event | CACA_KEY_PAGEDOWN; | case KEY_F(1): ev->data.key.c = CACA_KEY_F1; break; | ||||
case KEY_F(2): ev->data.key.c = CACA_KEY_F2; break; | |||||
case KEY_F(1): return event | CACA_KEY_F1; | case KEY_F(3): ev->data.key.c = CACA_KEY_F3; break; | ||||
case KEY_F(2): return event | CACA_KEY_F2; | case KEY_F(4): ev->data.key.c = CACA_KEY_F4; break; | ||||
case KEY_F(3): return event | CACA_KEY_F3; | case KEY_F(5): ev->data.key.c = CACA_KEY_F5; break; | ||||
case KEY_F(4): return event | CACA_KEY_F4; | case KEY_F(6): ev->data.key.c = CACA_KEY_F6; break; | ||||
case KEY_F(5): return event | CACA_KEY_F5; | case KEY_F(7): ev->data.key.c = CACA_KEY_F7; break; | ||||
case KEY_F(6): return event | CACA_KEY_F6; | case KEY_F(8): ev->data.key.c = CACA_KEY_F8; break; | ||||
case KEY_F(7): return event | CACA_KEY_F7; | case KEY_F(9): ev->data.key.c = CACA_KEY_F9; break; | ||||
case KEY_F(8): return event | CACA_KEY_F8; | case KEY_F(10): ev->data.key.c = CACA_KEY_F10; break; | ||||
case KEY_F(9): return event | CACA_KEY_F9; | case KEY_F(11): ev->data.key.c = CACA_KEY_F11; break; | ||||
case KEY_F(10): return event | CACA_KEY_F10; | case KEY_F(12): ev->data.key.c = CACA_KEY_F12; break; | ||||
case KEY_F(11): return event | CACA_KEY_F11; | default: ev->type = CACA_EVENT_NONE; return 0; | ||||
case KEY_F(12): return event | CACA_KEY_F12; | |||||
} | } | ||||
return CACA_EVENT_NONE; | ev->type = CACA_EVENT_KEY_PRESS; | ||||
ev->data.key.ucs4 = 0; | |||||
ev->data.key.utf8[0] = '\0'; | |||||
return 1; | |||||
} | } | ||||
/* | /* | ||||
@@ -283,7 +283,7 @@ static void network_handle_resize(caca_t *kk) | |||||
/* Not handled */ | /* Not handled */ | ||||
} | } | ||||
static unsigned int network_get_event(caca_t *kk) | static int network_get_event(caca_t *kk, struct caca_event *ev) | ||||
{ | { | ||||
/* Manage new connections as this function will be called sometimes | /* Manage new connections as this function will be called sometimes | ||||
* more often than display */ | * more often than display */ | ||||
@@ -254,13 +254,15 @@ static void slang_handle_resize(caca_t *kk) | |||||
SLsmg_reinit_smg(); | SLsmg_reinit_smg(); | ||||
} | } | ||||
static unsigned int slang_get_event(caca_t *kk) | static int slang_get_event(caca_t *kk, struct caca_event *ev) | ||||
{ | { | ||||
unsigned int event; | |||||
int intkey; | int intkey; | ||||
if(!SLang_input_pending(0)) | if(!SLang_input_pending(0)) | ||||
return CACA_EVENT_NONE; | { | ||||
ev->type = CACA_EVENT_NONE; | |||||
return 0; | |||||
} | |||||
/* We first use SLang_getkey() to see whether Esc was pressed | /* We first use SLang_getkey() to see whether Esc was pressed | ||||
* alone, then (if it wasn't) we unget the key and use SLkp_getkey() | * alone, then (if it wasn't) we unget the key and use SLkp_getkey() | ||||
@@ -276,7 +278,9 @@ static unsigned int slang_get_event(caca_t *kk) | |||||
/* If the key was ASCII, return it immediately */ | /* If the key was ASCII, return it immediately */ | ||||
if(intkey < 0x100) | if(intkey < 0x100) | ||||
{ | { | ||||
return CACA_EVENT_KEY_PRESS | intkey; | ev->type = CACA_EVENT_KEY_PRESS; | ||||
ev->data.key.c = intkey; | |||||
return 1; | |||||
} | } | ||||
if(intkey == 0x3e9) | if(intkey == 0x3e9) | ||||
@@ -284,49 +288,59 @@ static unsigned int slang_get_event(caca_t *kk) | |||||
int button = (SLang_getkey() - ' ' + 1) & 0xf; | int button = (SLang_getkey() - ' ' + 1) & 0xf; | ||||
unsigned int x = SLang_getkey() - '!'; | unsigned int x = SLang_getkey() - '!'; | ||||
unsigned int y = SLang_getkey() - '!'; | unsigned int y = SLang_getkey() - '!'; | ||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | button); | ev->data.mouse.button = button; | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | button); | ev->type = CACA_EVENT_MOUSE_PRESS; | ||||
_push_event(kk, ev); | |||||
ev->type = CACA_EVENT_MOUSE_RELEASE; | |||||
_push_event(kk, ev); | |||||
if(kk->mouse.x == x && kk->mouse.y == y) | if(kk->mouse.x == x && kk->mouse.y == y) | ||||
return _pop_event(kk); | return _pop_event(kk, ev); | ||||
kk->mouse.x = x; | kk->mouse.x = x; | ||||
kk->mouse.y = y; | kk->mouse.y = y; | ||||
return CACA_EVENT_MOUSE_MOTION | (kk->mouse.x << 12) | kk->mouse.y; | ev->type = CACA_EVENT_MOUSE_MOTION; | ||||
ev->data.mouse.x = kk->mouse.x; | |||||
ev->data.mouse.y = kk->mouse.y; | |||||
return 1; | |||||
} | } | ||||
event = CACA_EVENT_KEY_PRESS; | |||||
switch(intkey) | switch(intkey) | ||||
{ | { | ||||
case SL_KEY_UP: return event | CACA_KEY_UP; | case SL_KEY_UP: ev->data.key.c = CACA_KEY_UP; break; | ||||
case SL_KEY_DOWN: return event | CACA_KEY_DOWN; | case SL_KEY_DOWN: ev->data.key.c = CACA_KEY_DOWN; break; | ||||
case SL_KEY_LEFT: return event | CACA_KEY_LEFT; | case SL_KEY_LEFT: ev->data.key.c = CACA_KEY_LEFT; break; | ||||
case SL_KEY_RIGHT: return event | CACA_KEY_RIGHT; | case SL_KEY_RIGHT: ev->data.key.c = CACA_KEY_RIGHT; break; | ||||
case SL_KEY_IC: ev->data.key.c = CACA_KEY_INSERT; break; | |||||
case SL_KEY_IC: return event | CACA_KEY_INSERT; | case SL_KEY_DELETE: ev->data.key.c = CACA_KEY_DELETE; break; | ||||
case SL_KEY_DELETE: return event | CACA_KEY_DELETE; | case SL_KEY_HOME: ev->data.key.c = CACA_KEY_HOME; break; | ||||
case SL_KEY_HOME: return event | CACA_KEY_HOME; | case SL_KEY_END: ev->data.key.c = CACA_KEY_END; break; | ||||
case SL_KEY_END: return event | CACA_KEY_END; | case SL_KEY_PPAGE: ev->data.key.c = CACA_KEY_PAGEUP; break; | ||||
case SL_KEY_PPAGE: return event | CACA_KEY_PAGEUP; | case SL_KEY_NPAGE: ev->data.key.c = CACA_KEY_PAGEDOWN; break; | ||||
case SL_KEY_NPAGE: return event | CACA_KEY_PAGEDOWN; | case SL_KEY_F(1): ev->data.key.c = CACA_KEY_F1; break; | ||||
case SL_KEY_F(2): ev->data.key.c = CACA_KEY_F2; break; | |||||
case SL_KEY_F(1): return event | CACA_KEY_F1; | case SL_KEY_F(3): ev->data.key.c = CACA_KEY_F3; break; | ||||
case SL_KEY_F(2): return event | CACA_KEY_F2; | case SL_KEY_F(4): ev->data.key.c = CACA_KEY_F4; break; | ||||
case SL_KEY_F(3): return event | CACA_KEY_F3; | case SL_KEY_F(5): ev->data.key.c = CACA_KEY_F5; break; | ||||
case SL_KEY_F(4): return event | CACA_KEY_F4; | case SL_KEY_F(6): ev->data.key.c = CACA_KEY_F6; break; | ||||
case SL_KEY_F(5): return event | CACA_KEY_F5; | case SL_KEY_F(7): ev->data.key.c = CACA_KEY_F7; break; | ||||
case SL_KEY_F(6): return event | CACA_KEY_F6; | case SL_KEY_F(8): ev->data.key.c = CACA_KEY_F8; break; | ||||
case SL_KEY_F(7): return event | CACA_KEY_F7; | case SL_KEY_F(9): ev->data.key.c = CACA_KEY_F9; break; | ||||
case SL_KEY_F(8): return event | CACA_KEY_F8; | case SL_KEY_F(10): ev->data.key.c = CACA_KEY_F10; break; | ||||
case SL_KEY_F(9): return event | CACA_KEY_F9; | case SL_KEY_F(11): ev->data.key.c = CACA_KEY_F11; break; | ||||
case SL_KEY_F(10): return event | CACA_KEY_F10; | case SL_KEY_F(12): ev->data.key.c = CACA_KEY_F12; break; | ||||
case SL_KEY_F(11): return event | CACA_KEY_F11; | default: ev->type = CACA_EVENT_NONE; return 0; | ||||
case SL_KEY_F(12): return event | CACA_KEY_F12; | |||||
} | } | ||||
return CACA_EVENT_NONE; | ev->type = CACA_EVENT_KEY_PRESS; | ||||
ev->data.key.ucs4 = 0; | |||||
ev->data.key.utf8[0] = '\0'; | |||||
return 1; | |||||
} | } | ||||
/* | /* | ||||
@@ -134,10 +134,11 @@ static void vga_handle_resize(caca_t *kk) | |||||
kk->resize.h = kk->qq->height; | kk->resize.h = kk->qq->height; | ||||
} | } | ||||
static unsigned int vga_get_event(caca_t *kk) | static int vga_get_event(caca_t *kk, struct caca_event *ev) | ||||
{ | { | ||||
/* FIXME */ | /* FIXME */ | ||||
return CACA_EVENT_NONE; | ev->type = CACA_EVENT_NONE; | ||||
return 0; | |||||
} | } | ||||
/* | /* | ||||
@@ -235,7 +235,7 @@ static void win32_handle_resize(caca_t *kk) | |||||
kk->resize.h = kk->qq->height; | kk->resize.h = kk->qq->height; | ||||
} | } | ||||
static unsigned int win32_get_event(caca_t *kk) | static int win32_get_event(caca_t *kk, struct caca_event *ev) | ||||
{ | { | ||||
INPUT_RECORD rec; | INPUT_RECORD rec; | ||||
DWORD num; | DWORD num; | ||||
@@ -252,12 +252,19 @@ static unsigned int win32_get_event(caca_t *kk) | |||||
unsigned int event; | unsigned int event; | ||||
if(rec.Event.KeyEvent.bKeyDown) | if(rec.Event.KeyEvent.bKeyDown) | ||||
event = CACA_EVENT_KEY_PRESS; | ev->type = CACA_EVENT_KEY_PRESS; | ||||
else | else | ||||
event = CACA_EVENT_KEY_RELEASE; | ev->type = CACA_EVENT_KEY_RELEASE; | ||||
if(rec.Event.KeyEvent.uChar.AsciiChar) | if(rec.Event.KeyEvent.uChar.AsciiChar) | ||||
return event | rec.Event.KeyEvent.uChar.AsciiChar; | { | ||||
ev->data.key.c = rec.Event.KeyEvent.uChar.AsciiChar; | |||||
ev->data.key.ucs4 = (uint32_t)ev->data.key.c; | |||||
ev->data.key.utf8[0] = ev->data.key.c; | |||||
ev->data.key.utf8[1] = '\0'; | |||||
return 1; | |||||
} | |||||
} | } | ||||
if(rec.EventType == MOUSE_EVENT) | if(rec.EventType == MOUSE_EVENT) | ||||
@@ -265,10 +272,18 @@ static unsigned int win32_get_event(caca_t *kk) | |||||
if(rec.Event.MouseEvent.dwEventFlags == 0) | if(rec.Event.MouseEvent.dwEventFlags == 0) | ||||
{ | { | ||||
if(rec.Event.MouseEvent.dwButtonState & 0x01) | if(rec.Event.MouseEvent.dwButtonState & 0x01) | ||||
return CACA_EVENT_MOUSE_PRESS | 0x000001; | { | ||||
ev->type = CACA_EVENT_MOUSE_PRESS; | |||||
ev->data.mouse.button = 1; | |||||
return 1; | |||||
} | |||||
if(rec.Event.MouseEvent.dwButtonState & 0x02) | if(rec.Event.MouseEvent.dwButtonState & 0x02) | ||||
return CACA_EVENT_MOUSE_PRESS | 0x000002; | { | ||||
ev->type = CACA_EVENT_MOUSE_PRESS; | |||||
ev->data.mouse.button = 2; | |||||
return 1; | |||||
} | |||||
} | } | ||||
else if(rec.Event.MouseEvent.dwEventFlags == MOUSE_MOVED) | else if(rec.Event.MouseEvent.dwEventFlags == MOUSE_MOVED) | ||||
{ | { | ||||
@@ -281,8 +296,10 @@ static unsigned int win32_get_event(caca_t *kk) | |||||
kk->mouse.x = pos.X; | kk->mouse.x = pos.X; | ||||
kk->mouse.y = pos.Y; | kk->mouse.y = pos.Y; | ||||
return CACA_EVENT_MOUSE_MOTION | ev->type = CACA_EVENT_MOUSE_MOTION; | ||||
| (kk->mouse.x << 12) | kk->mouse.y; | ev->data.mouse.x = kk->mouse.x; | ||||
ev->data.mouse.y = kk->mouse.y; | |||||
return 1; | |||||
} | } | ||||
#if 0 | #if 0 | ||||
else if(rec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK) | else if(rec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK) | ||||
@@ -303,11 +320,13 @@ static unsigned int win32_get_event(caca_t *kk) | |||||
} | } | ||||
/* Unknown event */ | /* Unknown event */ | ||||
return CACA_EVENT_NONE; | ev->type = CACA_EVENT_NONE; | ||||
return 0; | |||||
} | } | ||||
/* No event */ | /* No event */ | ||||
return CACA_EVENT_NONE; | ev->type = CACA_EVENT_NONE; | ||||
return 0; | |||||
} | } | ||||
/* | /* | ||||
@@ -399,9 +399,8 @@ static void x11_handle_resize(caca_t *kk) | |||||
kk->drv.p->pixmap = new_pixmap; | kk->drv.p->pixmap = new_pixmap; | ||||
} | } | ||||
static unsigned int x11_get_event(caca_t *kk) | static int x11_get_event(caca_t *kk, struct caca_event *ev) | ||||
{ | { | ||||
unsigned int event = 0; | |||||
XEvent xevent; | XEvent xevent; | ||||
char key; | char key; | ||||
@@ -457,56 +456,77 @@ static unsigned int x11_get_event(caca_t *kk) | |||||
kk->mouse.x = newx; | kk->mouse.x = newx; | ||||
kk->mouse.y = newy; | kk->mouse.y = newy; | ||||
return CACA_EVENT_MOUSE_MOTION | (kk->mouse.x << 12) | kk->mouse.y; | ev->type = CACA_EVENT_MOUSE_MOTION; | ||||
ev->data.mouse.x = kk->mouse.x; | |||||
ev->data.mouse.y = kk->mouse.y; | |||||
return 1; | |||||
} | } | ||||
/* Check for mouse press and release events */ | /* Check for mouse press and release events */ | ||||
if(xevent.type == ButtonPress) | if(xevent.type == ButtonPress) | ||||
return CACA_EVENT_MOUSE_PRESS | { | ||||
| ((XButtonEvent *)&xevent)->button; | ev->type = CACA_EVENT_MOUSE_PRESS; | ||||
ev->data.mouse.button = ((XButtonEvent *)&xevent)->button; | |||||
return 1; | |||||
} | |||||
if(xevent.type == ButtonRelease) | if(xevent.type == ButtonRelease) | ||||
return CACA_EVENT_MOUSE_RELEASE | { | ||||
| ((XButtonEvent *)&xevent)->button; | ev->type = CACA_EVENT_MOUSE_RELEASE; | ||||
ev->data.mouse.button = ((XButtonEvent *)&xevent)->button; | |||||
return 1; | |||||
} | |||||
/* Check for key press and release events */ | /* Check for key press and release events */ | ||||
if(xevent.type == KeyPress) | if(xevent.type == KeyPress) | ||||
event |= CACA_EVENT_KEY_PRESS; | ev->type = CACA_EVENT_KEY_PRESS; | ||||
else if(xevent.type == KeyRelease) | else if(xevent.type == KeyRelease) | ||||
event |= CACA_EVENT_KEY_RELEASE; | ev->type = CACA_EVENT_KEY_RELEASE; | ||||
else | else | ||||
continue; | continue; | ||||
if(XLookupString(&xevent.xkey, &key, 1, NULL, NULL)) | if(XLookupString(&xevent.xkey, &key, 1, NULL, NULL)) | ||||
return event | key; | { | ||||
ev->data.key.c = key; | |||||
ev->data.key.ucs4 = key; | |||||
ev->data.key.utf8[0] = key; | |||||
ev->data.key.utf8[1] = '\0'; | |||||
return 1; | |||||
} | |||||
keysym = XKeycodeToKeysym(kk->drv.p->dpy, xevent.xkey.keycode, 0); | keysym = XKeycodeToKeysym(kk->drv.p->dpy, xevent.xkey.keycode, 0); | ||||
switch(keysym) | switch(keysym) | ||||
{ | { | ||||
case XK_F1: return event | CACA_KEY_F1; | case XK_F1: ev->data.key.c = CACA_KEY_F1; break; | ||||
case XK_F2: return event | CACA_KEY_F2; | case XK_F2: ev->data.key.c = CACA_KEY_F2; break; | ||||
case XK_F3: return event | CACA_KEY_F3; | case XK_F3: ev->data.key.c = CACA_KEY_F3; break; | ||||
case XK_F4: return event | CACA_KEY_F4; | case XK_F4: ev->data.key.c = CACA_KEY_F4; break; | ||||
case XK_F5: return event | CACA_KEY_F5; | case XK_F5: ev->data.key.c = CACA_KEY_F5; break; | ||||
case XK_F6: return event | CACA_KEY_F6; | case XK_F6: ev->data.key.c = CACA_KEY_F6; break; | ||||
case XK_F7: return event | CACA_KEY_F7; | case XK_F7: ev->data.key.c = CACA_KEY_F7; break; | ||||
case XK_F8: return event | CACA_KEY_F8; | case XK_F8: ev->data.key.c = CACA_KEY_F8; break; | ||||
case XK_F9: return event | CACA_KEY_F9; | case XK_F9: ev->data.key.c = CACA_KEY_F9; break; | ||||
case XK_F10: return event | CACA_KEY_F10; | case XK_F10: ev->data.key.c = CACA_KEY_F10; break; | ||||
case XK_F11: return event | CACA_KEY_F11; | case XK_F11: ev->data.key.c = CACA_KEY_F11; break; | ||||
case XK_F12: return event | CACA_KEY_F12; | case XK_F12: ev->data.key.c = CACA_KEY_F12; break; | ||||
case XK_F13: return event | CACA_KEY_F13; | case XK_F13: ev->data.key.c = CACA_KEY_F13; break; | ||||
case XK_F14: return event | CACA_KEY_F14; | case XK_F14: ev->data.key.c = CACA_KEY_F14; break; | ||||
case XK_F15: return event | CACA_KEY_F15; | case XK_F15: ev->data.key.c = CACA_KEY_F15; break; | ||||
case XK_Left: return event | CACA_KEY_LEFT; | case XK_Left: ev->data.key.c = CACA_KEY_LEFT; break; | ||||
case XK_Right: return event | CACA_KEY_RIGHT; | case XK_Right: ev->data.key.c = CACA_KEY_RIGHT; break; | ||||
case XK_Up: return event | CACA_KEY_UP; | case XK_Up: ev->data.key.c = CACA_KEY_UP; break; | ||||
case XK_Down: return event | CACA_KEY_DOWN; | case XK_Down: ev->data.key.c = CACA_KEY_DOWN; break; | ||||
default: return CACA_EVENT_NONE; | default: ev->type = CACA_EVENT_NONE; return 0; | ||||
} | } | ||||
ev->data.key.ucs4 = 0; | |||||
ev->data.key.utf8[0] = '\0'; | |||||
return 1; | |||||
} | } | ||||
return CACA_EVENT_NONE; | ev->type = CACA_EVENT_NONE; | ||||
return 0; | |||||
} | } | ||||
/* | /* | ||||
@@ -19,13 +19,17 @@ | |||||
#include "config.h" | #include "config.h" | ||||
#if !defined(__KERNEL__) | |||||
# include <stdio.h> | |||||
#endif | |||||
#include "cucul.h" | #include "cucul.h" | ||||
#include "cucul_internals.h" | #include "cucul_internals.h" | ||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
static unsigned int _get_next_event(caca_t *); | static int _get_next_event(caca_t *, struct caca_event *); | ||||
static unsigned int _lowlevel_event(caca_t *); | static int _lowlevel_event(caca_t *, struct caca_event *); | ||||
#if !defined(_DOXYGEN_SKIP_ME) | #if !defined(_DOXYGEN_SKIP_ME) | ||||
/* If no new key was pressed after AUTOREPEAT_THRESHOLD usec, assume the | /* If no new key was pressed after AUTOREPEAT_THRESHOLD usec, assume the | ||||
@@ -48,17 +52,17 @@ static unsigned int _lowlevel_event(caca_t *); | |||||
* \param event_mask Bitmask of requested events. | * \param event_mask Bitmask of requested events. | ||||
* \return The next matching event in the queue, or 0 if no event is pending. | * \return The next matching event in the queue, or 0 if no event is pending. | ||||
*/ | */ | ||||
unsigned int caca_get_event(caca_t *kk, unsigned int event_mask) | int caca_get_event(caca_t *kk, unsigned int event_mask, struct caca_event *ev) | ||||
{ | { | ||||
if(!event_mask) | if(!event_mask) | ||||
return CACA_EVENT_NONE; | return 0; | ||||
for( ; ; ) | for( ; ; ) | ||||
{ | { | ||||
unsigned int event = _get_next_event(kk); | int ret = _get_next_event(kk, ev); | ||||
if(!event || event & event_mask) | if(!ret || ev->type & event_mask) | ||||
return event; | return ret; | ||||
} | } | ||||
} | } | ||||
@@ -72,17 +76,17 @@ unsigned int caca_get_event(caca_t *kk, unsigned int event_mask) | |||||
* \param event_mask Bitmask of requested events. | * \param event_mask Bitmask of requested events. | ||||
* \return The next event in the queue. | * \return The next event in the queue. | ||||
*/ | */ | ||||
unsigned int caca_wait_event(caca_t *kk, unsigned int event_mask) | int caca_wait_event(caca_t *kk, unsigned int event_mask, struct caca_event *ev) | ||||
{ | { | ||||
if(!event_mask) | if(!event_mask) | ||||
return CACA_EVENT_NONE; | return 0; | ||||
for( ; ; ) | for( ; ; ) | ||||
{ | { | ||||
unsigned int event = _get_next_event(kk); | int ret = _get_next_event(kk, ev); | ||||
if(event & event_mask) | if(ret && (ev->type & event_mask)) | ||||
return event; | return ret; | ||||
_caca_sleep(10000); | _caca_sleep(10000); | ||||
} | } | ||||
@@ -126,22 +130,25 @@ unsigned int caca_get_mouse_y(caca_t *kk) | |||||
* XXX: The following functions are local. | * XXX: The following functions are local. | ||||
*/ | */ | ||||
static unsigned int _get_next_event(caca_t *kk) | static int _get_next_event(caca_t *kk, struct caca_event *ev) | ||||
{ | { | ||||
#if defined(USE_SLANG) || defined(USE_NCURSES) | #if defined(USE_SLANG) || defined(USE_NCURSES) | ||||
unsigned int ticks; | unsigned int ticks; | ||||
#endif | #endif | ||||
unsigned int event; | int ret; | ||||
/* If we are about to return a resize event, acknowledge it */ | /* If we are about to return a resize event, acknowledge it */ | ||||
if(kk->resize.resized) | if(kk->resize.resized) | ||||
{ | { | ||||
kk->resize.resized = 0; | kk->resize.resized = 0; | ||||
_caca_handle_resize(kk); | _caca_handle_resize(kk); | ||||
return CACA_EVENT_RESIZE; | ev->type = CACA_EVENT_RESIZE; | ||||
ev->data.resize.w = kk->qq->width; | |||||
ev->data.resize.h = kk->qq->height; | |||||
return 1; | |||||
} | } | ||||
event = _lowlevel_event(kk); | ret = _lowlevel_event(kk, ev); | ||||
#if defined(USE_SLANG) | #if defined(USE_SLANG) | ||||
if(kk->drv.driver != CACA_DRIVER_SLANG) | if(kk->drv.driver != CACA_DRIVER_SLANG) | ||||
@@ -149,7 +156,7 @@ static unsigned int _get_next_event(caca_t *kk) | |||||
#if defined(USE_NCURSES) | #if defined(USE_NCURSES) | ||||
if(kk->drv.driver != CACA_DRIVER_NCURSES) | if(kk->drv.driver != CACA_DRIVER_NCURSES) | ||||
#endif | #endif | ||||
return event; | return ret; | ||||
#if defined(USE_SLANG) || defined(USE_NCURSES) | #if defined(USE_SLANG) || defined(USE_NCURSES) | ||||
/* Simulate long keypresses using autorepeat features */ | /* Simulate long keypresses using autorepeat features */ | ||||
@@ -158,83 +165,87 @@ static unsigned int _get_next_event(caca_t *kk) | |||||
kk->events.autorepeat_ticks += ticks; | kk->events.autorepeat_ticks += ticks; | ||||
/* Handle autorepeat */ | /* Handle autorepeat */ | ||||
if(kk->events.last_key | if(kk->events.last_key_event.type | ||||
&& kk->events.autorepeat_ticks > AUTOREPEAT_TRIGGER | && kk->events.autorepeat_ticks > AUTOREPEAT_TRIGGER | ||||
&& kk->events.autorepeat_ticks > AUTOREPEAT_THRESHOLD | && kk->events.autorepeat_ticks > AUTOREPEAT_THRESHOLD | ||||
&& kk->events.autorepeat_ticks > AUTOREPEAT_RATE) | && kk->events.autorepeat_ticks > AUTOREPEAT_RATE) | ||||
{ | { | ||||
_push_event(kk, event); | _push_event(kk, ev); | ||||
kk->events.autorepeat_ticks -= AUTOREPEAT_RATE; | kk->events.autorepeat_ticks -= AUTOREPEAT_RATE; | ||||
return CACA_EVENT_KEY_PRESS | kk->events.last_key; | *ev = kk->events.last_key_event; | ||||
return 1; | |||||
} | } | ||||
/* We are in autorepeat mode and the same key was just pressed, ignore | /* We are in autorepeat mode and the same key was just pressed, ignore | ||||
* this event and return the next one by calling ourselves. */ | * this event and return the next one by calling ourselves. */ | ||||
if(event == (CACA_EVENT_KEY_PRESS | kk->events.last_key)) | if(ev->type == CACA_EVENT_KEY_PRESS | ||||
&& kk->events.last_key_event.type | |||||
&& ev->data.key.c == kk->events.last_key_event.data.key.c | |||||
&& ev->data.key.ucs4 == kk->events.last_key_event.data.key.ucs4) | |||||
{ | { | ||||
kk->events.last_key_ticks = 0; | kk->events.last_key_ticks = 0; | ||||
return _get_next_event(kk); | return _get_next_event(kk, ev); | ||||
} | } | ||||
/* We are in autorepeat mode, but key has expired or a new key was | /* We are in autorepeat mode, but key has expired or a new key was | ||||
* pressed - store our event and return a key release event first */ | * pressed - store our event and return a key release event first */ | ||||
if(kk->events.last_key | if(kk->events.last_key_event.type | ||||
&& (kk->events.last_key_ticks > AUTOREPEAT_THRESHOLD | && (kk->events.last_key_ticks > AUTOREPEAT_THRESHOLD | ||||
|| (event & CACA_EVENT_KEY_PRESS))) | || (ev->type & CACA_EVENT_KEY_PRESS))) | ||||
{ | { | ||||
_push_event(kk, event); | _push_event(kk, ev); | ||||
event = CACA_EVENT_KEY_RELEASE | kk->events.last_key; | *ev = kk->events.last_key_event; | ||||
kk->events.last_key = 0; | ev->type = CACA_EVENT_KEY_RELEASE; | ||||
return event; | kk->events.last_key_event.type = CACA_EVENT_NONE; | ||||
return 1; | |||||
} | } | ||||
/* A new key was pressed, enter autorepeat mode */ | /* A new key was pressed, enter autorepeat mode */ | ||||
if(event & CACA_EVENT_KEY_PRESS) | if(ev->type & CACA_EVENT_KEY_PRESS) | ||||
{ | { | ||||
kk->events.last_key_ticks = 0; | kk->events.last_key_ticks = 0; | ||||
kk->events.autorepeat_ticks = 0; | kk->events.autorepeat_ticks = 0; | ||||
kk->events.last_key = event & 0x00ffffff; | kk->events.last_key_event = *ev; | ||||
} | } | ||||
return event; | return ev->type ? 1 : 0; | ||||
#endif | #endif | ||||
} | } | ||||
static unsigned int _lowlevel_event(caca_t *kk) | static int _lowlevel_event(caca_t *kk, struct caca_event *ev) | ||||
{ | { | ||||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) | #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) | ||||
unsigned int event = _pop_event(kk); | int ret = _pop_event(kk, ev); | ||||
if(event) | if(ret) | ||||
return event; | return ret; | ||||
#endif | #endif | ||||
return kk->drv.get_event(kk); | return kk->drv.get_event(kk, ev); | ||||
} | } | ||||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) | #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) | ||||
void _push_event(caca_t *kk, unsigned int event) | void _push_event(caca_t *kk, struct caca_event *ev) | ||||
{ | { | ||||
if(!event || kk->events.queue == EVENTBUF_LEN) | if(!ev->type || kk->events.queue == EVENTBUF_LEN) | ||||
return; | return; | ||||
kk->events.buf[kk->events.queue] = event; | kk->events.buf[kk->events.queue] = *ev; | ||||
kk->events.queue++; | kk->events.queue++; | ||||
} | } | ||||
unsigned int _pop_event(caca_t *kk) | int _pop_event(caca_t *kk, struct caca_event *ev) | ||||
{ | { | ||||
int i; | int i; | ||||
unsigned int event; | |||||
if(kk->events.queue == 0) | if(kk->events.queue == 0) | ||||
return CACA_EVENT_NONE; | return 0; | ||||
event = kk->events.buf[0]; | *ev = kk->events.buf[0]; | ||||
for(i = 1; i < kk->events.queue; i++) | for(i = 1; i < kk->events.queue; i++) | ||||
kk->events.buf[i - 1] = kk->events.buf[i]; | kk->events.buf[i - 1] = kk->events.buf[i]; | ||||
kk->events.queue--; | kk->events.queue--; | ||||
return event; | return 1; | ||||
} | } | ||||
#endif | #endif | ||||
@@ -261,12 +261,15 @@ game (void) | |||||
#endif | #endif | ||||
{ | { | ||||
#ifdef LIBCACA | #ifdef LIBCACA | ||||
switch (caca_get_event(kk, CACA_EVENT_KEY_PRESS)) | struct caca_event ev; | ||||
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev)) | |||||
{ | { | ||||
case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: return; | switch(ev.data.key.c) | ||||
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | { | ||||
case CACA_KEY_ESCAPE: return; | |||||
case ' ': pause = !pause; | |||||
} | |||||
} | } | ||||
#endif | #endif | ||||
drawfire (); | drawfire (); | ||||
} | } | ||||
@@ -92,10 +92,14 @@ int main(int argc, char **argv) | |||||
/* Go ! */ | /* Go ! */ | ||||
for(;;) | for(;;) | ||||
{ | { | ||||
switch(caca_get_event(kk, CACA_EVENT_KEY_PRESS)) | struct caca_event ev; | ||||
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev)) | |||||
{ | { | ||||
case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: goto end; | switch(ev.data.key.c) | ||||
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | { | ||||
case CACA_KEY_ESCAPE: goto end; | |||||
case ' ': pause = !pause; | |||||
} | |||||
} | } | ||||
if(pause) | if(pause) | ||||
@@ -68,10 +68,14 @@ int main (int argc, char **argv) | |||||
/* Main loop */ | /* Main loop */ | ||||
for(;;) | for(;;) | ||||
{ | { | ||||
switch(caca_get_event(kk, CACA_EVENT_KEY_PRESS)) | struct caca_event ev; | ||||
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev)) | |||||
{ | { | ||||
case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: goto end; | switch(ev.data.key.c) | ||||
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | { | ||||
case CACA_KEY_ESCAPE: goto end; | |||||
case ' ': pause = !pause; | |||||
} | |||||
} | } | ||||
if(pause) | if(pause) | ||||
@@ -80,10 +80,14 @@ int main (int argc, char **argv) | |||||
/* Main loop */ | /* Main loop */ | ||||
for(;;) | for(;;) | ||||
{ | { | ||||
switch(caca_get_event(kk, CACA_EVENT_KEY_PRESS)) | struct caca_event ev; | ||||
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev)) | |||||
{ | { | ||||
case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: goto end; | switch(ev.data.key.c) | ||||
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | { | ||||
case CACA_KEY_ESCAPE: goto end; | |||||
case ' ': pause = !pause; | |||||
} | |||||
} | } | ||||
if(pause) | if(pause) | ||||
@@ -143,32 +143,34 @@ int main(int argc, char **argv) | |||||
/* Go ! */ | /* Go ! */ | ||||
while(!quit) | while(!quit) | ||||
{ | { | ||||
struct caca_event ev; | |||||
unsigned int const event_mask = CACA_EVENT_KEY_PRESS | unsigned int const event_mask = CACA_EVENT_KEY_PRESS | ||||
| CACA_EVENT_RESIZE | | CACA_EVENT_RESIZE | ||||
| CACA_EVENT_MOUSE_PRESS; | | CACA_EVENT_MOUSE_PRESS; | ||||
unsigned int event, new_status = 0, new_help = 0; | unsigned int new_status = 0, new_help = 0; | ||||
int event; | |||||
if(update) | if(update) | ||||
event = caca_get_event(kk, event_mask); | event = caca_get_event(kk, event_mask, &ev); | ||||
else | else | ||||
event = caca_wait_event(kk, event_mask); | event = caca_wait_event(kk, event_mask, &ev); | ||||
while(event) | while(event) | ||||
{ | { | ||||
if(event & CACA_EVENT_MOUSE_PRESS) | if(ev.type & CACA_EVENT_MOUSE_PRESS) | ||||
{ | { | ||||
if((event & 0x00ffffff) == 1) | if(ev.data.mouse.button == 1) | ||||
{ | { | ||||
if(items) current = (current + 1) % items; | if(items) current = (current + 1) % items; | ||||
reload = 1; | reload = 1; | ||||
} | } | ||||
else if((event & 0x00ffffff) == 2) | else if(ev.data.mouse.button == 2) | ||||
{ | { | ||||
if(items) current = (items + current - 1) % items; | if(items) current = (items + current - 1) % items; | ||||
reload = 1; | reload = 1; | ||||
} | } | ||||
} | } | ||||
else if(event & CACA_EVENT_KEY_PRESS) switch(event & 0x00ffffff) | else if(ev.type & CACA_EVENT_KEY_PRESS) switch(ev.data.key.c) | ||||
{ | { | ||||
case 'n': | case 'n': | ||||
case 'N': | case 'N': | ||||
@@ -287,11 +289,11 @@ int main(int argc, char **argv) | |||||
quit = 1; | quit = 1; | ||||
break; | break; | ||||
} | } | ||||
else if(event == CACA_EVENT_RESIZE) | else if(ev.type == CACA_EVENT_RESIZE) | ||||
{ | { | ||||
caca_display(kk); | caca_display(kk); | ||||
ww = cucul_get_width(qq); | ww = ev.data.resize.w; | ||||
wh = cucul_get_height(qq); | wh = ev.data.resize.h; | ||||
update = 1; | update = 1; | ||||
set_zoom(zoom); | set_zoom(zoom); | ||||
} | } | ||||
@@ -302,7 +304,7 @@ int main(int argc, char **argv) | |||||
if(help || new_help) | if(help || new_help) | ||||
help = new_help; | help = new_help; | ||||
event = caca_get_event(kk, CACA_EVENT_KEY_PRESS); | event = caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev); | ||||
} | } | ||||
if(items && reload) | if(items && reload) | ||||
@@ -24,6 +24,7 @@ int main(int argc, char **argv) | |||||
{ | { | ||||
cucul_t *qq; | cucul_t *qq; | ||||
caca_t *kk; | caca_t *kk; | ||||
struct caca_event ev; | |||||
int i, j; | int i, j; | ||||
qq = cucul_create(0, 0); | qq = cucul_create(0, 0); | ||||
@@ -49,7 +50,7 @@ int main(int argc, char **argv) | |||||
} | } | ||||
caca_display(kk); | caca_display(kk); | ||||
caca_wait_event(kk, CACA_EVENT_KEY_PRESS); | caca_wait_event(kk, CACA_EVENT_KEY_PRESS, &ev); | ||||
caca_detach(kk); | caca_detach(kk); | ||||
cucul_free(qq); | cucul_free(qq); | ||||
@@ -68,19 +68,19 @@ int main(int argc, char **argv) | |||||
/* Go ! */ | /* Go ! */ | ||||
while(!quit) | while(!quit) | ||||
{ | { | ||||
struct caca_event ev; | |||||
int menu = 0, mouse = 0, xmouse = 0, ymouse = 0; | int menu = 0, mouse = 0, xmouse = 0, ymouse = 0; | ||||
int event; | |||||
while((event = caca_get_event(kk, CACA_EVENT_ANY))) | while(caca_get_event(kk, CACA_EVENT_ANY, &ev)) | ||||
{ | { | ||||
if(demo && (event & CACA_EVENT_KEY_PRESS)) | if(demo && (ev.type & CACA_EVENT_KEY_PRESS)) | ||||
{ | { | ||||
menu = 1; | menu = 1; | ||||
demo = NULL; | demo = NULL; | ||||
} | } | ||||
else if(event & CACA_EVENT_KEY_PRESS) | else if(ev.type & CACA_EVENT_KEY_PRESS) | ||||
{ | { | ||||
switch(event & 0xffff) | switch(ev.data.key.c) | ||||
{ | { | ||||
case 'q': | case 'q': | ||||
case 'Q': | case 'Q': | ||||
@@ -139,11 +139,11 @@ int main(int argc, char **argv) | |||||
if(demo) | if(demo) | ||||
cucul_clear(qq); | cucul_clear(qq); | ||||
} | } | ||||
else if(event & CACA_EVENT_MOUSE_MOTION) | else if(ev.type & CACA_EVENT_MOUSE_MOTION) | ||||
{ | { | ||||
mouse = 1; | mouse = 1; | ||||
xmouse = (event & 0xfff000) >> 12; | xmouse = ev.data.mouse.x; | ||||
ymouse = event & 0xfff; | ymouse = ev.data.mouse.y; | ||||
} | } | ||||
} | } | ||||
@@ -34,6 +34,7 @@ char density[] = " -,+:;o&%w$W@#"; | |||||
int main(void) | int main(void) | ||||
{ | { | ||||
struct caca_event ev; | |||||
cucul_t *qq; | cucul_t *qq; | ||||
caca_t *kk; | caca_t *kk; | ||||
int neara, dista, nearb, distb, dist; | int neara, dista, nearb, distb, dist; | ||||
@@ -123,7 +124,7 @@ int main(void) | |||||
caca_display(kk); | caca_display(kk); | ||||
while(!caca_get_event(kk, CACA_EVENT_KEY_PRESS)); | caca_wait_event(kk, CACA_EVENT_KEY_PRESS, &ev); | ||||
caca_detach(kk); | caca_detach(kk); | ||||
cucul_free(qq); | cucul_free(qq); | ||||
@@ -23,11 +23,11 @@ | |||||
static cucul_t *qq; | static cucul_t *qq; | ||||
static caca_t *kk; | static caca_t *kk; | ||||
static void print_event(int, int, unsigned int); | static void print_event(int, int, struct caca_event *); | ||||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||||
{ | { | ||||
int *events; | struct caca_event *events; | ||||
int i, h, quit; | int i, h, quit; | ||||
qq = cucul_create(0, 0); | qq = cucul_create(0, 0); | ||||
@@ -47,23 +47,24 @@ int main(int argc, char **argv) | |||||
caca_display(kk); | caca_display(kk); | ||||
events = malloc(h * sizeof(int)); | events = malloc(h * sizeof(struct caca_event)); | ||||
memset(events, 0, h * sizeof(int)); | memset(events, 0, h * sizeof(struct caca_event)); | ||||
for(quit = 0; quit < 4; ) | for(quit = 0; quit < 4; ) | ||||
{ | { | ||||
struct caca_event ev; | |||||
static char const * quit_string[] = { "", "q", "qu", "qui", "quit" }; | static char const * quit_string[] = { "", "q", "qu", "qui", "quit" }; | ||||
unsigned int event = caca_wait_event(kk, CACA_EVENT_ANY); | int ret = caca_wait_event(kk, CACA_EVENT_ANY, &ev); | ||||
if(!event) | if(!ret) | ||||
continue; | continue; | ||||
do | do | ||||
{ | { | ||||
/* "quit" quits */ | /* "quit" quits */ | ||||
if(event & CACA_EVENT_KEY_PRESS) | if(ev.type & CACA_EVENT_KEY_PRESS) | ||||
{ | { | ||||
int key = event & ~CACA_EVENT_KEY_PRESS; | int key = ev.data.key.c; | ||||
if((key == 'q' && quit == 0) || (key == 'u' && quit == 1) | if((key == 'q' && quit == 0) || (key == 'u' && quit == 1) | ||||
|| (key == 'i' && quit == 2) || (key == 't' && quit == 3)) | || (key == 'i' && quit == 2) || (key == 't' && quit == 3)) | ||||
quit++; | quit++; | ||||
@@ -73,27 +74,27 @@ int main(int argc, char **argv) | |||||
quit = 0; | quit = 0; | ||||
} | } | ||||
memmove(events + 1, events, (h - 1) * sizeof(int)); | memmove(events + 1, events, (h - 1) * sizeof(struct caca_event)); | ||||
events[0] = event; | events[0] = ev; | ||||
event = caca_get_event(kk, CACA_EVENT_ANY); | ret = caca_get_event(kk, CACA_EVENT_ANY, &ev); | ||||
} | } | ||||
while(event); | while(ret); | ||||
cucul_clear(qq); | cucul_clear(qq); | ||||
/* Print current event */ | /* Print current event */ | ||||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | ||||
cucul_draw_line(qq, 0, 0, cucul_get_width(qq) - 1, 0, " "); | cucul_draw_line(qq, 0, 0, cucul_get_width(qq) - 1, 0, " "); | ||||
print_event(0, 0, events[0]); | print_event(0, 0, events); | ||||
cucul_draw_line(qq, 0, h, cucul_get_width(qq) - 1, h, " "); | cucul_draw_line(qq, 0, h, cucul_get_width(qq) - 1, h, " "); | ||||
cucul_printf(qq, 0, h, "type \"quit\" to exit: %s", quit_string[quit]); | cucul_printf(qq, 0, h, "type \"quit\" to exit: %s", quit_string[quit]); | ||||
/* Print previous events */ | /* Print previous events */ | ||||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | ||||
for(i = 1; i < h && events[i]; i++) | for(i = 1; i < h && events[i].type; i++) | ||||
print_event(0, i, events[i]); | print_event(0, i, events + i); | ||||
caca_display(kk); | caca_display(kk); | ||||
} | } | ||||
@@ -105,39 +106,40 @@ int main(int argc, char **argv) | |||||
return 0; | return 0; | ||||
} | } | ||||
static void print_event(int x, int y, unsigned int event) | static void print_event(int x, int y, struct caca_event *ev) | ||||
{ | { | ||||
int character; | int character; | ||||
switch(event & 0xff000000) | switch(ev->type) | ||||
{ | { | ||||
case CACA_EVENT_NONE: | case CACA_EVENT_NONE: | ||||
cucul_printf(qq, x, y, "CACA_EVENT_NONE"); | cucul_printf(qq, x, y, "CACA_EVENT_NONE"); | ||||
break; | break; | ||||
case CACA_EVENT_KEY_PRESS: | case CACA_EVENT_KEY_PRESS: | ||||
character = event & 0x00ffffff; | character = ev->data.key.c; | ||||
cucul_printf(qq, x, y, "CACA_EVENT_KEY_PRESS 0x%02x (%c)", character, | cucul_printf(qq, x, y, "CACA_EVENT_KEY_PRESS 0x%02x (%c)", character, | ||||
(character > 0x20 && character < 0x80) ? character : '?'); | (character > 0x20 && character < 0x80) ? character : '?'); | ||||
break; | break; | ||||
case CACA_EVENT_KEY_RELEASE: | case CACA_EVENT_KEY_RELEASE: | ||||
character = event & 0x00ffffff; | character = ev->data.key.c; | ||||
cucul_printf(qq, x, y, "CACA_EVENT_KEY_RELEASE 0x%02x (%c)", character, | cucul_printf(qq, x, y, "CACA_EVENT_KEY_RELEASE 0x%02x (%c)", character, | ||||
(character > 0x20 && character < 0x80) ? character : '?'); | (character > 0x20 && character < 0x80) ? character : '?'); | ||||
break; | break; | ||||
case CACA_EVENT_MOUSE_MOTION: | case CACA_EVENT_MOUSE_MOTION: | ||||
cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_MOTION %u %u", | cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_MOTION %u %u", | ||||
(event & 0x00fff000) >> 12, event & 0x00000fff); | ev->data.mouse.x, ev->data.mouse.y); | ||||
break; | break; | ||||
case CACA_EVENT_MOUSE_PRESS: | case CACA_EVENT_MOUSE_PRESS: | ||||
cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_PRESS %u", | cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_PRESS %u", | ||||
event & 0x00ffffff); | ev->data.mouse.button); | ||||
break; | break; | ||||
case CACA_EVENT_MOUSE_RELEASE: | case CACA_EVENT_MOUSE_RELEASE: | ||||
cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_RELEASE %u", | cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_RELEASE %u", | ||||
event & 0x00ffffff); | ev->data.mouse.button); | ||||
break; | break; | ||||
case CACA_EVENT_RESIZE: | case CACA_EVENT_RESIZE: | ||||
cucul_printf(qq, x, y, "CACA_EVENT_RESIZE"); | cucul_printf(qq, x, y, "CACA_EVENT_RESIZE %u %u", | ||||
ev->data.resize.w, ev->data.resize.h); | |||||
break; | break; | ||||
default: | default: | ||||
cucul_printf(qq, x, y, "CACA_EVENT_UNKNOWN"); | cucul_printf(qq, x, y, "CACA_EVENT_UNKNOWN"); | ||||
@@ -33,6 +33,7 @@ uint32_t buffer[256 * 4]; | |||||
int main(void) | int main(void) | ||||
{ | { | ||||
struct caca_event ev; | |||||
cucul_t *qq, *gg, *mask; | cucul_t *qq, *gg, *mask; | ||||
caca_t *kk; | caca_t *kk; | ||||
struct cucul_bitmap *left, *right; | struct cucul_bitmap *left, *right; | ||||
@@ -61,16 +62,19 @@ int main(void) | |||||
for(x = 0; ; x++) | for(x = 0; ; x++) | ||||
{ | { | ||||
int ev = caca_get_event(kk, CACA_EVENT_KEY_PRESS); | int ret = caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev); | ||||
if(ret) | |||||
if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_LEFT)) | { | ||||
gam /= 1.03; | if(ev.data.key.c == CACA_KEY_LEFT) | ||||
else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_RIGHT)) | gam /= 1.03; | ||||
gam *= 1.03; | else if(ev.data.key.c == CACA_KEY_RIGHT) | ||||
else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_DOWN)) | gam *= 1.03; | ||||
gam = 1.0; | else if(ev.data.key.c == CACA_KEY_DOWN) | ||||
else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE)) | gam = 1.0; | ||||
break; | else if(ev.data.key.c == CACA_KEY_ESCAPE) | ||||
break; | |||||
} | |||||
/* Resize the spare canvas, just in case the main one changed */ | /* Resize the spare canvas, just in case the main one changed */ | ||||
cucul_set_size(gg, cucul_get_width(qq), cucul_get_height(qq)); | cucul_set_size(gg, cucul_get_width(qq), cucul_get_height(qq)); | ||||
@@ -28,6 +28,7 @@ uint32_t buffer[256*256]; | |||||
int main(void) | int main(void) | ||||
{ | { | ||||
struct caca_event ev; | |||||
cucul_t *qq; | cucul_t *qq; | ||||
caca_t *kk; | caca_t *kk; | ||||
@@ -52,7 +53,7 @@ int main(void) | |||||
caca_display(kk); | caca_display(kk); | ||||
while(!caca_get_event(kk, CACA_EVENT_KEY_PRESS)); | caca_wait_event(kk, CACA_EVENT_KEY_PRESS, &ev); | ||||
caca_detach(kk); | caca_detach(kk); | ||||
cucul_free(qq); | cucul_free(qq); | ||||
@@ -53,13 +53,13 @@ int main(int argc, char **argv) | |||||
/* Go ! */ | /* Go ! */ | ||||
while(!quit) | while(!quit) | ||||
{ | { | ||||
struct caca_event ev; | |||||
int xa, ya, xb, yb; | int xa, ya, xb, yb; | ||||
char buf[BUFSIZ]; | char buf[BUFSIZ]; | ||||
int event; | |||||
while((event = caca_get_event(kk, CACA_EVENT_KEY_PRESS))) | while(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev)) | ||||
{ | { | ||||
switch(event & 0x00ffffff) | switch(ev.data.key.c) | ||||
{ | { | ||||
case 0: | case 0: | ||||
break; | break; | ||||
@@ -49,6 +49,7 @@ static char const *duck[] = | |||||
int main(void) | int main(void) | ||||
{ | { | ||||
struct caca_event ev; | |||||
cucul_t *qq, *normal, *flip, *flop, *rotate; | cucul_t *qq, *normal, *flip, *flop, *rotate; | ||||
caca_t *kk; | caca_t *kk; | ||||
int i; | int i; | ||||
@@ -107,7 +108,7 @@ int main(void) | |||||
caca_display(kk); | caca_display(kk); | ||||
while(!caca_get_event(kk, CACA_EVENT_KEY_PRESS)); | caca_wait_event(kk, CACA_EVENT_KEY_PRESS, &ev); | ||||
caca_detach(kk); | caca_detach(kk); | ||||
cucul_free(rotate); | cucul_free(rotate); | ||||
@@ -26,6 +26,7 @@ typedef unsigned int uint32_t; | |||||
int main(void) | int main(void) | ||||
{ | { | ||||
struct caca_event ev; | |||||
cucul_t *qq; | cucul_t *qq; | ||||
caca_t *kk; | caca_t *kk; | ||||
@@ -86,7 +87,7 @@ int main(void) | |||||
caca_display(kk); | caca_display(kk); | ||||
while(!caca_get_event(kk, CACA_EVENT_KEY_PRESS)); | caca_wait_event(kk, CACA_EVENT_KEY_PRESS, &ev); | ||||
caca_detach(kk); | caca_detach(kk); | ||||
cucul_free(qq); | cucul_free(qq); | ||||