From 3f4c8b57009b4f327e80b24f91105cddcc5c4838 Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Fri, 15 Jul 2011 18:42:28 +1000 Subject: [PATCH] MotionNotify unpack code --- lib/x11/xcore.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/x11/xcore.js b/lib/x11/xcore.js index 78b1ae4..e758c5d 100644 --- a/lib/x11/xcore.js +++ b/lib/x11/xcore.js @@ -82,6 +82,7 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs) // r is request name target[r] = (function(reqName) { var reqFunc = function req_proxy() { + client.seq_num++; // TODO: handle overflw (seq should be last 15 (?) bits of the number var args = Array.prototype.slice.call(req_proxy.arguments); // TODO: setup last argument to be reply/error callback // var callback = args.length > 0 ? null : args[args.length - 1]; @@ -127,6 +128,31 @@ XClient.prototype.AllocID = function() return (this.display.rsrc_id << this.display.rsrc_shift) + this.display.resource_base; } +XClient.prototype.unpackEvent = function(type, seq, extra, raw) +{ + var event = {}; // TODO: constructor & base functions + event.type = type; + event.seq = seq; + + if (type == 6) { // motion event + var values = raw.unpack('LLLSSSSSC'); //TODO: should be LLLLsssssSC + //event.raw = values; + // TODO: use unpackTo??? + event.time = extra; + event.root = values[0]; + event.wid = values[1]; + event.child = values[2]; + event.rootx = values[3]; + event.rooty = values[4]; + event.x = values[5]; + event.y = values[6]; + event.buttons = values[7]; + event.sameScreen = values[8]; + } + //console.log(event); + return event; +} + XClient.prototype.expectReplyHeader = function() { var client = this; @@ -147,8 +173,11 @@ XClient.prototype.expectReplyHeader = function() } else if (type > 1) { client.pack_stream.get(24, function(buf) { + var extra = res[3]; + var ev = client.unpackEvent(type, seq_num, extra, buf); + client.emit('event', ev); // TODO: dispatch, use sequence number - console.error('event!!!! ' + type); + // console.error('event!!!! ' + type); client.expectReplyHeader(); } ); return;