Mercurial > MadButterfly
changeset 871:67d0fed24120
Export a function to create a runtime for an existed window for JS
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Fri, 24 Sep 2010 14:09:02 +0800 |
parents | 512204bcafba |
children | bcc63b20d5c6 |
files | nodejs/X_supp_njs.c nodejs/X_supp_njs.h nodejs/mbfly_njs.cc nodejs/mbfly_njs.m4 |
diffstat | 4 files changed, 83 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/X_supp_njs.c Fri Sep 24 11:19:53 2010 +0800 +++ b/nodejs/X_supp_njs.c Fri Sep 24 14:09:02 2010 +0800 @@ -113,6 +113,22 @@ free(rt); } +/*! \brief Free njs_runtime_t. + */ +void +X_njs_MB_free_keep_win(njs_runtime_t *rt) { + /* + * stop IO and timer watcher + */ + if(rt->enable_io) + ev_io_stop(&rt->iowatcher); + if(rt->enable_timer) + ev_timer_stop(&rt->tmwatcher); + + X_MB_free_keep_win(rt->xrt); + free(rt); +} + int X_njs_MB_flush(njs_runtime_t *rt) { void *xrt = rt->xrt; @@ -141,6 +157,28 @@ return rt; } +/*! \brief Create a njs_runtime_t for an existed window. + * + * The njs_runtime_t created by this function must be free by + * X_njs_MB_free_keep_win(). + */ +njs_runtime_t * +X_njs_MB_new_with_win(void *display, long win) { + njs_runtime_t *rt; + void *xrt; + + rt = (njs_runtime_t *)malloc(sizeof(njs_runtime_t)); + ASSERT(rt != NULL); + + xrt = X_MB_new_with_win((Display *)display, win); + + rt->xrt = xrt; + rt->enable_io = 0; + rt->enable_timer = 0; /* no timer, now */ + + return rt; +} + /*! \brief Pass a X event to X runtime. */ void @@ -156,6 +194,7 @@ void X_njs_MB_no_more_event(njs_runtime_t *rt) { void *xrt = rt->xrt; + extern void _X_MB_no_more_event(void *rt); _X_MB_no_more_event(xrt); }
--- a/nodejs/X_supp_njs.h Fri Sep 24 11:19:53 2010 +0800 +++ b/nodejs/X_supp_njs.h Fri Sep 24 14:09:02 2010 +0800 @@ -16,6 +16,8 @@ extern void X_njs_MB_init_handle_connection(njs_runtime_t *rt); extern void X_njs_MB_free(njs_runtime_t *rt); extern njs_runtime_t *X_njs_MB_new(char *display_name, int w, int h); +extern void X_njs_MB_free_keep_win(njs_runtime_t *rt); +extern njs_runtime_t *X_njs_MB_new_with_win(void *display, long win); extern int X_njs_MB_flush(njs_runtime_t *rt); extern void X_njs_MB_handle_single_event(njs_runtime_t *rt, void *evt); extern void X_njs_MB_no_more_event(njs_runtime_t *rt);
--- a/nodejs/mbfly_njs.cc Fri Sep 24 11:19:53 2010 +0800 +++ b/nodejs/mbfly_njs.cc Fri Sep 24 14:09:02 2010 +0800 @@ -90,6 +90,27 @@ return obj; } +static njs_runtime_t * +_X_njs_MB_new_with_win(Handle<Object> self, void *display, + long win) { + njs_runtime_t *obj; + subject_t *subject; + Handle<Value> subject_o; + + obj = X_njs_MB_new_with_win(display, win); + WRAP(self, obj); /* mkroot need a wrapped object, but + * it is wrapped after returning of + * this function. So, we wrap it + * here. */ + xnjsmb_coord_mkroot(self); + + subject = X_njs_MB_kbevents(obj); + subject_o = export_xnjsmb_auto_subject_new(subject); + SET(self, "kbevents", subject_o); + + return obj; +} + /*! \defgroup njs_template_cb Callback functions for v8 engine and nodejs. * * @{ @@ -148,6 +169,8 @@ * Initialize template for MadButterfly runtime objects. */ xnjsmb_auto_mb_rt_init(); + xnjsmb_auto_mb_rt_display_init(); + xnjsmb_auto_mb_rt_with_win_init(); /* * Add properties to mb_rt templates for other modules. @@ -160,6 +183,8 @@ target->Set(String::New("mb_rt"), xnjsmb_auto_mb_rt_temp->GetFunction()); + target->Set(String::New("mb_rt_with_win"), + xnjsmb_auto_mb_rt_with_win_temp->GetFunction()); } /* @} */
--- a/nodejs/mbfly_njs.m4 Fri Sep 24 11:19:53 2010 +0800 +++ b/nodejs/mbfly_njs.m4 Fri Sep 24 14:09:02 2010 +0800 @@ -46,3 +46,20 @@ (), 0, [])], ((CTOR, ([_X_njs_MB_new], (SELF, STR(display_name), INT(width), INT(height)), 3)))dnl ) +dnl +dnl +dnl +STRUCT([mb_rt_display], [void], [], + [], + ())dnl +dnl +dnl Function to create mb_rt for an existed window. +dnl +STRUCT([mb_rt_with_win], [njs_runtime_t], [], + [], + ((CTOR, ([_X_njs_MB_new_with_win],dnl + (SELF, OBJ([display], [mb_rt_display], [void]),dnl + INT([window])),dnl + 2)),dnl + ([INHERIT], [mb_rt]))dnl +)