From 0b68bbbdb0b71d306d80195ac1560c2747942097 Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Fri, 8 Jun 2012 14:59:35 +1000 Subject: [PATCH] initial support to add event parsers from extension --- lib/x11/xcore.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/x11/xcore.js b/lib/x11/xcore.js index c3f9225..40468f6 100644 --- a/lib/x11/xcore.js +++ b/lib/x11/xcore.js @@ -24,9 +24,10 @@ function XClient(stream, displayNum, screenNum) EventEmitter.call(this); this.stream = stream; + // TODO: this is probably not used this.core_requests = {}; this.ext_requests = {}; - + this.displayNum = displayNum; this.screenNum = screenNum; this.authHost = os.hostname(); @@ -37,7 +38,7 @@ function XClient(stream, displayNum, screenNum) // read requests set by calls to .unpack and .unpackTo //stream.pipe(pack_stream); - // pack_stream write requests are buffered and + // pack_stream write requests are buffered and // flushed to stream as result of call to .flush // TODO: listen for drain event and flush automatically //pack_stream.pipe(stream); @@ -68,7 +69,8 @@ function XClient(stream, displayNum, screenNum) this.replies = {}; this.atoms = stdatoms; this.event_consumers = {}; // maps window id to eventemitter TODO: bad name - + this.eventParsers = {}; + this.importRequestsFromTemplates(this, coreRequests); this.startHandshake(); @@ -164,6 +166,12 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw) event.type = type; event.seq = seq; + var extUnpacker = this.eventParsers[type]; + if (extUnpacker) + { + return extUnpacker(type, seq, extra, code, raw); + } + if (type == 2 || type == 3 || type == 4 || type == 5 || type == 6) { // motion event var values = raw.unpack('LLLssssSC'); //event.raw = values;