mirror of
https://github.com/danbulant/node-x11
synced 2026-06-24 17:21:47 +00:00
Test
This commit is contained in:
parent
e5e4eac0e5
commit
965b5ca997
2 changed files with 47 additions and 46 deletions
|
|
@ -660,7 +660,7 @@ var templates = {
|
||||||
backR = backRGB.R
|
backR = backRGB.R
|
||||||
backG = backRGB.G
|
backG = backRGB.G
|
||||||
backB = backRGB.B
|
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] ];
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
||||||
91
lib/xcore.js
91
lib/xcore.js
|
|
@ -29,7 +29,7 @@ function XClient(stream, displayNum, screenNum, options)
|
||||||
// TODO: this is probably not used
|
// TODO: this is probably not used
|
||||||
this.core_requests = {};
|
this.core_requests = {};
|
||||||
this.ext_requests = {};
|
this.ext_requests = {};
|
||||||
|
|
||||||
this.displayNum = displayNum;
|
this.displayNum = displayNum;
|
||||||
this.screenNum = screenNum;
|
this.screenNum = screenNum;
|
||||||
this.authHost = os.hostname();
|
this.authHost = os.hostname();
|
||||||
|
|
@ -39,10 +39,10 @@ function XClient(stream, displayNum, screenNum, options)
|
||||||
// data received from stream is dispached to
|
// data received from stream is dispached to
|
||||||
// read requests set by calls to .unpack and .unpackTo
|
// read requests set by calls to .unpack and .unpackTo
|
||||||
//stream.pipe(pack_stream);
|
//stream.pipe(pack_stream);
|
||||||
|
|
||||||
// pack_stream write requests are buffered and
|
// pack_stream write requests are buffered and
|
||||||
// flushed to stream as result of call to .flush
|
// 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);
|
//pack_stream.pipe(stream);
|
||||||
var client = this;
|
var client = this;
|
||||||
pack_stream.on('data', function( data ) {
|
pack_stream.on('data', function( data ) {
|
||||||
|
|
@ -55,7 +55,7 @@ function XClient(stream, displayNum, screenNum, options)
|
||||||
//console.error(hexy(data, {prefix: 'to unpacker '}));
|
//console.error(hexy(data, {prefix: 'to unpacker '}));
|
||||||
//for (var i=0; i < data.length; ++i)
|
//for (var i=0; i < data.length; ++i)
|
||||||
// console.log('>>> ' + data[i]);
|
// console.log('>>> ' + data[i]);
|
||||||
pack_stream.write(data);
|
pack_stream.write(data);
|
||||||
});
|
});
|
||||||
stream.on('end', function() {
|
stream.on('end', function() {
|
||||||
client.emit('end');
|
client.emit('end');
|
||||||
|
|
@ -67,7 +67,7 @@ function XClient(stream, displayNum, screenNum, options)
|
||||||
var cli = this;
|
var cli = this;
|
||||||
if (cli.options.debug) {
|
if (cli.options.debug) {
|
||||||
this.seq_num_ = 0;
|
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", {
|
Object.defineProperty(cli, "seq_num", {
|
||||||
set : function(v) {
|
set : function(v) {
|
||||||
cli.seq_num_ = v;
|
cli.seq_num_ = v;
|
||||||
|
|
@ -84,7 +84,7 @@ function XClient(stream, displayNum, screenNum, options)
|
||||||
this.seq_num = 0;
|
this.seq_num = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// in/out packets indexed by sequence ID
|
// in/out packets indexed by sequence ID
|
||||||
this.replies = {};
|
this.replies = {};
|
||||||
this.atoms = stdatoms;
|
this.atoms = stdatoms;
|
||||||
|
|
@ -96,15 +96,15 @@ function XClient(stream, displayNum, screenNum, options)
|
||||||
|
|
||||||
return names;
|
return names;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
this.eventMask = em;
|
this.eventMask = em;
|
||||||
|
|
||||||
this.event_consumers = {}; // maps window id to eventemitter TODO: bad name
|
this.event_consumers = {}; // maps window id to eventemitter TODO: bad name
|
||||||
this.eventParsers = {};
|
this.eventParsers = {};
|
||||||
this.errorParsers = {};
|
this.errorParsers = {};
|
||||||
|
|
||||||
this.importRequestsFromTemplates(this, coreRequests);
|
this.importRequestsFromTemplates(this, coreRequests);
|
||||||
|
|
||||||
this.startHandshake();
|
this.startHandshake();
|
||||||
this._closing = false;
|
this._closing = false;
|
||||||
}
|
}
|
||||||
|
|
@ -142,21 +142,22 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs)
|
||||||
this.pending_atoms = {};
|
this.pending_atoms = {};
|
||||||
for (var r in reqs)
|
for (var r in reqs)
|
||||||
{
|
{
|
||||||
|
console.log(r);
|
||||||
// r is request name
|
// r is request name
|
||||||
target[r] = (function(reqName) {
|
target[r] = (function(reqName) {
|
||||||
|
|
||||||
var reqFunc = function req_proxy() {
|
var reqFunc = function req_proxy() {
|
||||||
|
|
||||||
if (client._closing)
|
if (client._closing)
|
||||||
throw new Error('client is in closing state');
|
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
|
// 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)
|
if (client.seq_num == 65535)
|
||||||
client.seq_num = 0;
|
client.seq_num = 0;
|
||||||
else
|
else
|
||||||
client.seq_num++;
|
client.seq_num++;
|
||||||
|
|
||||||
// is it fast?
|
// is it fast?
|
||||||
var args = Array.prototype.slice.call(req_proxy.arguments);
|
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;
|
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)
|
// call template with input arguments (not including callback which is last argument TODO currently with callback. won't hurt)
|
||||||
//reqPack = reqTemplate.call(args);
|
//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 format = reqPack[0];
|
||||||
var requestArguments = reqPack[1];
|
var requestArguments = reqPack[1];
|
||||||
|
|
||||||
if (callback)
|
if (callback)
|
||||||
this.replies[this.seq_num] = [reqReplTemplate[1], callback];
|
this.replies[this.seq_num] = [reqReplTemplate[1], callback];
|
||||||
|
|
||||||
client.pack_stream.pack(format, requestArguments);
|
client.pack_stream.pack(format, requestArguments);
|
||||||
var b = client.pack_stream.write_queue[0];
|
var b = client.pack_stream.write_queue[0];
|
||||||
client.pack_stream.flush();
|
client.pack_stream.flush();
|
||||||
|
|
||||||
} else if (templateType == 'Array'){
|
} else if (templateType == 'Array'){
|
||||||
if (reqName === 'GetAtomName') {
|
if (reqName === 'GetAtomName') {
|
||||||
var atom = req_proxy.arguments[0];
|
var atom = req_proxy.arguments[0];
|
||||||
|
|
@ -211,12 +212,12 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs)
|
||||||
client.pending_atoms[client.seq_num] = atom;
|
client.pending_atoms[client.seq_num] = atom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var format = reqTemplate[0];
|
var format = reqTemplate[0];
|
||||||
var requestArguments = [];
|
var requestArguments = [];
|
||||||
|
|
||||||
for (var a = 0; a < reqTemplate[1].length; ++a)
|
for (var a = 0; a < reqTemplate[1].length; ++a)
|
||||||
requestArguments.push(reqTemplate[1][a]);
|
requestArguments.push(reqTemplate[1][a]);
|
||||||
for (var a in args)
|
for (var a in args)
|
||||||
requestArguments.push(args[a]);
|
requestArguments.push(args[a]);
|
||||||
|
|
||||||
|
|
@ -249,8 +250,8 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
|
||||||
var event = {}; // TODO: constructor & base functions
|
var event = {}; // TODO: constructor & base functions
|
||||||
// Remove the most significant bit. See Chapter 1, Event Format section in X11 protocol
|
// Remove the most significant bit. See Chapter 1, Event Format section in X11 protocol
|
||||||
// specification
|
// specification
|
||||||
type = type & 0x7F;
|
type = type & 0x7F;
|
||||||
event.type = type;
|
event.type = type;
|
||||||
event.seq = seq;
|
event.seq = seq;
|
||||||
|
|
||||||
var extUnpacker = this.eventParsers[type];
|
var extUnpacker = this.eventParsers[type];
|
||||||
|
|
@ -265,7 +266,7 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
|
||||||
// TODO: use unpackTo???
|
// TODO: use unpackTo???
|
||||||
event.name = [,,'KeyPress', 'KeyRelease', 'ButtonPress', 'ButtonRelease', 'MotionNotify'][type]
|
event.name = [,,'KeyPress', 'KeyRelease', 'ButtonPress', 'ButtonRelease', 'MotionNotify'][type]
|
||||||
event.time = extra;
|
event.time = extra;
|
||||||
event.keycode = code;
|
event.keycode = code;
|
||||||
event.root = values[0];
|
event.root = values[0];
|
||||||
event.wid = values[1];
|
event.wid = values[1];
|
||||||
event.child = values[2];
|
event.child = values[2];
|
||||||
|
|
@ -352,13 +353,13 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
|
||||||
event.width = values[3]
|
event.width = values[3]
|
||||||
event.height = values[4]
|
event.height = values[4]
|
||||||
event.borderWidth = values[5];
|
event.borderWidth = values[5];
|
||||||
//
|
//
|
||||||
// The value-mask indicates which components were specified in
|
// The value-mask indicates which components were specified in
|
||||||
// the request. The value-mask and the corresponding values are reported as given
|
// 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
|
// 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
|
// window, except in the case of sibling and stack-mode, which are reported as None
|
||||||
// and Above (respectively) if not given in the request.
|
// 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
|
// 322, [ 12582925, 0, 0, 484, 316, 1, 12, 0
|
||||||
//console.log([extra, code, values]);
|
//console.log([extra, code, values]);
|
||||||
} else if (type == 28) {// PropertyNotify
|
} else if (type == 28) {// PropertyNotify
|
||||||
|
|
@ -398,7 +399,7 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
|
||||||
event.type = raw.readUInt32LE(0);
|
event.type = raw.readUInt32LE(0);
|
||||||
var format = (code === 32) ? 'LLLLL' : (code === 16) ? 'SSSSSSSSSS' : 'CCCCCCCCCCCCCCCCCCCC';
|
var format = (code === 32) ? 'LLLLL' : (code === 16) ? 'SSSSSSSSSS' : 'CCCCCCCCCCCCCCCCCCCC';
|
||||||
event.data = raw.unpack(format, 4);
|
event.data = raw.unpack(format, 4);
|
||||||
} else if (type == 34) {
|
} else if (type == 34) {
|
||||||
event.name = 'MappingNotify';
|
event.name = 'MappingNotify';
|
||||||
event.request = headerBuf[4];
|
event.request = headerBuf[4];
|
||||||
event.firstKeyCode = headerBuf[5];
|
event.firstKeyCode = headerBuf[5];
|
||||||
|
|
@ -421,7 +422,7 @@ XClient.prototype.expectReplyHeader = function()
|
||||||
var bad_value = res[3];
|
var bad_value = res[3];
|
||||||
|
|
||||||
if (type == 0)
|
if (type == 0)
|
||||||
{
|
{
|
||||||
var error_code = res[1];
|
var error_code = res[1];
|
||||||
var error = new Error();
|
var error = new Error();
|
||||||
error.error = error_code;
|
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)
|
// unpack error packet (32 bytes for all error types, 8 of them in CCSL header)
|
||||||
client.pack_stream.get(24, function(buf) {
|
client.pack_stream.get(24, function(buf) {
|
||||||
|
|
||||||
var res = buf.unpack('SC');
|
var res = buf.unpack('SC');
|
||||||
error.message = xerrors.errorText[error_code];
|
error.message = xerrors.errorText[error_code];
|
||||||
error.badParam = bad_value;
|
error.badParam = bad_value;
|
||||||
|
|
@ -444,7 +445,7 @@ XClient.prototype.expectReplyHeader = function()
|
||||||
if (extUnpacker) {
|
if (extUnpacker) {
|
||||||
extUnpacker(error, error_code, seq_num, bad_value, buf);
|
extUnpacker(error, error_code, seq_num, bad_value, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
var handler = client.replies[seq_num];
|
var handler = client.replies[seq_num];
|
||||||
if (handler) {
|
if (handler) {
|
||||||
var callback = handler[1];
|
var callback = handler[1];
|
||||||
|
|
@ -458,7 +459,7 @@ XClient.prototype.expectReplyHeader = function()
|
||||||
} else
|
} else
|
||||||
client.emit('error', error);
|
client.emit('error', error);
|
||||||
client.expectReplyHeader();
|
client.expectReplyHeader();
|
||||||
} );
|
} );
|
||||||
return;
|
return;
|
||||||
} else if (type > 1)
|
} else if (type > 1)
|
||||||
{
|
{
|
||||||
|
|
@ -466,20 +467,20 @@ XClient.prototype.expectReplyHeader = function()
|
||||||
var extra = res[3];
|
var extra = res[3];
|
||||||
var code = res[1];
|
var code = res[1];
|
||||||
var ev = client.unpackEvent(type, seq_num, extra, code, buf, headerBuf);
|
var ev = client.unpackEvent(type, seq_num, extra, code, buf, headerBuf);
|
||||||
|
|
||||||
// raw event 32-bytes packet (primarily for use in SendEvent);
|
// raw event 32-bytes packet (primarily for use in SendEvent);
|
||||||
// TODO: Event::pack based on event parameters, inverse to unpackEvent
|
// TODO: Event::pack based on event parameters, inverse to unpackEvent
|
||||||
ev.rawData = new Buffer(32);
|
ev.rawData = new Buffer(32);
|
||||||
headerBuf.copy(ev.rawData);
|
headerBuf.copy(ev.rawData);
|
||||||
buf.copy(ev.rawData, 8);
|
buf.copy(ev.rawData, 8);
|
||||||
|
|
||||||
client.emit('event', ev);
|
client.emit('event', ev);
|
||||||
var ee = client.event_consumers[ev.wid];
|
var ee = client.event_consumers[ev.wid];
|
||||||
if (ee) {
|
if (ee) {
|
||||||
ee.emit('event', ev);
|
ee.emit('event', ev);
|
||||||
}
|
}
|
||||||
client.expectReplyHeader();
|
client.expectReplyHeader();
|
||||||
} );
|
} );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -488,7 +489,7 @@ XClient.prototype.expectReplyHeader = function()
|
||||||
var bodylength = 24 + length_total*4; // 24 is rest if 32-bytes header
|
var bodylength = 24 + length_total*4; // 24 is rest if 32-bytes header
|
||||||
|
|
||||||
client.pack_stream.get( bodylength, function( data ) {
|
client.pack_stream.get( bodylength, function( data ) {
|
||||||
|
|
||||||
var handler = client.replies[seq_num];
|
var handler = client.replies[seq_num];
|
||||||
if (handler) {
|
if (handler) {
|
||||||
var unpack = handler[0];
|
var unpack = handler[0];
|
||||||
|
|
@ -504,8 +505,8 @@ XClient.prototype.expectReplyHeader = function()
|
||||||
}
|
}
|
||||||
// wait for new packet from server
|
// wait for new packet from server
|
||||||
client.expectReplyHeader();
|
client.expectReplyHeader();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -514,7 +515,7 @@ XClient.prototype.startHandshake = function()
|
||||||
var client = this;
|
var client = this;
|
||||||
|
|
||||||
handshake.writeClientHello(this.pack_stream, this.displayNum, this.authHost);
|
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
|
// TODO: readServerHello can set error state in display
|
||||||
// emit error in that case
|
// emit error in that case
|
||||||
|
|
@ -522,7 +523,7 @@ XClient.prototype.startHandshake = function()
|
||||||
client.display = display;
|
client.display = display;
|
||||||
display.client = client;
|
display.client = client;
|
||||||
client.emit('connect', display);
|
client.emit('connect', display);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
XClient.prototype.require = function(extName, callback)
|
XClient.prototype.require = function(extName, callback)
|
||||||
|
|
@ -558,7 +559,7 @@ module.exports.createClient = function(options, initCb)
|
||||||
var screenNum = displayMatch[3];
|
var screenNum = displayMatch[3];
|
||||||
if (!screenNum)
|
if (!screenNum)
|
||||||
screenNum = 0;
|
screenNum = 0;
|
||||||
|
|
||||||
// open stream
|
// open stream
|
||||||
var stream;
|
var stream;
|
||||||
var socketPath;
|
var socketPath;
|
||||||
|
|
@ -569,13 +570,13 @@ module.exports.createClient = function(options, initCb)
|
||||||
if (process.platform == 'darwin' || process.platform == 'mac')
|
if (process.platform == 'darwin' || process.platform == 'mac')
|
||||||
{
|
{
|
||||||
// socket path on OSX is /tmp/launch-(some id)/org.x:0
|
// socket path on OSX is /tmp/launch-(some id)/org.x:0
|
||||||
if (display[0] == '/')
|
if (display[0] == '/')
|
||||||
{
|
{
|
||||||
socketPath = display;
|
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?)
|
} 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;
|
||||||
}
|
}
|
||||||
//socketPath = '/tmp/.X11-unix/X' + displayNum;
|
//socketPath = '/tmp/.X11-unix/X' + displayNum;
|
||||||
if(socketPath)
|
if(socketPath)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue