initial support to add event parsers from extension

This commit is contained in:
Andrey Sidorov 2012-06-08 14:59:35 +10:00
parent 58e526d913
commit 0b68bbbdb0

View file

@ -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;