@@ -74,9 +74,9 @@ caca_t * caca_attach(cucul_t * qq) | |||
kk->events.key_timer.last_usec = 0; | |||
kk->events.last_key_ticks = 0; | |||
kk->events.autorepeat_ticks = 0; | |||
kk->events.last_key = 0; | |||
kk->events.last_key_event.type = CACA_EVENT_NONE; | |||
#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; | |||
#endif | |||
@@ -113,16 +113,29 @@ extern "C" | |||
* | |||
* Event types returned by caca_get_event(). | |||
*/ | |||
enum caca_event | |||
enum caca_event_type | |||
{ | |||
CACA_EVENT_NONE = 0x00000000, /**< No event. */ | |||
CACA_EVENT_KEY_PRESS = 0x01000000, /**< A key was pressed. */ | |||
CACA_EVENT_KEY_RELEASE = 0x02000000, /**< A key was released. */ | |||
CACA_EVENT_MOUSE_PRESS = 0x04000000, /**< A mouse button was pressed. */ | |||
CACA_EVENT_MOUSE_RELEASE = 0x08000000, /**< A mouse button was released. */ | |||
CACA_EVENT_MOUSE_MOTION = 0x10000000, /**< The mouse was moved. */ | |||
CACA_EVENT_RESIZE = 0x20000000, /**< The window was resized. */ | |||
CACA_EVENT_ANY = 0xff000000 /**< Bitmask for any event. */ | |||
CACA_EVENT_NONE = 0x0000, /**< No event. */ | |||
CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */ | |||
CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */ | |||
CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */ | |||
CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */ | |||
CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */ | |||
CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */ | |||
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. | |||
@@ -196,8 +209,8 @@ int caca_set_window_title(caca_t *kk, char const *); | |||
* clicks. | |||
* | |||
* @{ */ | |||
unsigned int caca_get_event(caca_t *kk, unsigned int); | |||
unsigned int caca_wait_event(caca_t *kk, unsigned int); | |||
int caca_get_event(caca_t *kk, unsigned int, struct caca_event *); | |||
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_y(caca_t *kk); | |||
/* @} */ | |||
@@ -115,7 +115,7 @@ struct caca_context | |||
unsigned int (* get_window_height) (caca_t *); | |||
void (* display) (caca_t *); | |||
void (* handle_resize) (caca_t *); | |||
unsigned int (* get_event) (caca_t *); | |||
int (* get_event) (caca_t *, struct caca_event *); | |||
} drv; | |||
/* Mouse position */ | |||
@@ -139,15 +139,15 @@ struct caca_context | |||
struct events | |||
{ | |||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) | |||
unsigned int buf[EVENTBUF_LEN]; | |||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) | |||
struct caca_event buf[EVENTBUF_LEN]; | |||
int queue; | |||
#endif | |||
#if defined(USE_SLANG) || defined(USE_NCURSES) | |||
struct caca_timer key_timer; | |||
unsigned int last_key_ticks; | |||
unsigned int autorepeat_ticks; | |||
unsigned int last_key; | |||
struct caca_event last_key_event; | |||
#endif | |||
} events; | |||
}; | |||
@@ -158,9 +158,9 @@ extern unsigned int _caca_getticks(struct caca_timer *); | |||
/* Internal event functions */ | |||
extern void _caca_handle_resize(caca_t *); | |||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) | |||
extern void _push_event(caca_t *, unsigned int); | |||
extern unsigned int _pop_event(caca_t *); | |||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) | |||
extern void _push_event(caca_t *, struct caca_event *); | |||
extern int _pop_event(caca_t *, struct caca_event *); | |||
#endif | |||
#endif /* __CACA_INTERNALS_H__ */ |
@@ -121,16 +121,30 @@ static void conio_handle_resize(caca_t *kk) | |||
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()) | |||
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(); | |||
_push_event(kk, CACA_EVENT_KEY_RELEASE | event); | |||
return CACA_EVENT_KEY_PRESS | event; | |||
return 1; | |||
} | |||
/* | |||
@@ -308,62 +308,80 @@ static void gl_handle_resize(caca_t *kk) | |||
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(); | |||
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) | |||
{ | |||
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) | |||
{ | |||
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->mouse.x = kk->drv.p->mouse_x; | |||
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; | |||
return 1; | |||
} | |||
if(kk->drv.p->key != 0) | |||
{ | |||
event |= CACA_EVENT_KEY_PRESS; | |||
event |= kk->drv.p->key; | |||
ev->type = CACA_EVENT_KEY_PRESS; | |||
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; | |||
return event; | |||
return 1; | |||
} | |||
if(kk->drv.p->special_key != 0) | |||
{ | |||
event |= CACA_EVENT_KEY_PRESS; | |||
switch(kk->drv.p->special_key) | |||
{ | |||
case GLUT_KEY_F1 : kk->drv.p->special_key = 0; return event | CACA_KEY_F1; | |||
case GLUT_KEY_F2 : kk->drv.p->special_key = 0; return event | CACA_KEY_F2; | |||
case GLUT_KEY_F3 : kk->drv.p->special_key = 0; return event | CACA_KEY_F3; | |||
case GLUT_KEY_F4 : kk->drv.p->special_key = 0; return event | CACA_KEY_F4; | |||
case GLUT_KEY_F5 : kk->drv.p->special_key = 0; return event | CACA_KEY_F5; | |||
case GLUT_KEY_F6 : kk->drv.p->special_key = 0; return event | CACA_KEY_F6; | |||
case GLUT_KEY_F7 : kk->drv.p->special_key = 0; return event | CACA_KEY_F7; | |||
case GLUT_KEY_F8 : kk->drv.p->special_key = 0; return event | CACA_KEY_F8; | |||
case GLUT_KEY_F9 : kk->drv.p->special_key = 0; return event | CACA_KEY_F9; | |||
case GLUT_KEY_F10: kk->drv.p->special_key = 0; return event | CACA_KEY_F10; | |||
case GLUT_KEY_F11: kk->drv.p->special_key = 0; return event | CACA_KEY_F11; | |||
case GLUT_KEY_F12: kk->drv.p->special_key = 0; return event | CACA_KEY_F12; | |||
case GLUT_KEY_LEFT : kk->drv.p->special_key = 0; return event | CACA_KEY_LEFT; | |||
case GLUT_KEY_RIGHT: kk->drv.p->special_key = 0; return event | CACA_KEY_RIGHT; | |||
case GLUT_KEY_UP : kk->drv.p->special_key = 0; return event | CACA_KEY_UP; | |||
case GLUT_KEY_DOWN : kk->drv.p->special_key = 0; return event | CACA_KEY_DOWN; | |||
default: return CACA_EVENT_NONE; | |||
case GLUT_KEY_F1 : ev->data.key.c = CACA_KEY_F1; break; | |||
case GLUT_KEY_F2 : ev->data.key.c = CACA_KEY_F2; break; | |||
case GLUT_KEY_F3 : ev->data.key.c = CACA_KEY_F3; break; | |||
case GLUT_KEY_F4 : ev->data.key.c = CACA_KEY_F4; break; | |||
case GLUT_KEY_F5 : ev->data.key.c = CACA_KEY_F5; break; | |||
case GLUT_KEY_F6 : ev->data.key.c = CACA_KEY_F6; break; | |||
case GLUT_KEY_F7 : ev->data.key.c = CACA_KEY_F7; break; | |||
case GLUT_KEY_F8 : ev->data.key.c = CACA_KEY_F8; break; | |||
case GLUT_KEY_F9 : ev->data.key.c = CACA_KEY_F9; break; | |||
case GLUT_KEY_F10: ev->data.key.c = CACA_KEY_F10; break; | |||
case GLUT_KEY_F11: ev->data.key.c = CACA_KEY_F11; break; | |||
case GLUT_KEY_F12: ev->data.key.c = CACA_KEY_F12; break; | |||
case GLUT_KEY_LEFT : ev->data.key.c = CACA_KEY_LEFT; break; | |||
case GLUT_KEY_RIGHT: ev->data.key.c = CACA_KEY_RIGHT; break; | |||
case GLUT_KEY_UP : ev->data.key.c = CACA_KEY_UP; break; | |||
case GLUT_KEY_DOWN : ev->data.key.c = CACA_KEY_DOWN; break; | |||
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; | |||
} | |||
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; | |||
intkey = getch(); | |||
if(intkey == ERR) | |||
return CACA_EVENT_NONE; | |||
{ | |||
ev->type = CACA_EVENT_NONE; | |||
return 0; | |||
} | |||
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) | |||
@@ -248,109 +252,129 @@ static unsigned int ncurses_get_event(caca_t *kk) | |||
switch(mevent.bstate) | |||
{ | |||
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; | |||
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; | |||
case BUTTON1_CLICKED: | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | |||
ev->data.mouse.button = 1; | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
break; | |||
case BUTTON1_DOUBLE_CLICKED: | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | |||
ev->data.mouse.button = 1; | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
break; | |||
case BUTTON1_TRIPLE_CLICKED: | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); | |||
ev->data.mouse.button = 1; | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
break; | |||
case BUTTON1_RESERVED_EVENT: | |||
break; | |||
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; | |||
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; | |||
case BUTTON2_CLICKED: | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | |||
ev->data.mouse.button = 2; | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
break; | |||
case BUTTON2_DOUBLE_CLICKED: | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | |||
ev->data.mouse.button = 2; | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
break; | |||
case BUTTON2_TRIPLE_CLICKED: | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); | |||
ev->data.mouse.button = 2; | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
break; | |||
case BUTTON2_RESERVED_EVENT: | |||
break; | |||
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; | |||
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; | |||
case BUTTON3_CLICKED: | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | |||
ev->data.mouse.button = 3; | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
break; | |||
case BUTTON3_DOUBLE_CLICKED: | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | |||
ev->data.mouse.button = 3; | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
break; | |||
case BUTTON3_TRIPLE_CLICKED: | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); | |||
ev->data.mouse.button = 3; | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
break; | |||
case BUTTON3_RESERVED_EVENT: | |||
break; | |||
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; | |||
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; | |||
case BUTTON4_CLICKED: | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | |||
ev->data.mouse.button = 4; | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
break; | |||
case BUTTON4_DOUBLE_CLICKED: | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | |||
ev->data.mouse.button = 4; | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
break; | |||
case BUTTON4_TRIPLE_CLICKED: | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); | |||
ev->data.mouse.button = 4; | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev); | |||
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev); | |||
break; | |||
case BUTTON4_RESERVED_EVENT: | |||
break; | |||
@@ -361,45 +385,51 @@ static unsigned int ncurses_get_event(caca_t *kk) | |||
if(kk->mouse.x == (unsigned int)mevent.x && | |||
kk->mouse.y == (unsigned int)mevent.y) | |||
return _pop_event(kk); | |||
return _pop_event(kk, ev); | |||
kk->mouse.x = mevent.x; | |||
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) | |||
{ | |||
case KEY_UP: return event | CACA_KEY_UP; | |||
case KEY_DOWN: return event | CACA_KEY_DOWN; | |||
case KEY_LEFT: return event | CACA_KEY_LEFT; | |||
case KEY_RIGHT: return event | CACA_KEY_RIGHT; | |||
case KEY_IC: return event | CACA_KEY_INSERT; | |||
case KEY_DC: return event | CACA_KEY_DELETE; | |||
case KEY_HOME: return event | CACA_KEY_HOME; | |||
case KEY_END: return event | CACA_KEY_END; | |||
case KEY_PPAGE: return event | CACA_KEY_PAGEUP; | |||
case KEY_NPAGE: return event | CACA_KEY_PAGEDOWN; | |||
case KEY_F(1): return event | CACA_KEY_F1; | |||
case KEY_F(2): return event | CACA_KEY_F2; | |||
case KEY_F(3): return event | CACA_KEY_F3; | |||
case KEY_F(4): return event | CACA_KEY_F4; | |||
case KEY_F(5): return event | CACA_KEY_F5; | |||
case KEY_F(6): return event | CACA_KEY_F6; | |||
case KEY_F(7): return event | CACA_KEY_F7; | |||
case KEY_F(8): return event | CACA_KEY_F8; | |||
case KEY_F(9): return event | CACA_KEY_F9; | |||
case KEY_F(10): return event | CACA_KEY_F10; | |||
case KEY_F(11): return event | CACA_KEY_F11; | |||
case KEY_F(12): return event | CACA_KEY_F12; | |||
case KEY_UP: ev->data.key.c = CACA_KEY_UP; break; | |||
case KEY_DOWN: ev->data.key.c = CACA_KEY_DOWN; break; | |||
case KEY_LEFT: ev->data.key.c = CACA_KEY_LEFT; break; | |||
case KEY_RIGHT: ev->data.key.c = CACA_KEY_RIGHT; break; | |||
case KEY_IC: ev->data.key.c = CACA_KEY_INSERT; break; | |||
case KEY_DC: ev->data.key.c = CACA_KEY_DELETE; break; | |||
case KEY_HOME: ev->data.key.c = CACA_KEY_HOME; break; | |||
case KEY_END: ev->data.key.c = CACA_KEY_END; break; | |||
case KEY_PPAGE: ev->data.key.c = CACA_KEY_PAGEUP; break; | |||
case KEY_NPAGE: ev->data.key.c = CACA_KEY_PAGEDOWN; break; | |||
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(3): ev->data.key.c = CACA_KEY_F3; break; | |||
case KEY_F(4): ev->data.key.c = CACA_KEY_F4; break; | |||
case KEY_F(5): ev->data.key.c = CACA_KEY_F5; break; | |||
case KEY_F(6): ev->data.key.c = CACA_KEY_F6; break; | |||
case KEY_F(7): ev->data.key.c = CACA_KEY_F7; break; | |||
case KEY_F(8): ev->data.key.c = CACA_KEY_F8; break; | |||
case KEY_F(9): ev->data.key.c = CACA_KEY_F9; break; | |||
case KEY_F(10): ev->data.key.c = CACA_KEY_F10; break; | |||
case KEY_F(11): ev->data.key.c = CACA_KEY_F11; break; | |||
case KEY_F(12): ev->data.key.c = CACA_KEY_F12; break; | |||
default: ev->type = CACA_EVENT_NONE; return 0; | |||
} | |||
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 */ | |||
} | |||
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 | |||
* more often than display */ | |||
@@ -254,13 +254,15 @@ static void slang_handle_resize(caca_t *kk) | |||
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; | |||
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 | |||
* 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(intkey < 0x100) | |||
{ | |||
return CACA_EVENT_KEY_PRESS | intkey; | |||
ev->type = CACA_EVENT_KEY_PRESS; | |||
ev->data.key.c = intkey; | |||
return 1; | |||
} | |||
if(intkey == 0x3e9) | |||
@@ -284,49 +288,59 @@ static unsigned int slang_get_event(caca_t *kk) | |||
int button = (SLang_getkey() - ' ' + 1) & 0xf; | |||
unsigned int x = SLang_getkey() - '!'; | |||
unsigned int y = SLang_getkey() - '!'; | |||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | button); | |||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | button); | |||
ev->data.mouse.button = 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) | |||
return _pop_event(kk); | |||
return _pop_event(kk, ev); | |||
kk->mouse.x = x; | |||
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) | |||
{ | |||
case SL_KEY_UP: return event | CACA_KEY_UP; | |||
case SL_KEY_DOWN: return event | CACA_KEY_DOWN; | |||
case SL_KEY_LEFT: return event | CACA_KEY_LEFT; | |||
case SL_KEY_RIGHT: return event | CACA_KEY_RIGHT; | |||
case SL_KEY_IC: return event | CACA_KEY_INSERT; | |||
case SL_KEY_DELETE: return event | CACA_KEY_DELETE; | |||
case SL_KEY_HOME: return event | CACA_KEY_HOME; | |||
case SL_KEY_END: return event | CACA_KEY_END; | |||
case SL_KEY_PPAGE: return event | CACA_KEY_PAGEUP; | |||
case SL_KEY_NPAGE: return event | CACA_KEY_PAGEDOWN; | |||
case SL_KEY_F(1): return event | CACA_KEY_F1; | |||
case SL_KEY_F(2): return event | CACA_KEY_F2; | |||
case SL_KEY_F(3): return event | CACA_KEY_F3; | |||
case SL_KEY_F(4): return event | CACA_KEY_F4; | |||
case SL_KEY_F(5): return event | CACA_KEY_F5; | |||
case SL_KEY_F(6): return event | CACA_KEY_F6; | |||
case SL_KEY_F(7): return event | CACA_KEY_F7; | |||
case SL_KEY_F(8): return event | CACA_KEY_F8; | |||
case SL_KEY_F(9): return event | CACA_KEY_F9; | |||
case SL_KEY_F(10): return event | CACA_KEY_F10; | |||
case SL_KEY_F(11): return event | CACA_KEY_F11; | |||
case SL_KEY_F(12): return event | CACA_KEY_F12; | |||
case SL_KEY_UP: ev->data.key.c = CACA_KEY_UP; break; | |||
case SL_KEY_DOWN: ev->data.key.c = CACA_KEY_DOWN; break; | |||
case SL_KEY_LEFT: ev->data.key.c = CACA_KEY_LEFT; break; | |||
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_DELETE: ev->data.key.c = CACA_KEY_DELETE; break; | |||
case SL_KEY_HOME: ev->data.key.c = CACA_KEY_HOME; break; | |||
case SL_KEY_END: ev->data.key.c = CACA_KEY_END; break; | |||
case SL_KEY_PPAGE: ev->data.key.c = CACA_KEY_PAGEUP; break; | |||
case SL_KEY_NPAGE: ev->data.key.c = CACA_KEY_PAGEDOWN; break; | |||
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(3): ev->data.key.c = CACA_KEY_F3; break; | |||
case SL_KEY_F(4): ev->data.key.c = CACA_KEY_F4; break; | |||
case SL_KEY_F(5): ev->data.key.c = CACA_KEY_F5; break; | |||
case SL_KEY_F(6): ev->data.key.c = CACA_KEY_F6; break; | |||
case SL_KEY_F(7): ev->data.key.c = CACA_KEY_F7; break; | |||
case SL_KEY_F(8): ev->data.key.c = CACA_KEY_F8; break; | |||
case SL_KEY_F(9): ev->data.key.c = CACA_KEY_F9; break; | |||
case SL_KEY_F(10): ev->data.key.c = CACA_KEY_F10; break; | |||
case SL_KEY_F(11): ev->data.key.c = CACA_KEY_F11; break; | |||
case SL_KEY_F(12): ev->data.key.c = CACA_KEY_F12; break; | |||
default: ev->type = CACA_EVENT_NONE; return 0; | |||
} | |||
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; | |||
} | |||
static unsigned int vga_get_event(caca_t *kk) | |||
static int vga_get_event(caca_t *kk, struct caca_event *ev) | |||
{ | |||
/* 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; | |||
} | |||
static unsigned int win32_get_event(caca_t *kk) | |||
static int win32_get_event(caca_t *kk, struct caca_event *ev) | |||
{ | |||
INPUT_RECORD rec; | |||
DWORD num; | |||
@@ -252,12 +252,19 @@ static unsigned int win32_get_event(caca_t *kk) | |||
unsigned int event; | |||
if(rec.Event.KeyEvent.bKeyDown) | |||
event = CACA_EVENT_KEY_PRESS; | |||
ev->type = CACA_EVENT_KEY_PRESS; | |||
else | |||
event = CACA_EVENT_KEY_RELEASE; | |||
ev->type = CACA_EVENT_KEY_RELEASE; | |||
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) | |||
@@ -265,10 +272,18 @@ static unsigned int win32_get_event(caca_t *kk) | |||
if(rec.Event.MouseEvent.dwEventFlags == 0) | |||
{ | |||
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) | |||
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) | |||
{ | |||
@@ -281,8 +296,10 @@ static unsigned int win32_get_event(caca_t *kk) | |||
kk->mouse.x = pos.X; | |||
kk->mouse.y = pos.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; | |||
} | |||
#if 0 | |||
else if(rec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK) | |||
@@ -303,11 +320,13 @@ static unsigned int win32_get_event(caca_t *kk) | |||
} | |||
/* Unknown event */ | |||
return CACA_EVENT_NONE; | |||
ev->type = CACA_EVENT_NONE; | |||
return 0; | |||
} | |||
/* 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; | |||
} | |||
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; | |||
char key; | |||
@@ -457,56 +456,77 @@ static unsigned int x11_get_event(caca_t *kk) | |||
kk->mouse.x = newx; | |||
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 */ | |||
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) | |||
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 */ | |||
if(xevent.type == KeyPress) | |||
event |= CACA_EVENT_KEY_PRESS; | |||
ev->type = CACA_EVENT_KEY_PRESS; | |||
else if(xevent.type == KeyRelease) | |||
event |= CACA_EVENT_KEY_RELEASE; | |||
ev->type = CACA_EVENT_KEY_RELEASE; | |||
else | |||
continue; | |||
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); | |||
switch(keysym) | |||
{ | |||
case XK_F1: return event | CACA_KEY_F1; | |||
case XK_F2: return event | CACA_KEY_F2; | |||
case XK_F3: return event | CACA_KEY_F3; | |||
case XK_F4: return event | CACA_KEY_F4; | |||
case XK_F5: return event | CACA_KEY_F5; | |||
case XK_F6: return event | CACA_KEY_F6; | |||
case XK_F7: return event | CACA_KEY_F7; | |||
case XK_F8: return event | CACA_KEY_F8; | |||
case XK_F9: return event | CACA_KEY_F9; | |||
case XK_F10: return event | CACA_KEY_F10; | |||
case XK_F11: return event | CACA_KEY_F11; | |||
case XK_F12: return event | CACA_KEY_F12; | |||
case XK_F13: return event | CACA_KEY_F13; | |||
case XK_F14: return event | CACA_KEY_F14; | |||
case XK_F15: return event | CACA_KEY_F15; | |||
case XK_Left: return event | CACA_KEY_LEFT; | |||
case XK_Right: return event | CACA_KEY_RIGHT; | |||
case XK_Up: return event | CACA_KEY_UP; | |||
case XK_Down: return event | CACA_KEY_DOWN; | |||
default: return CACA_EVENT_NONE; | |||
case XK_F1: ev->data.key.c = CACA_KEY_F1; break; | |||
case XK_F2: ev->data.key.c = CACA_KEY_F2; break; | |||
case XK_F3: ev->data.key.c = CACA_KEY_F3; break; | |||
case XK_F4: ev->data.key.c = CACA_KEY_F4; break; | |||
case XK_F5: ev->data.key.c = CACA_KEY_F5; break; | |||
case XK_F6: ev->data.key.c = CACA_KEY_F6; break; | |||
case XK_F7: ev->data.key.c = CACA_KEY_F7; break; | |||
case XK_F8: ev->data.key.c = CACA_KEY_F8; break; | |||
case XK_F9: ev->data.key.c = CACA_KEY_F9; break; | |||
case XK_F10: ev->data.key.c = CACA_KEY_F10; break; | |||
case XK_F11: ev->data.key.c = CACA_KEY_F11; break; | |||
case XK_F12: ev->data.key.c = CACA_KEY_F12; break; | |||
case XK_F13: ev->data.key.c = CACA_KEY_F13; break; | |||
case XK_F14: ev->data.key.c = CACA_KEY_F14; break; | |||
case XK_F15: ev->data.key.c = CACA_KEY_F15; break; | |||
case XK_Left: ev->data.key.c = CACA_KEY_LEFT; break; | |||
case XK_Right: ev->data.key.c = CACA_KEY_RIGHT; break; | |||
case XK_Up: ev->data.key.c = CACA_KEY_UP; break; | |||
case XK_Down: ev->data.key.c = CACA_KEY_DOWN; break; | |||
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" | |||
#if !defined(__KERNEL__) | |||
# include <stdio.h> | |||
#endif | |||
#include "cucul.h" | |||
#include "cucul_internals.h" | |||
#include "caca.h" | |||
#include "caca_internals.h" | |||
static unsigned int _get_next_event(caca_t *); | |||
static unsigned int _lowlevel_event(caca_t *); | |||
static int _get_next_event(caca_t *, struct caca_event *); | |||
static int _lowlevel_event(caca_t *, struct caca_event *); | |||
#if !defined(_DOXYGEN_SKIP_ME) | |||
/* 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. | |||
* \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) | |||
return CACA_EVENT_NONE; | |||
return 0; | |||
for( ; ; ) | |||
{ | |||
unsigned int event = _get_next_event(kk); | |||
int ret = _get_next_event(kk, ev); | |||
if(!event || event & event_mask) | |||
return event; | |||
if(!ret || ev->type & event_mask) | |||
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. | |||
* \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) | |||
return CACA_EVENT_NONE; | |||
return 0; | |||
for( ; ; ) | |||
{ | |||
unsigned int event = _get_next_event(kk); | |||
int ret = _get_next_event(kk, ev); | |||
if(event & event_mask) | |||
return event; | |||
if(ret && (ev->type & event_mask)) | |||
return ret; | |||
_caca_sleep(10000); | |||
} | |||
@@ -126,22 +130,25 @@ unsigned int caca_get_mouse_y(caca_t *kk) | |||
* 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) | |||
unsigned int ticks; | |||
#endif | |||
unsigned int event; | |||
int ret; | |||
/* If we are about to return a resize event, acknowledge it */ | |||
if(kk->resize.resized) | |||
{ | |||
kk->resize.resized = 0; | |||
_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(kk->drv.driver != CACA_DRIVER_SLANG) | |||
@@ -149,7 +156,7 @@ static unsigned int _get_next_event(caca_t *kk) | |||
#if defined(USE_NCURSES) | |||
if(kk->drv.driver != CACA_DRIVER_NCURSES) | |||
#endif | |||
return event; | |||
return ret; | |||
#if defined(USE_SLANG) || defined(USE_NCURSES) | |||
/* Simulate long keypresses using autorepeat features */ | |||
@@ -158,83 +165,87 @@ static unsigned int _get_next_event(caca_t *kk) | |||
kk->events.autorepeat_ticks += ticks; | |||
/* 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_THRESHOLD | |||
&& kk->events.autorepeat_ticks > AUTOREPEAT_RATE) | |||
{ | |||
_push_event(kk, event); | |||
_push_event(kk, ev); | |||
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 | |||
* 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; | |||
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 | |||
* 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 | |||
|| (event & CACA_EVENT_KEY_PRESS))) | |||
|| (ev->type & CACA_EVENT_KEY_PRESS))) | |||
{ | |||
_push_event(kk, event); | |||
event = CACA_EVENT_KEY_RELEASE | kk->events.last_key; | |||
kk->events.last_key = 0; | |||
return event; | |||
_push_event(kk, ev); | |||
*ev = kk->events.last_key_event; | |||
ev->type = CACA_EVENT_KEY_RELEASE; | |||
kk->events.last_key_event.type = CACA_EVENT_NONE; | |||
return 1; | |||
} | |||
/* 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.autorepeat_ticks = 0; | |||
kk->events.last_key = event & 0x00ffffff; | |||
kk->events.last_key_event = *ev; | |||
} | |||
return event; | |||
return ev->type ? 1 : 0; | |||
#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) | |||
unsigned int event = _pop_event(kk); | |||
int ret = _pop_event(kk, ev); | |||
if(event) | |||
return event; | |||
if(ret) | |||
return ret; | |||
#endif | |||
return kk->drv.get_event(kk); | |||
return kk->drv.get_event(kk, ev); | |||
} | |||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) | |||
void _push_event(caca_t *kk, unsigned int event) | |||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) | |||
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; | |||
kk->events.buf[kk->events.queue] = event; | |||
kk->events.buf[kk->events.queue] = *ev; | |||
kk->events.queue++; | |||
} | |||
unsigned int _pop_event(caca_t *kk) | |||
int _pop_event(caca_t *kk, struct caca_event *ev) | |||
{ | |||
int i; | |||
unsigned int event; | |||
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++) | |||
kk->events.buf[i - 1] = kk->events.buf[i]; | |||
kk->events.queue--; | |||
return event; | |||
return 1; | |||
} | |||
#endif | |||
@@ -261,12 +261,15 @@ game (void) | |||
#endif | |||
{ | |||
#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; | |||
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | |||
switch(ev.data.key.c) | |||
{ | |||
case CACA_KEY_ESCAPE: return; | |||
case ' ': pause = !pause; | |||
} | |||
} | |||
#endif | |||
drawfire (); | |||
} | |||
@@ -92,10 +92,14 @@ int main(int argc, char **argv) | |||
/* Go ! */ | |||
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; | |||
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | |||
switch(ev.data.key.c) | |||
{ | |||
case CACA_KEY_ESCAPE: goto end; | |||
case ' ': pause = !pause; | |||
} | |||
} | |||
if(pause) | |||
@@ -68,10 +68,14 @@ int main (int argc, char **argv) | |||
/* Main loop */ | |||
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; | |||
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | |||
switch(ev.data.key.c) | |||
{ | |||
case CACA_KEY_ESCAPE: goto end; | |||
case ' ': pause = !pause; | |||
} | |||
} | |||
if(pause) | |||
@@ -80,10 +80,14 @@ int main (int argc, char **argv) | |||
/* Main loop */ | |||
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; | |||
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | |||
switch(ev.data.key.c) | |||
{ | |||
case CACA_KEY_ESCAPE: goto end; | |||
case ' ': pause = !pause; | |||
} | |||
} | |||
if(pause) | |||
@@ -143,32 +143,34 @@ int main(int argc, char **argv) | |||
/* Go ! */ | |||
while(!quit) | |||
{ | |||
struct caca_event ev; | |||
unsigned int const event_mask = CACA_EVENT_KEY_PRESS | |||
| CACA_EVENT_RESIZE | |||
| 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) | |||
event = caca_get_event(kk, event_mask); | |||
event = caca_get_event(kk, event_mask, &ev); | |||
else | |||
event = caca_wait_event(kk, event_mask); | |||
event = caca_wait_event(kk, event_mask, &ev); | |||
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; | |||
reload = 1; | |||
} | |||
else if((event & 0x00ffffff) == 2) | |||
else if(ev.data.mouse.button == 2) | |||
{ | |||
if(items) current = (items + current - 1) % items; | |||
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': | |||
@@ -287,11 +289,11 @@ int main(int argc, char **argv) | |||
quit = 1; | |||
break; | |||
} | |||
else if(event == CACA_EVENT_RESIZE) | |||
else if(ev.type == CACA_EVENT_RESIZE) | |||
{ | |||
caca_display(kk); | |||
ww = cucul_get_width(qq); | |||
wh = cucul_get_height(qq); | |||
ww = ev.data.resize.w; | |||
wh = ev.data.resize.h; | |||
update = 1; | |||
set_zoom(zoom); | |||
} | |||
@@ -302,7 +304,7 @@ int main(int argc, char **argv) | |||
if(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) | |||
@@ -24,6 +24,7 @@ int main(int argc, char **argv) | |||
{ | |||
cucul_t *qq; | |||
caca_t *kk; | |||
struct caca_event ev; | |||
int i, j; | |||
qq = cucul_create(0, 0); | |||
@@ -49,7 +50,7 @@ int main(int argc, char **argv) | |||
} | |||
caca_display(kk); | |||
caca_wait_event(kk, CACA_EVENT_KEY_PRESS); | |||
caca_wait_event(kk, CACA_EVENT_KEY_PRESS, &ev); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
@@ -68,19 +68,19 @@ int main(int argc, char **argv) | |||
/* Go ! */ | |||
while(!quit) | |||
{ | |||
struct caca_event ev; | |||
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; | |||
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': | |||
@@ -139,11 +139,11 @@ int main(int argc, char **argv) | |||
if(demo) | |||
cucul_clear(qq); | |||
} | |||
else if(event & CACA_EVENT_MOUSE_MOTION) | |||
else if(ev.type & CACA_EVENT_MOUSE_MOTION) | |||
{ | |||
mouse = 1; | |||
xmouse = (event & 0xfff000) >> 12; | |||
ymouse = event & 0xfff; | |||
xmouse = ev.data.mouse.x; | |||
ymouse = ev.data.mouse.y; | |||
} | |||
} | |||
@@ -34,6 +34,7 @@ char density[] = " -,+:;o&%w$W@#"; | |||
int main(void) | |||
{ | |||
struct caca_event ev; | |||
cucul_t *qq; | |||
caca_t *kk; | |||
int neara, dista, nearb, distb, dist; | |||
@@ -123,7 +124,7 @@ int main(void) | |||
caca_display(kk); | |||
while(!caca_get_event(kk, CACA_EVENT_KEY_PRESS)); | |||
caca_wait_event(kk, CACA_EVENT_KEY_PRESS, &ev); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
@@ -23,11 +23,11 @@ | |||
static cucul_t *qq; | |||
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 *events; | |||
struct caca_event *events; | |||
int i, h, quit; | |||
qq = cucul_create(0, 0); | |||
@@ -47,23 +47,24 @@ int main(int argc, char **argv) | |||
caca_display(kk); | |||
events = malloc(h * sizeof(int)); | |||
memset(events, 0, h * sizeof(int)); | |||
events = malloc(h * sizeof(struct caca_event)); | |||
memset(events, 0, h * sizeof(struct caca_event)); | |||
for(quit = 0; quit < 4; ) | |||
{ | |||
struct caca_event ev; | |||
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; | |||
do | |||
{ | |||
/* "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) | |||
|| (key == 'i' && quit == 2) || (key == 't' && quit == 3)) | |||
quit++; | |||
@@ -73,27 +74,27 @@ int main(int argc, char **argv) | |||
quit = 0; | |||
} | |||
memmove(events + 1, events, (h - 1) * sizeof(int)); | |||
events[0] = event; | |||
memmove(events + 1, events, (h - 1) * sizeof(struct caca_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); | |||
/* Print current event */ | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
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_printf(qq, 0, h, "type \"quit\" to exit: %s", quit_string[quit]); | |||
/* Print previous events */ | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | |||
for(i = 1; i < h && events[i]; i++) | |||
print_event(0, i, events[i]); | |||
for(i = 1; i < h && events[i].type; i++) | |||
print_event(0, i, events + i); | |||
caca_display(kk); | |||
} | |||
@@ -105,39 +106,40 @@ int main(int argc, char **argv) | |||
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; | |||
switch(event & 0xff000000) | |||
switch(ev->type) | |||
{ | |||
case CACA_EVENT_NONE: | |||
cucul_printf(qq, x, y, "CACA_EVENT_NONE"); | |||
break; | |||
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, | |||
(character > 0x20 && character < 0x80) ? character : '?'); | |||
break; | |||
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, | |||
(character > 0x20 && character < 0x80) ? character : '?'); | |||
break; | |||
case CACA_EVENT_MOUSE_MOTION: | |||
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; | |||
case CACA_EVENT_MOUSE_PRESS: | |||
cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_PRESS %u", | |||
event & 0x00ffffff); | |||
ev->data.mouse.button); | |||
break; | |||
case CACA_EVENT_MOUSE_RELEASE: | |||
cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_RELEASE %u", | |||
event & 0x00ffffff); | |||
ev->data.mouse.button); | |||
break; | |||
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; | |||
default: | |||
cucul_printf(qq, x, y, "CACA_EVENT_UNKNOWN"); | |||
@@ -33,6 +33,7 @@ uint32_t buffer[256 * 4]; | |||
int main(void) | |||
{ | |||
struct caca_event ev; | |||
cucul_t *qq, *gg, *mask; | |||
caca_t *kk; | |||
struct cucul_bitmap *left, *right; | |||
@@ -61,16 +62,19 @@ int main(void) | |||
for(x = 0; ; x++) | |||
{ | |||
int ev = caca_get_event(kk, CACA_EVENT_KEY_PRESS); | |||
if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_LEFT)) | |||
gam /= 1.03; | |||
else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_RIGHT)) | |||
gam *= 1.03; | |||
else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_DOWN)) | |||
gam = 1.0; | |||
else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE)) | |||
break; | |||
int ret = caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev); | |||
if(ret) | |||
{ | |||
if(ev.data.key.c == CACA_KEY_LEFT) | |||
gam /= 1.03; | |||
else if(ev.data.key.c == CACA_KEY_RIGHT) | |||
gam *= 1.03; | |||
else if(ev.data.key.c == CACA_KEY_DOWN) | |||
gam = 1.0; | |||
else if(ev.data.key.c == CACA_KEY_ESCAPE) | |||
break; | |||
} | |||
/* Resize the spare canvas, just in case the main one changed */ | |||
cucul_set_size(gg, cucul_get_width(qq), cucul_get_height(qq)); | |||
@@ -28,6 +28,7 @@ uint32_t buffer[256*256]; | |||
int main(void) | |||
{ | |||
struct caca_event ev; | |||
cucul_t *qq; | |||
caca_t *kk; | |||
@@ -52,7 +53,7 @@ int main(void) | |||
caca_display(kk); | |||
while(!caca_get_event(kk, CACA_EVENT_KEY_PRESS)); | |||
caca_wait_event(kk, CACA_EVENT_KEY_PRESS, &ev); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
@@ -53,13 +53,13 @@ int main(int argc, char **argv) | |||
/* Go ! */ | |||
while(!quit) | |||
{ | |||
struct caca_event ev; | |||
int xa, ya, xb, yb; | |||
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: | |||
break; | |||
@@ -49,6 +49,7 @@ static char const *duck[] = | |||
int main(void) | |||
{ | |||
struct caca_event ev; | |||
cucul_t *qq, *normal, *flip, *flop, *rotate; | |||
caca_t *kk; | |||
int i; | |||
@@ -107,7 +108,7 @@ int main(void) | |||
caca_display(kk); | |||
while(!caca_get_event(kk, CACA_EVENT_KEY_PRESS)); | |||
caca_wait_event(kk, CACA_EVENT_KEY_PRESS, &ev); | |||
caca_detach(kk); | |||
cucul_free(rotate); | |||
@@ -26,6 +26,7 @@ typedef unsigned int uint32_t; | |||
int main(void) | |||
{ | |||
struct caca_event ev; | |||
cucul_t *qq; | |||
caca_t *kk; | |||
@@ -86,7 +87,7 @@ int main(void) | |||
caca_display(kk); | |||
while(!caca_get_event(kk, CACA_EVENT_KEY_PRESS)); | |||
caca_wait_event(kk, CACA_EVENT_KEY_PRESS, &ev); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||