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) {