From e5e4eac0e525ae66cb7f93e1b24ebe6448db753f Mon Sep 17 00:00:00 2001 From: champii Date: Sat, 30 Aug 2014 08:31:54 +0200 Subject: [PATCH 01/14] Added CreateCursor Method --- lib/corereqs.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/corereqs.js b/lib/corereqs.js index 49f1a24..dee0b0a 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -651,6 +651,20 @@ var templates = { } ], + CreateCursor: [ + function(cid, source, mask, foreRGB, backRGB, x, y) { + foreR = foreRGB.R + foreG = foreRGB.G + foreB = foreRGB.B + + backR = backRGB.R + backG = backRGB.G + backB = backRGB.B + return [ 'CxSLLLSSSSSSSS', [93, , cid, source, mask, foreR, foreG, foreB, backR, backG, backB, x, y] ]; + } + ], + + // opcode 55 CreateGC: [ function(cid, drawable, values) { var format = 'CxSLLL'; From 965b5ca99735828727ce512cb1b1bbd24db5d60e Mon Sep 17 00:00:00 2001 From: champii Date: Sat, 30 Aug 2014 08:37:18 +0200 Subject: [PATCH 02/14] Test --- lib/corereqs.js | 2 +- lib/xcore.js | 91 +++++++++++++++++++++++++------------------------ 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/lib/corereqs.js b/lib/corereqs.js index dee0b0a..9d80f4c 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -660,7 +660,7 @@ var templates = { backR = backRGB.R backG = backRGB.G backB = backRGB.B - return [ 'CxSLLLSSSSSSSS', [93, , cid, source, mask, foreR, foreG, foreB, backR, backG, backB, x, y] ]; + return [ 'CxSLLLSSSSSSSS', [93, 8, cid, source, mask, foreR, foreG, foreB, backR, backG, backB, x, y] ]; } ], diff --git a/lib/xcore.js b/lib/xcore.js index 9194b55..964ff0f 100644 --- a/lib/xcore.js +++ b/lib/xcore.js @@ -29,7 +29,7 @@ function XClient(stream, displayNum, screenNum, options) // TODO: this is probably not used this.core_requests = {}; this.ext_requests = {}; - + this.displayNum = displayNum; this.screenNum = screenNum; this.authHost = os.hostname(); @@ -39,10 +39,10 @@ function XClient(stream, displayNum, screenNum, options) // data received from stream is dispached to // read requests set by calls to .unpack and .unpackTo //stream.pipe(pack_stream); - + // pack_stream write requests are buffered and // flushed to stream as result of call to .flush - // TODO: listen for drain event and flush automatically + // TODO: listen for drain event and flush automatically //pack_stream.pipe(stream); var client = this; pack_stream.on('data', function( data ) { @@ -55,7 +55,7 @@ function XClient(stream, displayNum, screenNum, options) //console.error(hexy(data, {prefix: 'to unpacker '})); //for (var i=0; i < data.length; ++i) // console.log('>>> ' + data[i]); - pack_stream.write(data); + pack_stream.write(data); }); stream.on('end', function() { client.emit('end'); @@ -67,7 +67,7 @@ function XClient(stream, displayNum, screenNum, options) var cli = this; if (cli.options.debug) { this.seq_num_ = 0; - this.seq2stack = {}; // debug: map seq_num to stack at the moment request was issued + this.seq2stack = {}; // debug: map seq_num to stack at the moment request was issued Object.defineProperty(cli, "seq_num", { set : function(v) { cli.seq_num_ = v; @@ -84,7 +84,7 @@ function XClient(stream, displayNum, screenNum, options) this.seq_num = 0; } - + // in/out packets indexed by sequence ID this.replies = {}; this.atoms = stdatoms; @@ -96,15 +96,15 @@ function XClient(stream, displayNum, screenNum, options) return names; })(); - + this.eventMask = em; - + this.event_consumers = {}; // maps window id to eventemitter TODO: bad name - this.eventParsers = {}; - this.errorParsers = {}; + this.eventParsers = {}; + this.errorParsers = {}; this.importRequestsFromTemplates(this, coreRequests); - + this.startHandshake(); this._closing = false; } @@ -142,21 +142,22 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs) this.pending_atoms = {}; for (var r in reqs) { + console.log(r); // r is request name - target[r] = (function(reqName) { - + target[r] = (function(reqName) { + var reqFunc = function req_proxy() { - + if (client._closing) throw new Error('client is in closing state'); - + // simple overflow handling (this means that currently there is no way to have more than 65535 requests in the queue - // TODO: edge cases testing + // TODO: edge cases testing if (client.seq_num == 65535) client.seq_num = 0; else client.seq_num++; - + // is it fast? var args = Array.prototype.slice.call(req_proxy.arguments); @@ -185,20 +186,20 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs) client.pending_atoms[client.seq_num] = value; } } - + // call template with input arguments (not including callback which is last argument TODO currently with callback. won't hurt) //reqPack = reqTemplate.call(args); - var reqPack = reqTemplate.apply(this, req_proxy.arguments); + var reqPack = reqTemplate.apply(this, req_proxy.arguments); var format = reqPack[0]; var requestArguments = reqPack[1]; if (callback) this.replies[this.seq_num] = [reqReplTemplate[1], callback]; - + client.pack_stream.pack(format, requestArguments); var b = client.pack_stream.write_queue[0]; client.pack_stream.flush(); - + } else if (templateType == 'Array'){ if (reqName === 'GetAtomName') { var atom = req_proxy.arguments[0]; @@ -211,12 +212,12 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs) client.pending_atoms[client.seq_num] = atom; } } - + var format = reqTemplate[0]; var requestArguments = []; for (var a = 0; a < reqTemplate[1].length; ++a) - requestArguments.push(reqTemplate[1][a]); + requestArguments.push(reqTemplate[1][a]); for (var a in args) requestArguments.push(args[a]); @@ -249,8 +250,8 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf) var event = {}; // TODO: constructor & base functions // Remove the most significant bit. See Chapter 1, Event Format section in X11 protocol // specification - type = type & 0x7F; - event.type = type; + type = type & 0x7F; + event.type = type; event.seq = seq; var extUnpacker = this.eventParsers[type]; @@ -265,7 +266,7 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf) // TODO: use unpackTo??? event.name = [,,'KeyPress', 'KeyRelease', 'ButtonPress', 'ButtonRelease', 'MotionNotify'][type] event.time = extra; - event.keycode = code; + event.keycode = code; event.root = values[0]; event.wid = values[1]; event.child = values[2]; @@ -352,13 +353,13 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf) 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]; + event.mask = values[6]; // 322, [ 12582925, 0, 0, 484, 316, 1, 12, 0 //console.log([extra, code, values]); } else if (type == 28) {// PropertyNotify @@ -398,7 +399,7 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf) event.type = raw.readUInt32LE(0); var format = (code === 32) ? 'LLLLL' : (code === 16) ? 'SSSSSSSSSS' : 'CCCCCCCCCCCCCCCCCCCC'; event.data = raw.unpack(format, 4); - } else if (type == 34) { + } else if (type == 34) { event.name = 'MappingNotify'; event.request = headerBuf[4]; event.firstKeyCode = headerBuf[5]; @@ -421,7 +422,7 @@ XClient.prototype.expectReplyHeader = function() var bad_value = res[3]; if (type == 0) - { + { var error_code = res[1]; var error = new Error(); error.error = error_code; @@ -433,7 +434,7 @@ XClient.prototype.expectReplyHeader = function() // unpack error packet (32 bytes for all error types, 8 of them in CCSL header) client.pack_stream.get(24, function(buf) { - + var res = buf.unpack('SC'); error.message = xerrors.errorText[error_code]; error.badParam = bad_value; @@ -444,7 +445,7 @@ XClient.prototype.expectReplyHeader = function() if (extUnpacker) { extUnpacker(error, error_code, seq_num, bad_value, buf); } - + var handler = client.replies[seq_num]; if (handler) { var callback = handler[1]; @@ -458,7 +459,7 @@ XClient.prototype.expectReplyHeader = function() } else client.emit('error', error); client.expectReplyHeader(); - } ); + } ); return; } else if (type > 1) { @@ -466,20 +467,20 @@ XClient.prototype.expectReplyHeader = function() var extra = res[3]; var code = res[1]; var ev = client.unpackEvent(type, seq_num, extra, code, buf, headerBuf); - + // raw event 32-bytes packet (primarily for use in SendEvent); // TODO: Event::pack based on event parameters, inverse to unpackEvent ev.rawData = new Buffer(32); headerBuf.copy(ev.rawData); buf.copy(ev.rawData, 8); - + client.emit('event', ev); var ee = client.event_consumers[ev.wid]; if (ee) { ee.emit('event', ev); } client.expectReplyHeader(); - } ); + } ); return; } @@ -488,7 +489,7 @@ XClient.prototype.expectReplyHeader = function() var bodylength = 24 + length_total*4; // 24 is rest if 32-bytes header client.pack_stream.get( bodylength, function( data ) { - + var handler = client.replies[seq_num]; if (handler) { var unpack = handler[0]; @@ -504,8 +505,8 @@ XClient.prototype.expectReplyHeader = function() } // wait for new packet from server client.expectReplyHeader(); - }); - } + }); + } ); } @@ -514,7 +515,7 @@ XClient.prototype.startHandshake = function() var client = this; handshake.writeClientHello(this.pack_stream, this.displayNum, this.authHost); - handshake.readServerHello(this.pack_stream, function(display) + handshake.readServerHello(this.pack_stream, function(display) { // TODO: readServerHello can set error state in display // emit error in that case @@ -522,7 +523,7 @@ XClient.prototype.startHandshake = function() client.display = display; display.client = client; client.emit('connect', display); - }); + }); } XClient.prototype.require = function(extName, callback) @@ -558,7 +559,7 @@ module.exports.createClient = function(options, initCb) var screenNum = displayMatch[3]; if (!screenNum) screenNum = 0; - + // open stream var stream; var socketPath; @@ -569,13 +570,13 @@ module.exports.createClient = function(options, initCb) if (process.platform == 'darwin' || process.platform == 'mac') { // socket path on OSX is /tmp/launch-(some id)/org.x:0 - if (display[0] == '/') + if (display[0] == '/') { socketPath = display; - } + } } 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; - } + } //socketPath = '/tmp/.X11-unix/X' + displayNum; if(socketPath) { From 643c004fb5605f26c638a5ab7adb5235017d2245 Mon Sep 17 00:00:00 2001 From: champii Date: Sat, 30 Aug 2014 09:48:08 +0200 Subject: [PATCH 03/14] removed log --- lib/xcore.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/xcore.js b/lib/xcore.js index 964ff0f..97e3fdd 100644 --- a/lib/xcore.js +++ b/lib/xcore.js @@ -142,7 +142,6 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs) this.pending_atoms = {}; for (var r in reqs) { - console.log(r); // r is request name target[r] = (function(reqName) { From 2e2a87f6ff23e50a1f42c4bdec5c2748d34e20f5 Mon Sep 17 00:00:00 2001 From: champii Date: Sat, 30 Aug 2014 21:22:58 +0200 Subject: [PATCH 04/14] trying to use PutImage --- lib/corereqs.js | 3 ++- lib/xcore.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/corereqs.js b/lib/corereqs.js index 9d80f4c..d207cf5 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -775,7 +775,8 @@ var templates = { // TODO: move code to calculate reqLength and use BigReq if needed outside of corereq.js // NOTE: big req is used here (first 'L' in format, 0 and +1 in params), won't work if not enabled - return [ 'CCSLLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; + return [ 'CCSLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; + // return [ 'CCSLLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; } ], diff --git a/lib/xcore.js b/lib/xcore.js index 97e3fdd..6ccfefe 100644 --- a/lib/xcore.js +++ b/lib/xcore.js @@ -592,6 +592,7 @@ module.exports.createClient = function(options, initCb) client.on('connect', function(display) { // opt-in BigReq if (!options.disableBigRequests) { + console.log('Enable Big Requests') client.require('big-requests', function(BigReq) { BigReq.Enable(function(err, maxLen) { display.max_request_length = maxLen; From 21002831a034d582385eeb231b7e9feba5009fbe Mon Sep 17 00:00:00 2001 From: champii Date: Sat, 30 Aug 2014 21:29:44 +0200 Subject: [PATCH 05/14] trying to use PutImage --- lib/corereqs.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/corereqs.js b/lib/corereqs.js index d207cf5..9d80f4c 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -775,8 +775,7 @@ var templates = { // TODO: move code to calculate reqLength and use BigReq if needed outside of corereq.js // NOTE: big req is used here (first 'L' in format, 0 and +1 in params), won't work if not enabled - return [ 'CCSLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; - // return [ 'CCSLLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; + return [ 'CCSLLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; } ], From 793b551b7a320182d932ee6d06d579068e1d4328 Mon Sep 17 00:00:00 2001 From: champii Date: Mon, 1 Sep 2014 07:49:14 +0200 Subject: [PATCH 06/14] fixed putImage --- lib/corereqs.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/corereqs.js b/lib/corereqs.js index 9d80f4c..4ee6bb2 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -775,7 +775,8 @@ var templates = { // TODO: move code to calculate reqLength and use BigReq if needed outside of corereq.js // NOTE: big req is used here (first 'L' in format, 0 and +1 in params), won't work if not enabled - return [ 'CCSLLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; + return [ 'CCSLLLSSssCCxxaa', [72, format, 0, reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; + // return [ 'CCSLLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; } ], From 3b6f692d54c634d1a40549b8a82705bb11cd02ee Mon Sep 17 00:00:00 2001 From: champii Date: Wed, 3 Sep 2014 01:10:31 +0200 Subject: [PATCH 07/14] Trying to fix PutImage BadLength --- lib/corereqs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/corereqs.js b/lib/corereqs.js index 4ee6bb2..b798f9a 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -775,7 +775,7 @@ var templates = { // TODO: move code to calculate reqLength and use BigReq if needed outside of corereq.js // NOTE: big req is used here (first 'L' in format, 0 and +1 in params), won't work if not enabled - return [ 'CCSLLLSSssCCxxaa', [72, format, 0, reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; + return [ 'CCSLLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; // return [ 'CCSLLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; } ], @@ -791,7 +791,7 @@ var templates = { return { depth: depth, visualId: visualId, - data: buf.slice(20) + data: buf.slice(24) }; } ], From 48f132b3febee7ebfbd18971d16818b01bbb7a4c Mon Sep 17 00:00:00 2001 From: champii Date: Sat, 6 Sep 2014 07:51:32 +0200 Subject: [PATCH 08/14] ConfigureWindow, CreateWindow and CreateGC now give good format size to buffer, fixed some tests --- lib/corereqs.js | 350 +++++++++++++++++++++++---------------- lib/xcore.js | 1 - test/configure-window.js | 12 +- 3 files changed, 215 insertions(+), 148 deletions(-) diff --git a/lib/corereqs.js b/lib/corereqs.js index b798f9a..550c482 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -6,70 +6,207 @@ var hexy = require('./hexy').hexy; var valueMask = { CreateWindow: { - backgroundPixmap: 0x00000001, - backgroundPixel : 0x00000002, - borderPixmap : 0x00000004, - borderPixel : 0x00000008, - bitGravity : 0x00000010, - winGravity : 0x00000020, - backingStore : 0x00000040, - backingPlanes : 0x00000080, - backingPixel : 0x00000100, - overrideRedirect: 0x00000200, - saveUnder : 0x00000400, - eventMask : 0x00000800, - doNotPropagateMask: 0x00001000, - colormap : 0x00002000, - cursor : 0x00004000 + backgroundPixmap : { + mask: 0x00000001, + format: 'L' + }, + backgroundPixel : { + mask: 0x00000002, + format: 'L' + }, + borderPixmap : { + mask: 0x00000004, + format: 'L' + }, + borderPixel : { + mask: 0x00000008, + format: 'L' + }, + bitGravity : { + mask: 0x00000010, + format: 'C' + }, + winGravity : { + mask: 0x00000020, + format: 'C' + }, + backingStore : { + mask: 0x00000040, + format: 'C' + }, + backingPlanes : { + mask: 0x00000080, + format: 'L' + }, + backingPixel : { + mask: 0x00000100, + format: 'L' + }, + overrideRedirect : { + mask: 0x00000200, + format: 'C' + }, + saveUnder : { + mask: 0x00000400, + format: 'C' + }, + eventMask : { + mask: 0x00000800, + format: 'L' + }, + doNotPropagateMask : { + mask: 0x00001000, + format: 'L' + }, + colormap : { + mask: 0x00002000, + format: 'L' + }, + cursor : { + mask: 0x00004000, + format: 'L' + } }, CreateGC: { - 'function' : 0x00000001, // TODO: alias? _function? - planeMask : 0x00000002, - foreground : 0x00000004, - background : 0x00000008, - lineWidth : 0x00000010, - lineStyle : 0x00000020, - capStyle : 0x00000040, - joinStyle : 0x00000080, - fillStyle : 0x00000100, - fillRule : 0x00000200, - tile : 0x00000400, - stipple : 0x00000800, - tileStippleXOrigin: 0x00001000, - tileStippleYOrigin: 0x00002000, - font : 0x00004000, - subwindowMode: 0x00008000, - graphicsExposures: 0x00010000, - clipXOrigin : 0x00020000, - clipYOrigin : 0x00040000, - clipMask : 0x00080000, - dashOffset : 0x00100000, - dashes : 0x00200000, - arcMode : 0x00400000 + 'function' : { // TODO: alias? _function? + mask: 0x00000001, + format: 'C' + }, + planeMask : { + mask: 0x00000002, + format: 'L' + }, + foreground : { + mask: 0x00000004, + format: 'L' + }, + background : { + mask: 0x00000008, + format: 'L' + }, + lineWidth : { + mask: 0x00000010, + format: 'S' + }, + lineStyle : { + mask: 0x00000020, + format: 'C' + }, + capStyle : { + mask: 0x00000040, + format: 'C' + }, + joinStyle : { + mask: 0x00000080, + format: 'C' + }, + fillStyle : { + mask: 0x00000100, + format: 'C' + }, + fillRule : { + mask: 0x00000200, + format: 'C' + }, + tile : { + mask: 0x00000400, + format: 'L' + }, + stipple : { + mask: 0x00000800, + format: 'L' + }, + tileStippleXOrigin : { + mask: 0x00001000, + format: 's' + }, + tileStippleYOrigin : { + mask: 0x00002000, + format: 's' + }, + font : { + mask: 0x00004000, + format: 'L' + }, + subwindowMode : { + mask: 0x00008000, + format: 'C' + }, + graphicsExposures : { + mask: 0x00010000, + format: 'C' + }, + clipXOrigin : { + mask: 0x00020000, + format: 'S' + }, + clipYOrigin : { + mask: 0x00040000, + format: 'S' + }, + clipMask : { + mask: 0x00080000, + format: 'L' + }, + dashOffset : { + mask: 0x00100000, + format: 'S' + }, + dashes : { + mask: 0x00200000, + format: 'C' + }, + arcMode : { + mask: 0x00400000, + format: 'C' + } }, ConfigureWindow: { - x: 0x000001, - y: 0x000002, - width: 0x000004, - height: 0x000008, - borderWidth: 0x000010, - sibling: 0x000020, - stackMode: 0x000040 + x : { + mask: 0x000001, + format: 'sxx' + }, + y : { + mask: 0x000002, + format: 'sxx' + }, + width : { + mask: 0x000004, + format: 'Sxx' + }, + height : { + mask: 0x000008, + format: 'Sxx' + }, + borderWidth : { + mask: 0x000010, + format: 'Sxx' + }, + sibling : { + mask: 0x000020, + format: 'L' + }, + stackMode : { + mask: 0x000040, + format: 'Cxx' + } } }; + var valueMaskName = {}; for (var req in valueMask) { var masks = valueMask[req]; var names = valueMaskName[req] = {}; for (var m in masks) - names[masks[m]] = m; + names[masks[m].mask] = m; } function packValueMask(reqname, values) { var bitmask = 0; var masksList = []; + var format = ''; var reqValueMask = valueMask[reqname]; var reqValueMaskName = valueMaskName[reqname]; @@ -78,7 +215,7 @@ function packValueMask(reqname, values) for (var v in values) { - var valueBit = reqValueMask[v]; + var valueBit = reqValueMask[v].mask; if (!valueBit) throw new Error(reqname + ': incorrect value param ' + v); masksList.push(valueBit); @@ -89,9 +226,10 @@ function packValueMask(reqname, values) for (m in masksList) { var valueName = reqValueMaskName[masksList[m]]; + format += reqValueMask[valueName].format args.push( values[valueName] ); } - return [bitmask, args] + return [format, bitmask, args] } /* @@ -135,8 +273,6 @@ var templates = { var packetLength = 8 + (values ? Object.keys(values).length : 0); var format = 'CCSLLssSSSSLL'; - // create bitmask - var bitmask = 0; // TODO: slice from function arguments? var args = [1, depth, packetLength, id, parentId, x, y, width, height, borderWidth, _class, visual]; @@ -145,32 +281,10 @@ var templates = { // bitmask (bytes #24 to #31 in the packet) - 32 bit indicating what adittional arguments we supply // values list (bytes #32 .. #32+4*num_values) in order of corresponding bits TODO: it's actually not 4*num. Some values are 4b ytes, some - 1 byte - - // TODO: replace with packValueMask - var masksList = []; - for (var v in values) - { - var valueBit = valueMask['CreateWindow'][v]; - if (!valueBit) - { - throw new Error('CreateWindow: incorrect value param ' + v); - } - masksList.push(valueBit); - bitmask |= valueBit; - format += 'L'; // TODO: not all values are 4 bytes CARD32!!! - } - // values packed in order of corresponding bit - masksList.sort(); - // set bits to indicate additional values we are sending in this request - args.push(bitmask); - - // add values in the order of the bits - // TODO: maybe it's better just to scan all 32 bits anstead of sorting parameters we are actually have? - for (var m in masksList) - { - var valueName = valueMaskName['CreateWindow'][masksList[m]]; - args.push( values[valueName] ); - } + var vals = packValueMask('CreateWindow', values); + format += vals[0]; + args.push(vals[1]); + args = args.concat(vals[2]); return [format, args]; } @@ -181,13 +295,10 @@ var templates = { var format = 'CxSLL'; var packetLength = 3 + (values ? Object.keys(values).length : 0); var vals = packValueMask('CreateWindow', values); - var args = [2, packetLength, wid, vals[0]]; - var valArr = vals[1]; - for (var v in valArr) - { - format += 'L'; - args.push(valArr[v]); - } + var args = [2, packetLength, wid, vals[1]]; + var valArr = vals[2]; + format += vals[0]; + args = args.concat(valArr); return [format, args]; } ], @@ -248,60 +359,13 @@ var templates = { * } */ function(win, options) { - var format = 'CxSLSxx'; - var n = 3; - var mask = 0; - var params = []; - if (options.x !== undefined) { - mask |= valueMask.ConfigureWindow.x; - format += 'sxx'; - params.push(options.x); - ++ n; - } + var vals = packValueMask('ConfigureWindow', options); + var format = 'CxSLL' + vals[0]; + var params = [12, Object.keys(options).length + 3, win, vals[1]]; - if (options.y !== undefined) { - mask |= valueMask.ConfigureWindow.y; - format += 'sxx'; - params.push(options.y); - ++ n; - } + params = params.concat(vals[2]); - if (options.width !== undefined) { - mask |= valueMask.ConfigureWindow.width; - format += 'Sxx'; - params.push(options.width); - ++ n; - } - - if (options.height !== undefined) { - mask |= valueMask.ConfigureWindow.height; - format += 'Sxx'; - params.push(options.height); - ++ n; - } - - if (options.borderWidth !== undefined) { - mask |= valueMask.ConfigureWindow.borderWidth; - format += 'Sxx'; - params.push(options.borderWidth); - ++ n; - } - - if (options.sibling !== undefined) { - mask |= valueMask.ConfigureWindow.sibling; - format += 'L'; - params.push(options.sibling); - ++ n; - } - - if (options.stackMode !== undefined) { - mask |= valueMask.ConfigureWindow.stackMode; - format += 'Cxxx'; - params.push(options.stackMode); - ++ n; - } - - return [format, [12, n, win, mask].concat(params)]; + return [format, params]; } ], @@ -671,13 +735,15 @@ var templates = { var packetLength = 4 + (values ? Object.keys(values).length : 0); var args = [55, packetLength, cid, drawable]; var vals = packValueMask('CreateGC', values); - args.push(vals[0]); // values bitmask - var valArr = vals[1]; - for (var v in valArr) - { - format += 'L'; // TODO: we know format string length in advance and += inefficient for string - args.push(valArr[v]); - } + format += vals[0] + args.push(vals[1]); // values bitmask + args = args.concat(vals[2]) + // var valArr = vals[2]; + // for (var v in valArr) + // { + // format += 'L'; // TODO: we know format string length in advance and += inefficient for string + // args.push(valArr[v]); + // } return [format, args]; } ], diff --git a/lib/xcore.js b/lib/xcore.js index 6ccfefe..97e3fdd 100644 --- a/lib/xcore.js +++ b/lib/xcore.js @@ -592,7 +592,6 @@ module.exports.createClient = function(options, initCb) client.on('connect', function(display) { // opt-in BigReq if (!options.disableBigRequests) { - console.log('Enable Big Requests') client.require('big-requests', function(BigReq) { BigReq.Enable(function(err, maxLen) { display.max_request_length = maxLen; diff --git a/test/configure-window.js b/test/configure-window.js index cc6c9f7..c65c819 100644 --- a/test/configure-window.js +++ b/test/configure-window.js @@ -22,34 +22,35 @@ describe('ConfigureWindow', function() { }); }); - client.on('error', done); + client.on('error', function (err) { + console.error('Error : ', err); + }); }); it('should ResizeWindow correctly to 200x300 pixels', function(done) { var self = this; - this.X.ResizeWindow(this.wid, 200, 300); this.X.once('event', function(ev) { ev.type.should.equal(22); /* ConfigureNotify */ ev.height.should.equal(300); ev.width.should.equal(200); done(); }); + this.X.ResizeWindow(this.wid, 200, 300); }); it('should MoveWindow correctly to x: 100, y: 150 pixels', function(done) { var self = this; - this.X.MoveWindow(this.wid, 100, 150); this.X.once('event', function(ev) { ev.type.should.equal(22); /* ConfigureNotify */ ev.x.should.equal(100); ev.y.should.equal(150); done(); }); + this.X.MoveWindow(this.wid, 100, 150); }); it('should MoveResizeWindow correctly to x: 200, y: 250 and 500x100 pixels', function(done) { var self = this; - this.X.MoveResizeWindow(this.wid, 200, 250, 500, 100); this.X.once('event', function(ev) { ev.type.should.equal(22); /* ConfigureNotify */ ev.x.should.equal(200); @@ -58,16 +59,17 @@ describe('ConfigureWindow', function() { ev.width.should.equal(500); done(); }); + this.X.MoveResizeWindow(this.wid, 200, 250, 500, 100); }); it('should RaiseWindow correctly', function(done) { var self = this; - this.X.RaiseWindow(this.wid); this.X.once('event', function(ev) { ev.type.should.equal(22); /* ConfigureNotify */ ev.aboveSibling.should.equal(self.wid_helper); done(); }); + this.X.RaiseWindow(this.wid); }); after(function(done) { From d46d43a22e915a7dea9e3ff3576db69ef8886ee0 Mon Sep 17 00:00:00 2001 From: champii Date: Mon, 8 Sep 2014 08:54:05 +0200 Subject: [PATCH 09/14] Trying to fix tests --- lib/corereqs.js | 18 +++++++++++------- lib/ext/composite.js | 19 +++++++++++-------- test/configure-window.js | 9 ++++++++- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/lib/corereqs.js b/lib/corereqs.js index 550c482..7111b03 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -188,7 +188,7 @@ var valueMask = { }, stackMode : { mask: 0x000040, - format: 'Cxx' + format: 'Cxxx' } } }; @@ -285,6 +285,7 @@ var templates = { format += vals[0]; args.push(vals[1]); args = args.concat(vals[2]); + // console.log('CreateWindow', format, args); return [format, args]; } @@ -292,13 +293,14 @@ var templates = { ChangeWindowAttributes:[ function(wid, values) { - var format = 'CxSLL'; + var format = 'CxSLSxx'; var packetLength = 3 + (values ? Object.keys(values).length : 0); var vals = packValueMask('CreateWindow', values); var args = [2, packetLength, wid, vals[1]]; var valArr = vals[2]; format += vals[0]; args = args.concat(valArr); + // console.log('ChangeWindowAttributes', format, args); return [format, args]; } ], @@ -360,12 +362,13 @@ var templates = { */ function(win, options) { var vals = packValueMask('ConfigureWindow', options); - var format = 'CxSLL' + vals[0]; - var params = [12, Object.keys(options).length + 3, win, vals[1]]; + var format = 'CxSLSxx' + vals[0]; + var args = [12, Object.keys(options).length + 3, win, vals[1]]; - params = params.concat(vals[2]); + args = args.concat(vals[2]); - return [format, params]; + // console.log('ConfigureWindow', format, args); + return [format, args]; } ], @@ -476,7 +479,7 @@ var templates = { }, function(buf, format) { - var res = buf.unpack('LLL'); + var res = buf.unpack('LLL'); var prop = {}; prop.type = res[0]; prop.bytesAfter = res[1]; @@ -744,6 +747,7 @@ var templates = { // format += 'L'; // TODO: we know format string length in advance and += inefficient for string // args.push(valArr[v]); // } + console.log('CreateGC', format, args); return [format, args]; } ], diff --git a/lib/ext/composite.js b/lib/ext/composite.js index 7e739de..ea1cd88 100644 --- a/lib/ext/composite.js +++ b/lib/ext/composite.js @@ -14,15 +14,15 @@ var x11 = require('..'); // TODO: move to templates -exports.requireExt = function(display, callback) +exports.requireExt = function(display, callback) { var X = display.client; - X.QueryExtension('Composite', function(err, ext) { + X.QueryExtension('Composite', function(err, ext) { if (!ext.present) return callback(new Error('extension not available')); - ext.Redirect = { + ext.Redirect = { Automatic: 0, Manual: 1 }; @@ -33,7 +33,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]); X.replies[X.seq_num] = [ function(buf, opt) { - var res = buf.unpack('LL'); + var res = buf.unpack('LL'); return res; }, callback @@ -82,7 +82,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('CCSLL', [ext.majorOpcode, 6, 3, window, pixmap]); X.pack_stream.flush(); } - + ext.GetOverlayWindow = function(window, callback) { X.seq_num++; @@ -96,19 +96,22 @@ exports.requireExt = function(display, callback) ]; X.pack_stream.flush(); } - + ext.ReleaseOverlayWindow = function(window) { X.seq_num++; X.pack_stream.pack('CCSL', [ext.majorOpcode, 8, 2, window]); X.pack_stream.flush(); } - + // currently version 0.4 TODO: bump up with coordinate translations ext.QueryVersion(0, 4, function(err, vers) { + if (err) + return callback(err); + ext.major = vers[0]; ext.minor = vers[1]; - callback(ext); + callback(null, ext); }); }); } diff --git a/test/configure-window.js b/test/configure-window.js index c65c819..012b504 100644 --- a/test/configure-window.js +++ b/test/configure-window.js @@ -13,6 +13,12 @@ describe('ConfigureWindow', function() { self.wid_helper = self.X.AllocID(); self.X.CreateWindow(self.wid, dpy.screen[0].root, 0, 0, 1, 1); // 1x1 pixel window self.X.CreateWindow(self.wid_helper, dpy.screen[0].root, 0, 0, 1, 1); // 1x1 pixel window + + + // self.X.ConfigureWindow(self.wid, { stackMode: 1 }); + // self.X.ConfigureWindow(self.wid_helper, { stackMode: 1 }); + + self.X.QueryTree(dpy.screen[0].root, function(err, list) { should.not.exist(err); list.children.indexOf(self.wid).should.not.equal(-1); @@ -65,6 +71,7 @@ describe('ConfigureWindow', function() { it('should RaiseWindow correctly', function(done) { var self = this; this.X.once('event', function(ev) { + console.log(ev); ev.type.should.equal(22); /* ConfigureNotify */ ev.aboveSibling.should.equal(self.wid_helper); done(); @@ -75,7 +82,7 @@ describe('ConfigureWindow', function() { after(function(done) { this.X.DestroyWindow(this.wid); this.X.DestroyWindow(this.wid_helper); - this.X.terminate(); this.X.on('end', done); + this.X.terminate(); }); }); From b69f67222b55099f75a1d53082f62482c1b5c7d4 Mon Sep 17 00:00:00 2001 From: champii Date: Mon, 8 Sep 2014 16:16:21 +0200 Subject: [PATCH 10/14] added FreeCursor call --- lib/corereqs.js | 6 ++++++ lib/ext/damage.js | 32 ++++++++++++++++---------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/corereqs.js b/lib/corereqs.js index 7111b03..ccd64af 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -718,6 +718,12 @@ var templates = { } ], + FreePixmap: [ + function (pixmap) { + return [ 'CxSL', [54, 2, pixmap] ]; + } + ], + CreateCursor: [ function(cid, source, mask, foreRGB, backRGB, x, y) { foreR = foreRGB.R diff --git a/lib/ext/damage.js b/lib/ext/damage.js index cdae2a4..c4aa996 100644 --- a/lib/ext/damage.js +++ b/lib/ext/damage.js @@ -3,19 +3,19 @@ var x11 = require('..'); // TODO: move to templates -exports.requireExt = function(display, callback) +exports.requireExt = function(display, callback) { var X = display.client; - X.QueryExtension('DAMAGE', function(err, ext) { + X.QueryExtension('DAMAGE', function(err, ext) { if (!ext.present) return callback(new Error('extension not available')); - ext.ReportLevel = { + ext.ReportLevel = { RawRectangles: 0, DeltaRectangles: 1, BoundingBox: 2, - NonEmpty: 3 + NonEmpty: 3 }; ext.QueryVersion = function(clientMaj, clientMin, callback) @@ -24,7 +24,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]); X.replies[X.seq_num] = [ function(buf, opt) { - var res = buf.unpack('LL'); + var res = buf.unpack('LL'); return res; }, callback @@ -59,18 +59,18 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('CCSLL', [ext.majorOpcode, 4, 3, damage, region]); X.pack_stream.flush(); } - + ext.QueryVersion(1, 1, function(err, vers) { ext.major = vers[0]; ext.minor = vers[1]; - callback(ext); + callback(null, ext); }); ext.events = { DamageNotify: 0 } - X.eventParsers[ext.firstEvent + ext.events.DamageNotify] = function(type, seq, extra, code, raw) + X.eventParsers[ext.firstEvent + ext.events.DamageNotify] = function(type, seq, extra, code, raw) { var event = {}; event.level = code; @@ -80,16 +80,16 @@ exports.requireExt = function(display, callback) event.damage = values[0]; event.time = values[1]; event.area = { - x: values[2], - y: values[3], - w: values[4], - h: values[5] + x: values[2], + y: values[3], + w: values[4], + h: values[5] }; event.geometry = { - x: values[6], - y: values[7], - w: values[8], - h: values[9] + x: values[6], + y: values[7], + w: values[8], + h: values[9] }; event.name = 'DamageNotify'; return event; From 0c95b39c28e2efa040173177bfdc3e08bcc9f3a8 Mon Sep 17 00:00:00 2001 From: champii Date: Mon, 8 Sep 2014 17:21:14 +0200 Subject: [PATCH 11/14] Norme --- lib/ext/xtest.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ext/xtest.js b/lib/ext/xtest.js index 689c0b6..5ad4a66 100644 --- a/lib/ext/xtest.js +++ b/lib/ext/xtest.js @@ -2,10 +2,10 @@ var x11 = require('..'); // TODO: move to templates -exports.requireExt = function(display, callback) +exports.requireExt = function(display, callback) { var X = display.client; - X.QueryExtension('XTEST', function(err, ext) { + X.QueryExtension('XTEST', function(err, ext) { if (!ext.present) return callback(new Error('extension not available')); @@ -39,7 +39,7 @@ exports.requireExt = function(display, callback) X.pack_stream.flush(); } - callback(ext); + callback(null, ext); }); } - + From 4feba9204719fed9140bfeb031c3810bc9e7b659 Mon Sep 17 00:00:00 2001 From: champii Date: Tue, 23 Sep 2014 15:41:37 +0200 Subject: [PATCH 12/14] fixed PR --- lib/corereqs.js | 29 ++++++++--------------------- test/configure-window.js | 7 ------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/lib/corereqs.js b/lib/corereqs.js index ccd64af..ca6697b 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -270,11 +270,9 @@ var templates = { if (values === undefined) values = {} - var packetLength = 8 + (values ? Object.keys(values).length : 0); var format = 'CCSLLssSSSSLL'; // TODO: slice from function arguments? - var args = [1, depth, packetLength, id, parentId, x, y, width, height, borderWidth, _class, visual]; // TODO: the code is a little bit mess // additional values need to be packed in the following way: @@ -282,10 +280,11 @@ var templates = { // values list (bytes #32 .. #32+4*num_values) in order of corresponding bits TODO: it's actually not 4*num. Some values are 4b ytes, some - 1 byte var vals = packValueMask('CreateWindow', values); + var packetLength = 8 + (values ? vals[2].length : 0); + var args = [1, depth, packetLength, id, parentId, x, y, width, height, borderWidth, _class, visual]; format += vals[0]; args.push(vals[1]); args = args.concat(vals[2]); - // console.log('CreateWindow', format, args); return [format, args]; } @@ -294,13 +293,12 @@ var templates = { ChangeWindowAttributes:[ function(wid, values) { var format = 'CxSLSxx'; - var packetLength = 3 + (values ? Object.keys(values).length : 0); var vals = packValueMask('CreateWindow', values); + var packetLength = 3 + (values ? vals[2].length : 0); var args = [2, packetLength, wid, vals[1]]; var valArr = vals[2]; format += vals[0]; args = args.concat(valArr); - // console.log('ChangeWindowAttributes', format, args); return [format, args]; } ], @@ -363,11 +361,8 @@ var templates = { function(win, options) { var vals = packValueMask('ConfigureWindow', options); var format = 'CxSLSxx' + vals[0]; - var args = [12, Object.keys(options).length + 3, win, vals[1]]; - + var args = [12, vals[2].length + 3, win, vals[1]]; args = args.concat(vals[2]); - - // console.log('ConfigureWindow', format, args); return [format, args]; } ], @@ -741,19 +736,12 @@ var templates = { CreateGC: [ function(cid, drawable, values) { var format = 'CxSLLL'; - var packetLength = 4 + (values ? Object.keys(values).length : 0); - var args = [55, packetLength, cid, drawable]; var vals = packValueMask('CreateGC', values); + var packetLength = 4 + (values ? vals[2].length : 0); + var args = [55, packetLength, cid, drawable]; format += vals[0] args.push(vals[1]); // values bitmask args = args.concat(vals[2]) - // var valArr = vals[2]; - // for (var v in valArr) - // { - // format += 'L'; // TODO: we know format string length in advance and += inefficient for string - // args.push(valArr[v]); - // } - console.log('CreateGC', format, args); return [format, args]; } ], @@ -761,9 +749,9 @@ var templates = { ChangeGC: [ function(cid, values) { var format = 'CxSLL'; - var packetLength = 3 + (values ? Object.keys(values).length : 0); - var args = [56, packetLength, cid]; var vals = packValueMask('CreateGC', values); + var packetLength = 3 + (values ? vals[2].length : 0); + var args = [56, packetLength, cid]; args.push(vals[0]); // values bitmask var valArr = vals[1]; for (var v in valArr) @@ -852,7 +840,6 @@ var templates = { // TODO: move code to calculate reqLength and use BigReq if needed outside of corereq.js // NOTE: big req is used here (first 'L' in format, 0 and +1 in params), won't work if not enabled return [ 'CCSLLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; - // return [ 'CCSLLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; } ], diff --git a/test/configure-window.js b/test/configure-window.js index 012b504..8d9bf4a 100644 --- a/test/configure-window.js +++ b/test/configure-window.js @@ -13,12 +13,6 @@ describe('ConfigureWindow', function() { self.wid_helper = self.X.AllocID(); self.X.CreateWindow(self.wid, dpy.screen[0].root, 0, 0, 1, 1); // 1x1 pixel window self.X.CreateWindow(self.wid_helper, dpy.screen[0].root, 0, 0, 1, 1); // 1x1 pixel window - - - // self.X.ConfigureWindow(self.wid, { stackMode: 1 }); - // self.X.ConfigureWindow(self.wid_helper, { stackMode: 1 }); - - self.X.QueryTree(dpy.screen[0].root, function(err, list) { should.not.exist(err); list.children.indexOf(self.wid).should.not.equal(-1); @@ -71,7 +65,6 @@ describe('ConfigureWindow', function() { it('should RaiseWindow correctly', function(done) { var self = this; this.X.once('event', function(ev) { - console.log(ev); ev.type.should.equal(22); /* ConfigureNotify */ ev.aboveSibling.should.equal(self.wid_helper); done(); From 6d6c8d3b9f35e5944477403aa0d48f4b06a0d40d Mon Sep 17 00:00:00 2001 From: champii Date: Tue, 23 Sep 2014 16:09:18 +0200 Subject: [PATCH 13/14] Extensions, tests and exemples are now cps-style --- examples/kbdheatmap/kbdheatmap.js | 44 ++++++++++++++-------------- examples/opengl/glxgears.js | 2 +- examples/opengl/test1.js | 2 +- examples/opengl/tp2.js | 2 +- examples/opengl/triangle.js | 2 +- examples/paint.js | 12 ++++---- examples/png/test.js | 6 ++-- examples/simple/gradients.js | 36 +++++++++++------------ examples/simple/render.js | 6 ++-- examples/simple/text/render-glyph.js | 2 +- examples/smoketest/applewm.js | 16 +++++----- examples/smoketest/compositetest.js | 4 +-- examples/smoketest/damagetest.js | 4 +-- examples/smoketest/fixestest.js | 2 +- examples/smoketest/putimage1.js | 2 +- examples/smoketest/randr.js | 2 +- examples/smoketest/shapetest.js | 6 ++-- examples/smoketest/sstest.js | 6 ++-- examples/smoketest/transpwindow.js | 14 ++++----- examples/smoketest/xcmisc.js | 4 +-- examples/smoketest/xtesttest.js | 2 +- examples/vncviewer/vncgui.js | 18 ++++++------ examples/windowmanager/wm.js | 2 +- lib/ext/apple-wm.js | 22 +++++++------- lib/ext/big-requests.js | 8 ++--- lib/ext/damage.js | 2 ++ lib/ext/dpms.js | 2 +- lib/ext/fixes.js | 36 ++++++++++++----------- lib/ext/glx.js | 2 +- lib/ext/randr.js | 14 ++++----- lib/ext/render.js | 4 ++- lib/ext/screen-saver.js | 21 ++++++------- lib/ext/shape.js | 14 ++++----- lib/ext/xc-misc.js | 12 ++++---- lib/xcore.js | 4 ++- test/dpms.js | 4 +-- test/randr.js | 4 +-- test/xtest.js | 4 +-- 38 files changed, 180 insertions(+), 169 deletions(-) diff --git a/examples/kbdheatmap/kbdheatmap.js b/examples/kbdheatmap/kbdheatmap.js index 96a58f8..dd4ba64 100755 --- a/examples/kbdheatmap/kbdheatmap.js +++ b/examples/kbdheatmap/kbdheatmap.js @@ -15,7 +15,7 @@ var ButtonRelease = x11.eventMask.ButtonRelease; var kbdImg = require('./node-jpg').readJpeg('./keyboard.jpg'); var keycoords = require('./coordinates'); -// from https://github.com/substack/node-keysym +// from https://github.com/substack/node-keysym var keysyms = require('./keysyms').records; var ks2name = {}; for (var k in keysyms) @@ -23,18 +23,18 @@ for (var k in keysyms) var kk2name = {}; -x11.createClient(function(err, display) +x11.createClient(function(err, display) { - var X = display.client; - X.require('big-requests', function(BigReq) + var X = display.client; + X.require('big-requests', function(err, BigReq) { - X.require('render', function(Render) { + X.require('render', function(err, Render) { X.Render = Render; BigReq.Enable(function(err, maxLen) { var min = display.min_keycode; var max = display.max_keycode; - X.GetKeyboardMapping(min, max-min, function(err, list) + X.GetKeyboardMapping(min, max-min, function(err, list) { // map keycode to key name for (var i=0; i < list.length; ++i) @@ -62,26 +62,26 @@ function main(X) var win = X.AllocID(); X.CreateWindow( - win, root, - 0, 0, kbdImg.width, kbdImg.height, + win, root, + 0, 0, kbdImg.width, kbdImg.height, 0, 0, 0, 0, - { - backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress + { + backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress } ); X.MapWindow(win); - + var win1 = X.AllocID(); X.CreateWindow( - win1, root, - 0, 0, kbdImg.width, kbdImg.height, + win1, root, + 0, 0, kbdImg.width, kbdImg.height, 0, 0, 0, 0, - { - backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress + { + backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress } ); X.MapWindow(win1); - + var gc = X.AllocID(); X.CreateGC(gc, win); @@ -103,15 +103,15 @@ function main(X) var picKbd = X.AllocID(); X.PutImage(2, pixmapKbd, gc, kbdImg.width, kbdImg.height, 0, 0, 0, 24, kbdImg.data); Render.CreatePicture(picKbd, pixmapKbd, Render.rgb24); - + var pixmapHeat = X.AllocID(); X.CreatePixmap(pixmapHeat, win, 32, kbdImg.width, kbdImg.height); var picHeat = X.AllocID(); Render.CreatePicture(picHeat, pixmapHeat, Render.rgba32); - + var picWin = X.AllocID(); Render.CreatePicture(picWin, win, Render.rgb24); - + var picWin1 = X.AllocID(); Render.CreatePicture(picWin1, win1, Render.rgb24); @@ -135,12 +135,12 @@ function main(X) mindist = dist; } } - + Render.Composite(3, picKbd, 0, picWin, 0, 0, 0, 0, 0, 0, kbdImg.width, kbdImg.height); Render.Composite(3, picHeatPush, 0, picWin, 0, 0, 0, 0, x -150/2, y-150/2, 150, 150); } if (ev.type == 2) { - + var name = kk2name[ev.keycode]; for (var n in name) { @@ -152,7 +152,7 @@ function main(X) Render.Composite(3, picHeatPush, 0, picHeat, 0, 0, 0, 0, pt[0] -150/2, pt[1]-150/2, 150, 150); Render.Composite(3, picHeatPush, 0, picWin1, 0, 0, 0, 0, pt[0] -150/2, pt[1]-150/2, 150, 150); - + break; } else { //console.log(name); diff --git a/examples/opengl/glxgears.js b/examples/opengl/glxgears.js index cff19b2..2d4392c 100644 --- a/examples/opengl/glxgears.js +++ b/examples/opengl/glxgears.js @@ -294,7 +294,7 @@ x11.createClient(function(error, display) { var root = display.screen[0].root; var width = 500; var height = 500; - X.require('glx', function(GLX) { + X.require('glx', function(err, GLX) { var depth = 24; findBestVisual(display, function(err, visual) { diff --git a/examples/opengl/test1.js b/examples/opengl/test1.js index 60d37c6..b8f6eac 100644 --- a/examples/opengl/test1.js +++ b/examples/opengl/test1.js @@ -13,7 +13,7 @@ var listId = 1; x11.createClient(function(err, display) { var X = display.client; var root = display.screen[0].root; - X.require('glx', function(GLX) { + X.require('glx', function(err, GLX) { var visual = 0; var visuals = display.screen[0].depths[24]; for (visual in visuals) { diff --git a/examples/opengl/tp2.js b/examples/opengl/tp2.js index 0864856..44503c2 100644 --- a/examples/opengl/tp2.js +++ b/examples/opengl/tp2.js @@ -304,7 +304,7 @@ x11.createClient(function(err, display) { var root = display.screen[0].root; var width = 1000; var height = 1000; - X.require('glx', function(GLX) { + X.require('glx', function(err, GLX) { var visual = 0xa1; var win = X.AllocID(); X.CreateWindow(win, root, 0, 0, width, height, 0, 0, 0, 0, { eventMask: eventmask }); diff --git a/examples/opengl/triangle.js b/examples/opengl/triangle.js index d1c60f7..7abbc85 100644 --- a/examples/opengl/triangle.js +++ b/examples/opengl/triangle.js @@ -8,7 +8,7 @@ for(var i=0; i < 20000; ++i) { var xclient = x11.createClient(function(err, display) { var X = display.client; var root = display.screen[0].root; - X.require('glx', function(GLX) { + X.require('glx', function(err, GLX) { var screen = 0; var isDirect = 0; var ctx = X.AllocID(); diff --git a/examples/paint.js b/examples/paint.js index f4900bb..5d666ff 100644 --- a/examples/paint.js +++ b/examples/paint.js @@ -10,10 +10,10 @@ var gradNo = 0; var xclient = x11.createClient(function(err, display) { X = display.client; var root = display.screen[0].root; - X.require('render', function(rendExt) { + X.require('render', function(err, rendExt) { Render = rendExt; var wid = X.AllocID(); - + var white = display.screen[0].white_pixel; var black = display.screen[0].black_pixel; X.CreateWindow(wid, root, 10, 10, 400, 300, 0, 0, 0, 0, { backgroundPixel: white, eventMask: PointerMotion|ButtonPress|ButtonRelease }); @@ -36,8 +36,8 @@ var xclient = x11.createClient(function(err, display) { function draw(x, y) { Render.Composite(3, pictGrad[gradNo], 0, pict, 0, 0, 0, 0, x-50, y-50, 100, 100); - } - + } + X.on('event', function(ev) { if (ev.type == 4 && ev.keycode == 1) pressed = true; @@ -45,14 +45,14 @@ var xclient = x11.createClient(function(err, display) { pressed = false; else if (ev.type == 5 && ev.keycode == 4) { - gradNo--; + gradNo--; if (gradNo < 0) gradNo = 0; console.log(gradNo); } else if (ev.type == 5 && ev.keycode == 5) { - gradNo++; + gradNo++; if (gradNo > 9) gradNo = 9; console.log(gradNo); diff --git a/examples/png/test.js b/examples/png/test.js index 943d70a..08aa934 100644 --- a/examples/png/test.js +++ b/examples/png/test.js @@ -7,7 +7,7 @@ var Exposure = x11.eventMask.Exposure; x11.createClient(function(err, display) { var X = display.client; - X.require('render', function(Render) { + X.require('render', function(err, Render) { var root = display.screen[0].root; main(root, X, Render); }); @@ -15,7 +15,7 @@ x11.createClient(function(err, display) function main(root, X, Render) { - + var win, picWin, pic, gc; win = X.AllocID(); @@ -39,7 +39,7 @@ function main(root, X, Render) { Render.CreatePicture(logoPicture, logoPixmap, Render.rgb24); var winPicture = X.AllocID(); Render.CreatePicture(winPicture, win, Render.rgb24); - + X.on('event', function(ev) { if (ev.name == 'Expose') Render.Composite(3, logoPicture, 0, winPicture, 0, 0, 0, 0, 0, 0, logo.width, logo.height); diff --git a/examples/simple/gradients.js b/examples/simple/gradients.js index 0b6d27e..9e4f017 100644 --- a/examples/simple/gradients.js +++ b/examples/simple/gradients.js @@ -9,21 +9,21 @@ var x11 = require('../../lib'); x11.createClient( function(err, display) { var X = display.client; - X.require('render', function(Render) { + X.require('render', function(err, Render) { var root = display.screen[0].root; var win = X.AllocID(); var white = display.screen[0].white_pixel; var black = display.screen[0].black_pixel; - X.CreateWindow(win, root, 0, 0, 500, 500, 0, 0, 0, 0, - { - backgroundPixel: white, + X.CreateWindow(win, root, 0, 0, 500, 500, 0, 0, 0, 0, + { + backgroundPixel: white, eventMask: x11.eventMask.Exposure | x11.eventMask.ButtonPress | x11.eventMask.PointerMotion }); X.MapWindow(win); var picture = X.AllocID(); - Render.CreatePicture(picture, win, Render.rgb24, { polyEdge: 1, polyMode: 0 } ); + Render.CreatePicture(picture, win, Render.rgb24, { polyEdge: 1, polyMode: 0 } ); var pixmap = X.AllocID(); X.CreatePixmap(pixmap, win, 32, 2500, 2500); var pix_pict = X.AllocID(); @@ -34,30 +34,30 @@ x11.createClient( //RenderRadialGradient(pic_grad, [0,0], [1000,100], 10, 1000, //RenderConicalGradient(pic_grad, [250,250], 360, [ - [0, [0,0,0,0x3000 ] ], - [0.1, [0xfff, 0, 0xffff, 0x1000] ] , - [0.25, [0xffff, 0, 0xfff, 0x3000] ] , - [0.5, [0xffff, 0, 0xffff, 0x4000] ] , - [1, [0xffff, 0xffff, 0, 0x8000] ] + [0, [0,0,0,0x3000 ] ], + [0.1, [0xfff, 0, 0xffff, 0x1000] ] , + [0.25, [0xffff, 0, 0xfff, 0x3000] ] , + [0.5, [0xffff, 0, 0xffff, 0x4000] ] , + [1, [0xffff, 0xffff, 0, 0x8000] ] ]); var pic_grad1 = X.AllocID(); Render.ConicalGradient(pic_grad1, [250,250], 10, [ - [0, [0,0,0,0x5000 ] ], - [0.1, [0xfff, 0, 0xffff, 0x3000] ] , - [0.25, [0xffff, 0, 0xfff, 0x2000] ] , - [0.5, [0xffff, 0, 0xffff, 0x1000] ] , - [1, [0xffff, 0xffff, 0, 0x8000] ] + [0, [0,0,0,0x5000 ] ], + [0.1, [0xfff, 0, 0xffff, 0x3000] ] , + [0.25, [0xffff, 0, 0xfff, 0x2000] ] , + [0.5, [0xffff, 0, 0xffff, 0x1000] ] , + [1, [0xffff, 0xffff, 0, 0x8000] ] ]); var pic_grad2 = X.AllocID(); Render.RadialGradient(pic_grad2, [250,250], [250,250], 0, 250, [ - [0, [0,0,0,0x5000 ] ], + [0, [0,0,0,0x5000 ] ], [0.99, [0xffff, 0xffff, 0, 0xffff] ], - [1, [0xffff, 0xffff, 0, 0x0] ] + [1, [0xffff, 0xffff, 0, 0x0] ] ]); var pixmap1 = X.AllocID(); @@ -112,7 +112,7 @@ x11.createClient( draw(); } else { draw(); - } + } }); }); } diff --git a/examples/simple/render.js b/examples/simple/render.js index 7f56075..c0f046f 100644 --- a/examples/simple/render.js +++ b/examples/simple/render.js @@ -4,7 +4,7 @@ var PointerMotion = x11.eventMask.PointerMotion; var xclient = x11.createClient(function(err, display) { var X = display.client; var root = display.screen[0].root; - display.client.require('render', function(Render) { + display.client.require('render', function(err, Render) { var wid = X.AllocID(); var white = display.screen[0].white_pixel; varblack = display.screen[0].black_pixel; @@ -24,8 +24,8 @@ var xclient = x11.createClient(function(err, display) { function draw(x, y) { Render.Composite(3, pictGrad, 0, pict, 0, 0, 0, 0, x-26, y-26, 52, 52); - } - + } + X.on('event', function(ev) { draw(ev.x, ev.y); }); diff --git a/examples/simple/text/render-glyph.js b/examples/simple/text/render-glyph.js index 748e98a..d2a633c 100644 --- a/examples/simple/text/render-glyph.js +++ b/examples/simple/text/render-glyph.js @@ -39,7 +39,7 @@ function padWidth(buf, width) { var xclient = x11.createClient({ debug: true }, function(err, display) { var X = display.client; var root = display.screen[0].root; - display.client.require('render', function(Render) { + display.client.require('render', function(err, Render) { var wid = X.AllocID(); var white = display.screen[0].white_pixel; varblack = display.screen[0].black_pixel; diff --git a/examples/smoketest/applewm.js b/examples/smoketest/applewm.js index ba376c5..9770df6 100644 --- a/examples/smoketest/applewm.js +++ b/examples/smoketest/applewm.js @@ -3,18 +3,18 @@ var x11 = require('../../lib'); x11.createClient(function(err, display) { var X = display.client; var root = display.screen[0].root; - X.require('apple-wm', function(AppleWM) { + X.require('apple-wm', function(err, AppleWM) { //AppleWM.SetFrontProcess(); - //AppleWM.CanQuit(true); + //AppleWM.CanQuit(true); AppleWM.SelectInput(AppleWM.NotifyMask.All) - + /* for (level in AppleWM.WindowLevel) { var win = X.AllocID(); X.CreateWindow(win, root, 0, 0, 300, 300); X.MapWindow(win); - X.ChangeProperty(0, win, X.atoms.WM_NAME, X.atoms.STRING, 8, level); + X.ChangeProperty(0, win, X.atoms.WM_NAME, X.atoms.STRING, 8, level); AppleWM.SetWindowLevel(win, AppleWM.WindowLevel[level]); }; */ @@ -22,7 +22,7 @@ x11.createClient(function(err, display) { var win1 = X.AllocID(); X.CreateWindow(win1, root, 0, 0, 300, 300); X.MapWindow(win1); - X.ChangeProperty(0, win1, X.atoms.WM_NAME, X.atoms.STRING, 8, "parent"); + X.ChangeProperty(0, win1, X.atoms.WM_NAME, X.atoms.STRING, 8, "parent"); var win2 = X.AllocID(); X.CreateWindow(win2, root, 0, 0, 200, 200); X.MapWindow(win2); @@ -37,12 +37,12 @@ x11.createClient(function(err, display) { // (screen, window, frameClass, attr, ix, iy, iw, ih, ox, oy, ow, oh, titleLength) var gc = X.AllocID(); X.CreateGC(gc, win); - - function r(v) { var res = parseInt(Math.random()*v); console.log(res); return res;} + + function r(v) { var res = parseInt(Math.random()*v); console.log(res); return res;} function df() { X.PolyFillRectangle(win, gc, [0, 0, 1000, 1000]); AppleWM.FrameDraw(0, win, 65535, r(65535), 30, 30, 500, 50, 0, 0, 550, 100, "title title");} //setInterval(df, 100); X.on('event', function(ev) { console.log("Event", ev); df(); }); }); X.on('error', function(err) { console.log("Error", err); }); - + }); diff --git a/examples/smoketest/compositetest.js b/examples/smoketest/compositetest.js index 53ce1ec..76f75ef 100644 --- a/examples/smoketest/compositetest.js +++ b/examples/smoketest/compositetest.js @@ -3,8 +3,8 @@ var x11 = require('../../lib'); x11.createClient(function(err, display) { var X = display.client; var root = display.screen[0].root; - X.require('composite', function(Composite) { - X.require('damage', function(Damage) { + X.require('composite', function(err, Composite) { + X.require('damage', function(err, Damage) { var wid = parseInt(process.argv[2]); //Composite.GetOverlayWindow(wid, function(err, overlayid) { // console.log("OVERLAY:", err, overlayid); diff --git a/examples/smoketest/damagetest.js b/examples/smoketest/damagetest.js index 9aea817..72be79a 100644 --- a/examples/smoketest/damagetest.js +++ b/examples/smoketest/damagetest.js @@ -3,7 +3,7 @@ var x11 = require('../../lib'); x11.createClient(function(err, display) { var X = display.client; var root = display.screen[0].root; - X.require('damage', function(Damage) { + X.require('damage', function(err, Damage) { console.log(Damage); var id = parseInt(process.argv[2]); var damage = X.AllocID(); @@ -14,5 +14,5 @@ x11.createClient(function(err, display) { }); }); X.on('error', function(err) { console.log(err); }); - + }); diff --git a/examples/smoketest/fixestest.js b/examples/smoketest/fixestest.js index 84b0a1a..d1bd456 100644 --- a/examples/smoketest/fixestest.js +++ b/examples/smoketest/fixestest.js @@ -3,7 +3,7 @@ var x11 = require('../../lib'); x11.createClient(function(err, display) { var X = display.client; var root = display.screen[0].root; - X.require('fixes', function(Fixes) { + X.require('fixes', function(err, Fixes) { console.log(Fixes); var win = X.AllocID(); X.CreateWindow(win, root, 0, 0, 100, 100); diff --git a/examples/smoketest/putimage1.js b/examples/smoketest/putimage1.js index 9adb5e1..71f354b 100644 --- a/examples/smoketest/putimage1.js +++ b/examples/smoketest/putimage1.js @@ -23,7 +23,7 @@ x11.createClient(function(err, display) { if (err) throw err; var X = display.client; -X.require('render', function(Render) { +X.require('render', function(err, Render) { var root = display.screen[0].root; var white = display.screen[0].white_pixel; diff --git a/examples/smoketest/randr.js b/examples/smoketest/randr.js index 0700483..4684217 100644 --- a/examples/smoketest/randr.js +++ b/examples/smoketest/randr.js @@ -3,7 +3,7 @@ var x11 = require('../../lib'); x11.createClient(function(err, display) { var X = display.client; var root = display.screen[0].root; - X.require('randr', function(Randr) { + X.require('randr', function(err, Randr) { //console.log(Randr); //Randr.QueryVersion(1, 4, console.log); Randr.SelectInput(root, Randr.NotifyMask.ScreenChange); diff --git a/examples/smoketest/shapetest.js b/examples/smoketest/shapetest.js index 4ee6070..31ba286 100644 --- a/examples/smoketest/shapetest.js +++ b/examples/smoketest/shapetest.js @@ -3,11 +3,11 @@ var x11 = require('../../lib'); x11.createClient(function(err, display) { var X = display.client; var root = display.screen[0].root; - X.require('shape', function(Shape) { + X.require('shape', function(err, Shape) { var win = X.AllocID(); X.CreateWindow(win, root, 0, 0, 200, 200); var gc = X.AllocID(); - X.CreateGC(gc, win); + X.CreateGC(gc, win); //X.MapWindow(win); Shape.SelectInput(win, 1); Shape.InputSelected(win, function(err, isSelected) { @@ -23,5 +23,5 @@ x11.createClient(function(err, display) { }); }); X.on('error', function(err) { console.log(err); }); - + }); diff --git a/examples/smoketest/sstest.js b/examples/smoketest/sstest.js index 2e4688f..40de289 100644 --- a/examples/smoketest/sstest.js +++ b/examples/smoketest/sstest.js @@ -7,7 +7,7 @@ x11.createClient(function(err, display) { X.SetScreenSaver(20, 10, 2, 2); - X.require('screen-saver', function(SS) { + X.require('screen-saver', function(err, SS) { SS.SelectInput(root, SS.eventMask.Notify|SS.eventMask.Cycle); //console.log(SS); //setTimeout(function() { @@ -15,7 +15,7 @@ x11.createClient(function(err, display) { //}, 5000); setInterval(function() { SS.QueryInfo(root, function(err, info) { - console.log(info.until); + console.log(info.until); //SS.SelectInput(root, SS.eventMask.Notify|SS.eventMask.Cycle); }); }, 1000); @@ -24,5 +24,5 @@ x11.createClient(function(err, display) { }); }); X.on('error', function(err) { console.log(err); }); - + }); diff --git a/examples/smoketest/transpwindow.js b/examples/smoketest/transpwindow.js index 30abafb..32da418 100644 --- a/examples/smoketest/transpwindow.js +++ b/examples/smoketest/transpwindow.js @@ -25,18 +25,18 @@ x11.createClient(function(err, display) { var cmid = X.AllocID(); var depth = 32; - X.CreateColormap(cmid, root, visual, 0); // 0=AllocNone, 1 AllocAll - + X.CreateColormap(cmid, root, visual, 0); // 0=AllocNone, 1 AllocAll + X.CreateWindow(wid, root, 10, 10, 168, 195, 1, depth, 1, visual, { eventMask: x11.eventMask.Exposure, colormap: cmid, backgroundPixel: 0, borderPixel: 0 }); X.MapWindow(wid); var gc = X.AllocID(); - X.require('render', function(Render) { + X.require('render', function(err, Render) { var pict = X.AllocID(); Render.CreatePicture(pict, wid, Render.rgba32); var gradients = []; - + function randomLinear() { var stops = []; for (var i=0; i<3; ++i) @@ -49,8 +49,8 @@ x11.createClient(function(err, display) { parseInt(Math.random()*65535), parseInt(Math.random()*65535), parseInt(Math.random()*65535)]]); - - console.log(colors); + + console.log(colors); var gradient = X.AllocID(); Render.LinearGradient(gradient, [0, 0], [100+parseInt(Math.random()*500), parseInt(100+Math.random()*300)], colors); @@ -64,7 +64,7 @@ x11.createClient(function(err, display) { var gid = parseInt(Math.random()*gradients.length); console.log(gradients[gid]); Render.Composite(1, gradients[gid], 0, pict, 0, 0, 0, 0, 0, 0, 400, 300); - }, 2000); + }, 2000); }); //X.CreateGC(gc, wid, { foreground: black, background: white } ); //setInterval(function() { diff --git a/examples/smoketest/xcmisc.js b/examples/smoketest/xcmisc.js index 0516265..18069f8 100644 --- a/examples/smoketest/xcmisc.js +++ b/examples/smoketest/xcmisc.js @@ -3,7 +3,7 @@ var x11 = require('../../lib'); x11.createClient(function(err, display) { var X = display.client; var root = display.screen[0].root; - X.require('xc-misc', function(Misc) { + X.require('xc-misc', function(err, Misc) { var xid = X.AllocID(); console.log("first ID from connection: " + xid); debugger; @@ -15,5 +15,5 @@ x11.createClient(function(err, display) { }); }); X.on('error', function(err) { console.log("Error", err); }); - + }); diff --git a/examples/smoketest/xtesttest.js b/examples/smoketest/xtesttest.js index 10e3874..d7c215e 100644 --- a/examples/smoketest/xtesttest.js +++ b/examples/smoketest/xtesttest.js @@ -3,7 +3,7 @@ var x11 = require('../../lib'); var xclient = x11.createClient(function(err, display) { var X = display.client; var root = display.screen[0].root; - display.client.require('xtest', function(Test) { + display.client.require('xtest', function(err, Test) { console.log(Test); setInterval(function() { Test.FakeInput(Test.KeyPress, 65, 0, root, 0, 0); // space diff --git a/examples/vncviewer/vncgui.js b/examples/vncviewer/vncgui.js index 7c897b9..725bf4e 100644 --- a/examples/vncviewer/vncgui.js +++ b/examples/vncviewer/vncgui.js @@ -30,8 +30,8 @@ var KeyPress = x11.eventMask.KeyPress; var KeyRelease = x11.eventMask.KeyRelease; x11.createClient(function(err, display) { - var X = display.client; - X.require('big-requests', function(BigReq) { + var X = display.client; + X.require('big-requests', function(err, BigReq) { BigReq.Enable(function(err, maxLen) { var keycode2keysym = []; var min = display.min_keycode; @@ -54,19 +54,19 @@ x11.createClient(function(err, display) { var wid = X.AllocID(); X.CreateWindow(wid, root, 0, 0, r.width, r.height); - X.ChangeWindowAttributes(wid, { - backgroundPixel: black, - eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease|KeyPress|KeyRelease + X.ChangeWindowAttributes(wid, { + backgroundPixel: black, + eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease|KeyPress|KeyRelease }); X.ChangeProperty(0, wid, X.atoms.WM_NAME, X.atoms.STRING, 8, r.title); X.MapWindow(wid); var gc = X.AllocID(); X.CreateGC(gc, wid, { foreground: black, background: white } ); - + //var pixbuf = X.AllocID(); //X.CreatePixmap(pixbuf, wid, 32, r.width, r.height); - //var pic = X.AllocID(); + //var pic = X.AllocID(); //Render.CreatePicture(pic, pixbuf, Render.rgba32); var buttonsState = 0; @@ -86,7 +86,7 @@ x11.createClient(function(err, display) { // set button bit if (ev.type == 4) buttonsState |= buttonBit; - else + else buttonsState &= ~buttonBit; r.pointerEvent(ev.x, ev.y, buttonsState); } else if (ev.type == 2 || ev.type == 3) { @@ -121,7 +121,7 @@ x11.createClient(function(err, display) { }); }); // r.on('connect) - }); // GetKeyboardMapping + }); // GetKeyboardMapping }); // BigReq.Enable }); // require('big-requests diff --git a/examples/windowmanager/wm.js b/examples/windowmanager/wm.js index dcaebdd..384846e 100644 --- a/examples/windowmanager/wm.js +++ b/examples/windowmanager/wm.js @@ -80,7 +80,7 @@ function ManageWindow(wid) x11.createClient(function(err, display) { X = display.client; - X.require('render', function(Render) { + X.require('render', function(err, Render) { X.Render = Render; root = display.screen[0].root; diff --git a/lib/ext/apple-wm.js b/lib/ext/apple-wm.js index 6e6db66..dd9e3c1 100644 --- a/lib/ext/apple-wm.js +++ b/lib/ext/apple-wm.js @@ -18,10 +18,10 @@ var xutil = require('../xutil'); #define X_AppleWMAttachTransient 13 */ -exports.requireExt = function(display, callback) +exports.requireExt = function(display, callback) { var X = display.client; - X.QueryExtension('Apple-WM', function(err, ext) { + X.QueryExtension('Apple-WM', function(err, ext) { if (!ext.present) callback(new Error('extension not available')); @@ -32,7 +32,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('CCS', [ext.majorOpcode, 0, 1]); X.replies[X.seq_num] = [ function(buf, opt) { - var res = buf.unpack('SSL'); + var res = buf.unpack('SSL'); return res; }, cb @@ -52,7 +52,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('CCSSSSSSSSSSS', [ext.majorOpcode, 1, 6, frame_class, frame_rect, ix, iy, iw, ih, ox, oy, ow, oh, cb]); X.replies[X.seq_num] = [ function(buf, opt) { - var res = buf.unpack('SSSS'); + var res = buf.unpack('SSSS'); return { x: res[0], y: res[1], @@ -64,7 +64,7 @@ exports.requireExt = function(display, callback) ]; X.pack_stream.flush(); } - + ext.FrameHitTest = function(frame_class, px, py, ix, iy, iw, ih, ox, oy, ow, oh, cb) { X.seq_num++; @@ -80,7 +80,7 @@ exports.requireExt = function(display, callback) } -// from /usr/include/Xplugin.h +// from /usr/include/Xplugin.h ext.FrameClass = { DecorLarge: 1, Reserved1: 2, @@ -107,7 +107,7 @@ exports.requireExt = function(display, callback) CloseBoxClicked: 0x800, CollapseBoxClicked: 0x1000, ZoomBoxClicked: 0x2000, - GrowBox: 0x4000 + GrowBox: 0x4000 }; ext.FrameDraw = function(screen, window, frameClass, attr, ix, iy, iw, ih, ox, oy, ow, oh, title) @@ -189,7 +189,7 @@ exports.requireExt = function(display, callback) var reqlen = 8; var extlength = 0; items.forEach(function(i) { - + }); } @@ -209,13 +209,13 @@ exports.requireExt = function(display, callback) X.pack_stream.flush(); } - callback(ext); + callback(null, ext); /* ext.QueryVersion(function(err, vers) { ext.major = vers[0]; ext.minor = vers[1]; ext.patch = vers[2]; - callback(ext); + callback(null, ext); }); */ @@ -248,7 +248,7 @@ exports.requireExt = function(display, callback) CopyToPasteboard: 0 } }; - + X.eventParsers[ext.firstEvent + ext.events.AppleWMControllerNotify] = X.eventParsers[ext.firstEvent + ext.events.AppleWMActivationNotify] = X.eventParsers[ext.firstEvent + ext.events.AppleWMPasteboardNotify] = function(type, seq, extra, code, raw) diff --git a/lib/ext/big-requests.js b/lib/ext/big-requests.js index 19b61e9..8f91d3d 100644 --- a/lib/ext/big-requests.js +++ b/lib/ext/big-requests.js @@ -1,11 +1,11 @@ // http://www.x.org/releases/X11R7.6/doc/bigreqsproto/bigreq.html // TODO: move to templates -exports.requireExt = function(display, callback) +exports.requireExt = function(display, callback) { var X = display.client; - X.QueryExtension('BIG-REQUESTS', function(err, ext) { - + X.QueryExtension('BIG-REQUESTS', function(err, ext) { + if (!ext.present) return callback(new Error('extension not available')); @@ -21,6 +21,6 @@ exports.requireExt = function(display, callback) ]; X.pack_stream.flush(); } - callback(ext); + callback(null, ext); }); } diff --git a/lib/ext/damage.js b/lib/ext/damage.js index c4aa996..bfebcc8 100644 --- a/lib/ext/damage.js +++ b/lib/ext/damage.js @@ -61,6 +61,8 @@ exports.requireExt = function(display, callback) } ext.QueryVersion(1, 1, function(err, vers) { + if (err) + return callback(err); ext.major = vers[0]; ext.minor = vers[1]; callback(null, ext); diff --git a/lib/ext/dpms.js b/lib/ext/dpms.js index 2aeefdf..a607fd3 100644 --- a/lib/ext/dpms.js +++ b/lib/ext/dpms.js @@ -94,7 +94,7 @@ exports.requireExt = function(display, callback) X.pack_stream.flush(); }; - callback(ext); + callback(null, ext); }); }; diff --git a/lib/ext/fixes.js b/lib/ext/fixes.js index 434a8ee..8bb0686 100644 --- a/lib/ext/fixes.js +++ b/lib/ext/fixes.js @@ -7,7 +7,7 @@ function parse_rectangle(buf, pos) { if (!pos) { pos = 0; } - + return { x : buf[pos], y : buf[pos + 1], @@ -16,10 +16,10 @@ function parse_rectangle(buf, pos) { } } -exports.requireExt = function(display, callback) +exports.requireExt = function(display, callback) { var X = display.client; - X.QueryExtension('XFIXES', function(err, ext) { + X.QueryExtension('XFIXES', function(err, ext) { if (!ext.present) return callback(new Error('extension not available')); @@ -30,7 +30,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]); X.replies[X.seq_num] = [ function(buf, opt) { - var res = buf.unpack('LL'); + var res = buf.unpack('LL'); return res; }, callback @@ -68,7 +68,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack(format, args); X.pack_stream.flush(); } - + ext.CreateRegionFromWindow = function(region, wid, kind) { X.seq_num ++; X.pack_stream.pack('CCSLLCxxx', [ ext.majorOpcode, 7, 4, region, wid, kind ]); @@ -92,7 +92,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('CCSLss', [ ext.majorOpcode, 17, 3, region, dx, dy ]); X.pack_stream.flush(); } - + ext.FetchRegion = function(region, cb) { X.seq_num ++; X.pack_stream.pack('CCSL', [ ext.majorOpcode, 19, 2, region ]); @@ -110,7 +110,7 @@ exports.requireExt = function(display, callback) for (var i = 0; i < n_rectangles; ++ i) { reg.rectangles.push(parse_rectangle(res, 4 + (i << 2))); } - + return reg; }, cb @@ -120,16 +120,18 @@ exports.requireExt = function(display, callback) } ext.QueryVersion(5, 0, function(err, vers) { + if (err) + return callback(err); ext.major = vers[0]; ext.minor = vers[1]; - callback(ext); + callback(null, ext); }); ext.events = { DamageNotify: 0 } - X.eventParsers[ext.firstEvent + ext.events.DamageNotify] = function(type, seq, extra, code, raw) + X.eventParsers[ext.firstEvent + ext.events.DamageNotify] = function(type, seq, extra, code, raw) { var event = {}; event.level = code; @@ -139,16 +141,16 @@ exports.requireExt = function(display, callback) event.damage = values[0]; event.time = values[1]; event.area = { - x: values[2], - y: values[3], - w: values[4], - h: values[5] + x: values[2], + y: values[3], + w: values[4], + h: values[5] }; event.geometry = { - x: values[6], - y: values[7], - w: values[8], - h: values[9] + x: values[6], + y: values[7], + w: values[8], + h: values[9] }; event.name = 'DamageNotify'; return event; diff --git a/lib/ext/glx.js b/lib/ext/glx.js index f60ecf5..df3c42d 100644 --- a/lib/ext/glx.js +++ b/lib/ext/glx.js @@ -319,7 +319,7 @@ exports.requireExt = function(display, callback) }; }); - callback(ext); + callback(null, ext); }); } diff --git a/lib/ext/randr.js b/lib/ext/randr.js index fb69629..6516518 100644 --- a/lib/ext/randr.js +++ b/lib/ext/randr.js @@ -3,15 +3,15 @@ var x11 = require('..'); // TODO: move to templates -exports.requireExt = function(display, callback) +exports.requireExt = function(display, callback) { var X = display.client; - X.QueryExtension('RANDR', function(err, ext) { + X.QueryExtension('RANDR', function(err, ext) { if (!ext.present) return callback(new Error('extension not available')); - //ext.ReportLevel = { + //ext.ReportLevel = { //}; ext.QueryVersion = function(clientMaj, clientMin, callback) @@ -198,7 +198,7 @@ exports.requireExt = function(display, callback) pos += res_modes[i + 11]; } - + return resources; }, cb @@ -223,7 +223,7 @@ exports.requireExt = function(display, callback) height : res[4], mode : res[5], rotation : res[6], - rotations : res[7] + rotations : res[7] }; pos += 24; @@ -239,7 +239,7 @@ exports.requireExt = function(display, callback) X.pack_stream.flush(); }, - X.eventParsers[ext.firstEvent + ext.events.RRScreenChangeNotify] = function(type, seq, extra, code, raw) + X.eventParsers[ext.firstEvent + ext.events.RRScreenChangeNotify] = function(type, seq, extra, code, raw) { var event = {}; event.raw = raw; @@ -263,6 +263,6 @@ exports.requireExt = function(display, callback) return event; }; - callback(ext); + callback(null, ext); }); } diff --git a/lib/ext/render.js b/lib/ext/render.js index e99629d..cf01c39 100644 --- a/lib/ext/render.js +++ b/lib/ext/render.js @@ -530,6 +530,8 @@ exports.requireExt = function(display, callback) // 11 - colormap or none ext.QueryPictFormat(function(err, formats) { + if (err) + return callback(err); for (var i=0; i < formats.formats.length; ++i) { var f = formats.formats[i]; if (f[2] == 1 && f[10] == 1) @@ -542,7 +544,7 @@ exports.requireExt = function(display, callback) if (f[2] == 8 && f[10] == 255) ext.a8 = f[0]; } - callback(ext); + callback(null, ext); }); [ diff --git a/lib/ext/screen-saver.js b/lib/ext/screen-saver.js index 89da127..82e7bc4 100644 --- a/lib/ext/screen-saver.js +++ b/lib/ext/screen-saver.js @@ -3,10 +3,10 @@ var x11 = require('..'); // TODO: move to templates -exports.requireExt = function(display, callback) +exports.requireExt = function(display, callback) { var X = display.client; - X.QueryExtension('MIT-SCREEN-SAVER', function(err, ext) { + X.QueryExtension('MIT-SCREEN-SAVER', function(err, ext) { if (!ext.present) return callback(new Error('extension not available')); @@ -18,7 +18,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('CCSCCxx', [ext.majorOpcode, 0, 2, clientMaj, clientMin]); X.replies[X.seq_num] = [ function(buf, opt) { - var res = buf.unpack('CC'); + var res = buf.unpack('CC'); return res; }, cb @@ -26,18 +26,18 @@ exports.requireExt = function(display, callback) X.pack_stream.flush(); } - ext.State = { + ext.State = { Off: 0, On: 1, Disabled: 2 }; - ext.Kind = { + ext.Kind = { Blanked: 0, Internal: 1, External: 2 }; - + ext.QueryInfo = function(drawable, callback) { X.seq_num++; @@ -51,7 +51,7 @@ exports.requireExt = function(display, callback) info.until = res[1]; info.idle = res[2]; info.eventMask = res[3]; - info.kind = res[4] + info.kind = res[4] return info; }, callback @@ -73,10 +73,11 @@ exports.requireExt = function(display, callback) } ext.QueryVersion(1, 1, function(err, vers) { - + if (err) + return callback(err); ext.major = vers[0]; ext.minor = vers[1]; - callback(ext); + callback(null, ext); }); ext.events = { @@ -89,7 +90,7 @@ exports.requireExt = function(display, callback) Cycle: 2 } - X.eventParsers[ext.firstEvent + ext.events.ScreenSaverNotify] = function(type, seq, extra, code, raw) + X.eventParsers[ext.firstEvent + ext.events.ScreenSaverNotify] = function(type, seq, extra, code, raw) { var event = {}; event.state = code; diff --git a/lib/ext/shape.js b/lib/ext/shape.js index acb54ba..f328c11 100644 --- a/lib/ext/shape.js +++ b/lib/ext/shape.js @@ -3,7 +3,7 @@ var x11 = require('..'); // TODO: move to templates -exports.requireExt = function(display, callback) +exports.requireExt = function(display, callback) { function captureStack() { @@ -14,12 +14,12 @@ exports.requireExt = function(display, callback) } var X = display.client; - X.QueryExtension('SHAPE', function(err, ext) { + X.QueryExtension('SHAPE', function(err, ext) { if (!ext.present) return callback(new Error('extension not available')); - ext.Kind = { + ext.Kind = { Bounding: 0, Clip: 1, Input: 2 @@ -40,7 +40,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 1]); X.replies[X.seq_num] = [ function(buf, opt) { - var res = buf.unpack('SS'); + var res = buf.unpack('SS'); return res; }, cb @@ -78,13 +78,13 @@ exports.requireExt = function(display, callback) X.pack_stream.flush(); } - callback(ext); - + callback(null, ext); + /* ext.QueryVersion(function(err, version) { ext.major = version[0]; ext.minor = version[1]; - callback(ext); + callback(null, ext); }); */ }); diff --git a/lib/ext/xc-misc.js b/lib/ext/xc-misc.js index 1f0bc42..53aa72f 100644 --- a/lib/ext/xc-misc.js +++ b/lib/ext/xc-misc.js @@ -3,10 +3,10 @@ var x11 = require('..'); // TODO: move to templates -exports.requireExt = function(display, callback) +exports.requireExt = function(display, callback) { var X = display.client; - X.QueryExtension('XC-MISC', function(err, ext) { + X.QueryExtension('XC-MISC', function(err, ext) { if (!ext.present) return callback(new Error('extension not available')); @@ -17,7 +17,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('CCSSS', [ext.majorOpcode, 0, 2, clientMaj, clientMin]); X.replies[X.seq_num] = [ function(buf, opt) { - var res = buf.unpack('SS'); + var res = buf.unpack('SS'); return res; }, cb @@ -31,7 +31,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('CCS', [ext.majorOpcode, 1, 1]); X.replies[X.seq_num] = [ function(buf, opt) { - var res = buf.unpack('LL'); + var res = buf.unpack('LL'); return { startId: res[0], count: res[1] @@ -60,9 +60,11 @@ exports.requireExt = function(display, callback) } ext.QueryVersion(1, 1, function(err, vers) { + if (err) + return callback(err); ext.major = vers[0]; ext.minor = vers[1]; - callback(ext); + callback(null, ext); }); }); } diff --git a/lib/xcore.js b/lib/xcore.js index 97e3fdd..1586d67 100644 --- a/lib/xcore.js +++ b/lib/xcore.js @@ -592,7 +592,9 @@ module.exports.createClient = function(options, initCb) client.on('connect', function(display) { // opt-in BigReq if (!options.disableBigRequests) { - client.require('big-requests', function(BigReq) { + client.require('big-requests', function(err, BigReq) { + if (err) + return initCb(err) BigReq.Enable(function(err, maxLen) { display.max_request_length = maxLen; cbCalled = true; diff --git a/test/dpms.js b/test/dpms.js index d231d37..d184011 100644 --- a/test/dpms.js +++ b/test/dpms.js @@ -12,8 +12,8 @@ describe('DPMS extension', function() { if (!err) { display = dpy; X = display.client; - X.require('dpms', function(ext) { - if (util.isError(ext)) { + X.require('dpms', function(err, ext) { + if (err) { done(ext); } else { dpms = ext; diff --git a/test/randr.js b/test/randr.js index 97d101d..683c4d1 100644 --- a/test/randr.js +++ b/test/randr.js @@ -11,8 +11,8 @@ describe('RANDR extension', function() { self.X = dpy.client; self.screen = dpy.screen[0]; self.root = self.screen.root; - self.X.require('randr', function(ext) { - util.isError(ext).should.equal(false); + self.X.require('randr', function(err, ext) { + err.should.equal(null); self.randr = ext; /* We HAVE to QueryVersion before using it. Otherwise it does not work as expected */ self.randr.QueryVersion(1, 2, done); diff --git a/test/xtest.js b/test/xtest.js index 65c79df..a977b8f 100644 --- a/test/xtest.js +++ b/test/xtest.js @@ -12,8 +12,8 @@ describe('XTEST extension', function() { if (!err) { display = dpy; X = display.client; - X.require('xtest', function(ext) { - if (util.isError(ext)) { + X.require('xtest', function(err, ext) { + if (err) { done(ext); } else { xtest = ext; From 47b791dc425b9dbb724c07a1822a5691e43f2185 Mon Sep 17 00:00:00 2001 From: champii Date: Tue, 23 Sep 2014 16:31:08 +0200 Subject: [PATCH 14/14] coding style --- test/dpms.js | 9 +++------ test/xtest.js | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/test/dpms.js b/test/dpms.js index d184011..7226bf8 100644 --- a/test/dpms.js +++ b/test/dpms.js @@ -13,12 +13,9 @@ describe('DPMS extension', function() { display = dpy; X = display.client; X.require('dpms', function(err, ext) { - if (err) { - done(ext); - } else { - dpms = ext; - done(); - } + should.not.exist(err); + dpms = ext; + done(); }); } else { done(err); diff --git a/test/xtest.js b/test/xtest.js index a977b8f..e682a58 100644 --- a/test/xtest.js +++ b/test/xtest.js @@ -13,12 +13,9 @@ describe('XTEST extension', function() { display = dpy; X = display.client; X.require('xtest', function(err, ext) { - if (err) { - done(ext); - } else { - xtest = ext; - done(); - } + should.not.exist(err); + xtest = ext; + done(); }); } else { done(err);