# HG changeset patch # User John Tsiombikas # Date 1305269061 -10800 # Node ID 0cb438c86b9822cf07b6082f0d1318a2fd446925 # Parent 0570e27e5ebc1f10245837abeb7cb7e4172702e8 X11 sounds about ready diff -r 0570e27e5ebc -r 0cb438c86b98 include/sgl.h --- a/include/sgl.h Fri May 13 07:49:47 2011 +0300 +++ b/include/sgl.h Fri May 13 09:44:21 2011 +0300 @@ -7,6 +7,16 @@ #define SGL_STEREO 8 #define SGL_MULTISAMPLE 16 +typedef void (*sgl_create_callback_t)(int); +typedef void (*sgl_close_callback_t)(int); +typedef void (*sgl_display_callback_t)(void); +typedef void (*sgl_reshape_callback_t)(int, int); +typedef void (*sgl_keyboard_callback_t)(int, int); +typedef void (*sgl_mouse_callback_t)(int, int, int, int, int); +typedef void (*sgl_motion_callback_t)(int, int, int); +typedef void (*sgl_passive_callback_t)(int, int, int); +typedef void (*sgl_idle_callback_t)(void); + enum { SGL_CREATE, SGL_CLOSE, @@ -51,4 +61,14 @@ void sgl_set_callback(int idx, void (*func)()); void (*sgl_get_callback(int idx))(); +void sgl_create_callback(sgl_create_callback_t func); +void sgl_close_callback(sgl_close_callback_t func); +void sgl_display_callback(sgl_display_callback_t func); +void sgl_reshape_callback(sgl_reshape_callback_t func); +void sgl_keyboard_callback(sgl_keyboard_callback_t func); +void sgl_mouse_callback(sgl_mouse_callback_t func); +void sgl_motion_callback(sgl_motion_callback_t func); +void sgl_passive_callback(sgl_passive_callback_t func); +void sgl_idle_callback(sgl_idle_callback_t func); + #endif /* SGL_H_ */ diff -r 0570e27e5ebc -r 0cb438c86b98 src/cb.c --- a/src/cb.c Fri May 13 07:49:47 2011 +0300 +++ b/src/cb.c Fri May 13 09:44:21 2011 +0300 @@ -64,6 +64,53 @@ return cb->func[idx]; } + +void sgl_create_callback(sgl_create_callback_t func) +{ + sgl_set_callback(SGL_CREATE, func); +} + +void sgl_close_callback(sgl_close_callback_t func) +{ + sgl_set_callback(SGL_CLOSE, func); +} + +void sgl_display_callback(sgl_display_callback_t func) +{ + sgl_set_callback(SGL_DISPLAY, func); +} + +void sgl_reshape_callback(sgl_reshape_callback_t func) +{ + sgl_set_callback(SGL_RESHAPE, func); +} + +void sgl_keyboard_callback(sgl_keyboard_callback_t func) +{ + sgl_set_callback(SGL_KEYBOARD, func); +} + +void sgl_mouse_callback(sgl_mouse_callback_t func) +{ + sgl_set_callback(SGL_MOUSE, func); +} + +void sgl_motion_callback(sgl_motion_callback_t func) +{ + sgl_set_callback(SGL_MOTION, func); +} + +void sgl_passive_callback(sgl_passive_callback_t func) +{ + sgl_set_callback(SGL_PASSIVE, func); +} + +void sgl_idle_callback(sgl_idle_callback_t func) +{ + sgl_set_callback(SGL_IDLE, func); +} + + /* notify the window system module as to which events are active */ static void notify_wsys(void) { diff -r 0570e27e5ebc -r 0cb438c86b98 src/wsys_x11.c --- a/src/wsys_x11.c Fri May 13 07:49:47 2011 +0300 +++ b/src/wsys_x11.c Fri May 13 09:44:21 2011 +0300 @@ -139,6 +139,7 @@ unsigned int attr_valid; long evmask; struct window *wnode; + void (*func)(); if(!(wnode = malloc(sizeof *wnode))) { return -1; @@ -198,7 +199,17 @@ if(!active_win) { set_active(win); + } else { + activate_window(wnode); } + + if((func = sgl_get_callback(SGL_CREATE))) { + func(win); + } + if((func = sgl_get_callback(SGL_RESHAPE))) { + func(xsz, ysz); + } + activate_window(prev_active); return win; } @@ -263,6 +274,8 @@ static void close_window(int id) { struct window dummy, *win, *prev; + sgl_close_callback_t close_func; + dummy.next = winlist; prev = &dummy; @@ -270,6 +283,9 @@ while(win) { if(win->win == id) { + if(!(close_func = sgl_get_callback(SGL_CLOSE))) { + close_func(id); + } glXDestroyContext(dpy, win->ctx); XDestroyWindow(dpy, win->win); prev->next = win->next; @@ -465,7 +481,7 @@ func = sgl_get_callback(SGL_PASSIVE); } if(func) { - func(xev->xmotion.x, xev->xmotion.y); + func(0, xev->xmotion.x, xev->xmotion.y); } break; @@ -478,7 +494,7 @@ } if((func = sgl_get_callback(SGL_MOUSE))) { int bn = xev->xbutton.button - 1; - func(bn, state, xev->xbutton.x, xev->xbutton.y); + func(0, bn, state, xev->xbutton.x, xev->xbutton.y); } break; diff -r 0570e27e5ebc -r 0cb438c86b98 tests/simple/simple.c --- a/tests/simple/simple.c Fri May 13 07:49:47 2011 +0300 +++ b/tests/simple/simple.c Fri May 13 09:44:21 2011 +0300 @@ -6,8 +6,8 @@ void disp(void); void reshape(int x, int y); void keyb(int key, int state); -void mouse(int bn, int state, int x, int y); -void motion(int x, int y); +void mouse(int pidx, int bn, int state, int x, int y); +void motion(int pidx, int x, int y); int main(void) @@ -18,11 +18,11 @@ sgl_create_window(640, 480, SGL_DOUBLE | SGL_DEPTH); - sgl_set_callback(SGL_DISPLAY, disp); - sgl_set_callback(SGL_RESHAPE, reshape); - sgl_set_callback(SGL_KEYBOARD, keyb); - sgl_set_callback(SGL_MOUSE, mouse); - sgl_set_callback(SGL_MOTION, motion); + sgl_display_callback(disp); + sgl_reshape_callback(reshape); + sgl_keyboard_callback(keyb); + sgl_mouse_callback(mouse); + sgl_motion_callback(motion); sgl_event_loop(); sgl_quit(); @@ -72,12 +72,12 @@ } } -void mouse(int bn, int state, int x, int y) +void mouse(int pidx, int bn, int state, int x, int y) { printf("mouse: button%d %s (ptr: %d %d)\n", bn, state ? "pressed" : "released", x, y); } -void motion(int x, int y) +void motion(int pidx, int x, int y) { printf("mouse dragged to: (%d %d)\n", x, y); }