# HG changeset patch # User Thinker K.F. Li # Date 1281094297 -28800 # Node ID 799c852b90658cdea918671813f0d83f3e10df93 # Parent 40ba8915edc7a3001024b3f4df147fc05832e5f8 Extract event info from C object to JS object diff -r 40ba8915edc7 -r 799c852b9065 nodejs/mbfly_njs.cc --- 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; } diff -r 40ba8915edc7 -r 799c852b9065 nodejs/observer.cc --- 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 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 func) { diff -r 40ba8915edc7 -r 799c852b9065 nodejs/observer.m4 --- 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]))) diff -r 40ba8915edc7 -r 799c852b9065 nodejs/testcase.js --- 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); + });