From a6cb1c26291cf0bac85b873ff68cb247be440b02 Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Tue, 28 Feb 2012 17:32:28 +1100 Subject: [PATCH] more event decoders --- lib/x11/xcore.js | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/lib/x11/xcore.js b/lib/x11/xcore.js index 270a11f..c8639bb 100644 --- a/lib/x11/xcore.js +++ b/lib/x11/xcore.js @@ -66,7 +66,7 @@ function XClient(stream, displayNum, screenNum) this.pack_stream = pack_stream; - this.rcrc_id = 0; // generated for each new resource + this.rsrc_id = 0; // generated for each new resource this.seq_num = 0; // incremented in each request. (even if we don't expect reply) this.seq2stack = {}; // debug: map seq_num to stack at the moment request was issued @@ -194,14 +194,45 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw) event.height = values[3]; event.count = values[4]; // TODO: ??? } else if (type == 16) { // CreateNotify - var values = raw.unpack('LLSSSSS'); + var values = raw.unpack('LLssSSSc'); event.parent = extra; event.wid = values[0]; + event.x = values[2]; + event.y = values[3]; + event.width = values[4]; + event.height = values[5]; + event.overrideRedirect = values[6] ? true : false; // x, y, width, height, border + } else if (type == 17) { // destroy notify + var values = raw.unpack('LL'); + event.wid = extra; + event.wid1 = values[0]; } else if (type == 19) { // MapNotify var values = raw.unpack('LLC'); - //event.wid = extra; + event.wid = extra; + event.wid1 = values[0]; + } else if (type == 20) { + var values = raw.unpack('LL'); + event.parent = extra; + event.wid = values[0] + } else if (type == 23) { + var values = raw.unpack('LLLssSSS'); + event.parent = extra; event.wid = values[0]; + event.x = values[1] + event.y = values[2] + event.width = values[3] + event.height = values[4] + event.borderWidth = values[5]; + // + // The value-mask indicates which components were specified in + // the request. The value-mask and the corresponding values are reported as given + // in the request. The remaining values are filled in from the current geometry of the + // window, except in the case of sibling and stack-mode, which are reported as None + // and Above (respectively) if not given in the request. + event.mask = values[6]; + // 322, [ 12582925, 0, 0, 484, 316, 1, 12, 0 + //console.log([extra, code, values]); } return event; } @@ -239,9 +270,10 @@ XClient.prototype.expectReplyHeader = function() var handler = client.replies[seq_num]; if (handler) { var callback = handler[1]; - callback(error); - if (!error.handled) + var handled = callback(error); + if (!handled) client.emit('error', error); + // TODO: should we delete seq2stack and reply even if there is no handler? delete client.seq2stack[seq_num]; delete client.replies[seq_num]; } else @@ -342,7 +374,6 @@ module.exports.createClient = function(initCb, display) // try local socket on non-windows platforms if ( ['cygwin', 'win32', 'win64'].indexOf(process.platform) < 0 ) { - console.log(['here1', display, process.platform]); if (process.platform == 'darwin' || process.platform == 'mac') { // socket path on OSX is /tmp/launch-(some id)/org.x:0 @@ -350,7 +381,7 @@ module.exports.createClient = function(initCb, display) { socketPath = display; } - } else if(host == '127.0.0.1') + } else if(host == '127.0.0.1') //TODO check if it's consistent with xlib (DISPLAY=127.0.0.1:0 -> local unix socket or port 6000?) socketPath = '/tmp/.X11-unix/X' + displayNum; } if(socketPath)