Mercurial > MadButterfly
changeset 679:799c852b9065
Extract event info from C object to JS object
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 06 Aug 2010 19:31:37 +0800 |
parents | 40ba8915edc7 |
children | a588eefd3f04 |
files | nodejs/mbfly_njs.cc nodejs/observer.cc nodejs/observer.m4 nodejs/testcase.js |
diffstat | 4 files changed, 54 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/mbfly_njs.cc Fri Aug 06 19:30:52 2010 +0800 +++ b/nodejs/mbfly_njs.cc Fri Aug 06 19:31:37 2010 +0800 @@ -87,6 +87,10 @@ subject_o = export_xnjsmb_auto_subject_new(subject); SET(root_o, "subject", subject_o); + subject = X_MB_kbevents(obj->xrt); + subject_o = export_xnjsmb_auto_subject_new(subject); + SET(self, "kbevent", subject_o); + return obj; }
--- a/nodejs/observer.cc Fri Aug 06 19:30:52 2010 +0800 +++ b/nodejs/observer.cc Fri Aug 06 19:31:37 2010 +0800 @@ -19,6 +19,44 @@ static void event_handler(event_t *evt, void *arg); +static void +xnjsmb_event_mod(Handle<Object> self, event_t *evt) { + mouse_event_t *mevt; + X_kb_event_t *xkbevt; + + switch(evt->type) { + case EVT_ANY: + case EVT_MOUSE_OVER: + case EVT_MOUSE_OUT: + case EVT_MOUSE_MOVE: + case EVT_MOUSE_BUT_PRESS: + case EVT_MOUSE_BUT_RELEASE: + mevt = (mouse_event_t *)evt; + SET(self, "x", Integer::New(mevt->x)); + SET(self, "y", Integer::New(mevt->y)); + SET(self, "but_state", Integer::New(mevt->but_state)); + SET(self, "button", Integer::New(mevt->button)); + break; + + case EVT_KB_PRESS: + case EVT_KB_RELEASE: + xkbevt = (X_kb_event_t *)evt; + SET(self, "keycode", Integer::New(xkbevt->keycode)); + SET(self, "sym", Integer::New(xkbevt->sym)); + break; + + case EVT_PROGM_COMPLETE: + case EVT_RDMAN_REDRAW: + case EVT_MONITOR_ADD: + case EVT_MONITOR_REMOVE: + case EVT_MONITOR_FREE: + case EVT_MOUSE_MOVE_RAW: + default: + /* Not implemented. Do nothing. */ + break; + } +} + static observer_t * _subject_add_event_observer(subject_t *subject, int type, Handle<Function> func) {
--- a/nodejs/observer.m4 Fri Aug 06 19:30:52 2010 +0800 +++ b/nodejs/observer.m4 Fri Aug 06 19:31:37 2010 +0800 @@ -1,5 +1,5 @@ -define([PROJ_PREFIX], [xnjsmb_auto_]) - +define([PROJ_PREFIX], [xnjsmb_auto_])dnl +dnl STRUCT([observer], [observer_t], [INT([type])], []) @@ -15,4 +15,4 @@ ACCESSOR([tgt], [xnjsmb_event_tgt_getter], [xnjsmb_event_tgt_setter]), ACCESSOR([cur_tgt], [xnjsmb_event_cur_tgt_getter], [xnjsmb_event_cur_tgt_setter]), - INT([flags])], []) + INT([flags])], [], (([STMOD], [xnjsmb_event_mod])))
--- a/nodejs/testcase.js Fri Aug 06 19:30:52 2010 +0800 +++ b/nodejs/testcase.js Fri Aug 06 19:31:37 2010 +0800 @@ -55,6 +55,13 @@ sys.puts(root.subject); var observer; /* Mouse button pressed */ -observer = root.subject.add_event_observer(4, function() { - sys.puts("mouse"); +observer = root.subject.add_event_observer(4, function(evt) { + sys.puts("mouse " + evt.x + " " + evt.y); }); + +var kbobserver; +/* Keyboard event */ +kbobserver = mb_rt.kbevent.add_event_observer(6, function(evt) { + sys.puts("keycode = " + evt.keycode); + sys.puts("sym = " + evt.sym); + });