mirror of
https://github.com/brl/mutter.git
synced 2024-11-29 19:40:43 -05:00
9ef37423fc
Instead of simply relying on the emscripten mainloop api to wake us up periodically so that we can poll for SDL events we now pause the emscripten mainloop whenever no redraw is queued and instead hook an input event listener into the real browser mainloop to resume the emscripten mainloop whenever input is received. This way the example can go to sleep while there's no input to handle. This provides a simple example of binding custom javascript into native code. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit a8b1e2eda491dc7c44c84cd47e160c7b8ba0f792)
20 lines
514 B
JavaScript
20 lines
514 B
JavaScript
//"use strict";
|
|
|
|
var LibraryEXAMPLE = {
|
|
$EXAMPLE__deps: ['$Browser'],
|
|
$EXAMPLE: {
|
|
receiveEvent: function(event) {
|
|
Browser.mainLoop.resume();
|
|
},
|
|
},
|
|
example_js_add_input_listener: function() {
|
|
['mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll',
|
|
'mousewheel', 'mouseout'].forEach(function(event) {
|
|
Module['canvas'].addEventListener(event, EXAMPLE.receiveEvent, true);
|
|
});
|
|
}
|
|
};
|
|
|
|
autoAddDeps(LibraryEXAMPLE, '$EXAMPLE');
|
|
mergeInto(LibraryManager.library, LibraryEXAMPLE);
|